Note: The default ITS GitLab runner is a shared resource and is subject to slowdowns during heavy usage.
You can run your own GitLab runner that is dedicated just to your group if you need to avoid processing delays.

Commit a55d04f9 authored by Rob Carleski's avatar Rob Carleski 🇮🇸
Browse files

Merge branch 'fix-requirements' into 'master'

Build system improvements

See merge request carleski/python-mcommunity!1
parents 1a6a2842 07d19bdf
__pycache__
*.pyc
bin/
dist/
venv/
.eggs
VERSION
umich_mcomm.egg-info
......@@ -7,8 +7,7 @@ stages:
test:
stage: test
before_script:
- pip install -U pip
- pip install -I -r python-requirements.txt
- cd tests/
- pip install virtualenv
- ./init.sh
script:
- pytest -v
- ./venv/bin/python setup.py test
## 1.0.0 (2019-02-07)
- Initial stable release.
Copyright (c) 2019 Regents of The University of Michigan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
include CHANGELOG.md
include COPYING
include VERSION
include tests/data/*
include version.sh
# python-mcommunity
python-mcommunity is a Python library for interacting with the MCommunity API.
## Setting up your environment
python-mcommunity requires Python 3.
For development, we recommend using a virtualenv.
* Run `init.sh` to set up the virtualenv.
* When you want to hack on python-mcommunity, source env-setup.sh
(`. env-setup.sh`) to set up the necessary environment variables.
## Testing
Tests can be run with `python setup.py test`.
python-mcommunity uses the [pytest](https://pytest.org/) testing framework, so
tests can also be run directly with the command `pytest`.
#!/bin/bash
hacking_dir=$(readlink -fn $(dirname "$BASH_SOURCE"))
VIRTUAL_ENV_DISABLE_PROMPT=1
. $hacking_dir/venv/bin/activate
#!/bin/bash
virtualenv -p python36 --system-site-packages bin/python
. bin/python/bin/activate
pip install -U pip
pip install -I -r python-requirements.txt
cd $(readlink -fn $(dirname "$BASH_SOURCE"))
if which virtualenv; then
[[ -d venv/bin ]] || virtualenv -p python3 venv
. venv/bin/activate
pip install -U pip
pip install -U -r requirements.txt
else
echo "Automated environment setup requires virtualenv."
fi
[aliases]
test=pytest
[tool:pytest]
addopts=-v --pep8
pep8maxlinelength=160
import os
from subprocess import check_output
from setuptools import setup, find_packages
setup(name='umich_mcomm',
version='1.00',
description='Library for interacting with MCommunity APIs',
url='https://gitlab.umich.edu/carleski/python-mcommunity.git',
author='Rob Carleski',
author_email='carleski@umich.edu',
license='MIT',
python_requires='>=3',
packages=find_packages(),
zip_safe=False)
version = check_output(['bash', os.path.join(os.path.dirname(__file__), 'version.sh')]).decode(encoding='utf-8')
with open(os.path.join(os.path.dirname(__file__), 'README.md'), 'r') as f:
long_description = f.read()
test_deps = [
'pytest',
'pytest-pep8',
'flask',
]
setup(
name='umich_mcomm',
version=version,
description='Library for interacting with MCommunity APIs',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://gitlab.umich.edu/carleski/python-mcommunity.git',
author='Rob Carleski',
author_email='carleski@umich.edu',
license='MIT',
python_requires='>=3',
packages=find_packages(),
install_requires=[
'requests',
],
setup_requires=[
'pytest-runner',
],
tests_require=test_deps,
extras_require={
'test': test_deps,
},
zip_safe=False
)
import flask
import os
import pytest
import subprocess
import pytest
pytest_plugins = "pep8"
@pytest.fixture(scope="session")
def mock_mcomm():
os.environ["FLASK_APP"] = 'mock_mcomm.py'
p = subprocess.Popen(['flask', 'run'])
p = subprocess.Popen(['python3', os.path.join(os.path.dirname(__file__), 'mock_mcomm.py')])
yield p
p.kill()
[
{
"dn": "cn=testgroup,ou=User Groups,ou=Groups,dc=umich,dc=edu",
"naming": null,
"displayName": "testgroup",
"email": null,
"displayTitle": null,
"title": null,
"affiliation": null,
"description": null,
"member": false,
"owner": false,
"moderator": false,
"person": false,
"group": true,
"external": false,
"securityEquals": null,
"groupMembership": null,
"role": null
}
]
[
{
"dn": "cn=testgroup2,ou=User Groups,ou=Groups,dc=umich,dc=edu",
"naming": null,
"displayName": "testgroup2",
"email": null,
"displayTitle": null,
"title": null,
"affiliation": null,
"description": null,
"member": false,
"owner": false,
"moderator": false,
"person": false,
"group": true,
"external": false,
"securityEquals": null,
"groupMembership": null,
"role": null
}
]
[
{
"dn": "uid=testuser,ou=People,dc=umich,dc=edu",
"naming": "testuser",
"displayName": "Test Usersson",
"email": "testuser@umich.edu",
"displayTitle": "Application Operations System Administrator Senior",
"title": [
"Application Operations System Administrator Senior"
],
"affiliation": [
"ITS Infra Sys Application Ops - Faculty and Staff",
"ITS Infrastrc - Systems - Faculty and Staff"
],
"description": null,
"member": false,
"owner": false,
"moderator": false,
"person": true,
"group": false,
"external": false,
"securityEquals": null,
"groupMembership": null,
"role": null
},
{
"dn": "cn=testuser-group,ou=User Groups,ou=Groups,dc=umich,dc=edu",
"naming": null,
"displayName": "testuser-group",
"email": null,
"displayTitle": null,
"title": null,
"affiliation": null,
"description": null,
"member": false,
"owner": false,
"moderator": false,
"person": false,
"group": true,
"external": false,
"securityEquals": null,
"groupMembership": null,
"role": null
},
{
"dn": "cn=testuser-dev,ou=User Groups,ou=Groups,dc=umich,dc=edu",
"naming": null,
"displayName": "testuser-dev",
"email": null,
"displayTitle": null,
"title": null,
"affiliation": null,
"description": null,
"member": false,
"owner": false,
"moderator": false,
"person": false,
"group": true,
"external": false,
"securityEquals": null,
"groupMembership": null,
"role": null
},
{
"dn": "cn=test-testuser,ou=User Groups,ou=Groups,dc=umich,dc=edu",
"naming": null,
"displayName": "test-testuser",
"email": null,
"displayTitle": null,
"title": null,
"affiliation": null,
"description": null,
"member": false,
"owner": false,
"moderator": false,
"person": false,
"group": true,
"external": false,
"securityEquals": null,
"groupMembership": null,
"role": null
}
]
[
{
"dn": "uid=testuser2,ou=People,dc=umich,dc=edu",
"naming": "testuser2",
"displayName": "Test Usersson Jr.",
"email": "testuser2@umich.edu",
"displayTitle": "Application Operations System Administrator Senior",
"title": [
"Application Operations System Administrator Senior"
],
"affiliation": [
"ITS Infra Sys Application Ops - Faculty and Staff",
"ITS Infrastrc - Systems - Faculty and Staff"
],
"description": null,
"member": false,
"owner": false,
"moderator": false,
"person": true,
"group": false,
"external": false,
"securityEquals": null,
"groupMembership": null,
"role": null
}
]
{
"dn": "uid=testuser,ou=People,dc=umich,dc=edu",
"naming": "testuser",
"displayName": "Test Usersson",
"email": "testuser@umich.edu",
"displayTitle": "Application Operations System Administrator Senior",
"title": [
"Application Operations System Administrator Senior"
],
"affiliation": [
"ITS Infra Sys Application Ops - Faculty and Staff",
"ITS Infrastrc - Systems - Faculty and Staff"
],
"description": null,
"member": false,
"owner": false,
"moderator": false,
"person": true,
"group": false,
"external": false,
"securityEquals": null,
"groupMembership": null,
"role": null
}
{
"group": [
{
"objectClass": [
"top",
"groupofnames",
"umichgroup",
"rfc822mailgroup",
"umichexpire",
"dirxml-entitlementrecipient",
"posixgroup",
"ndsloginproperties"
],
"dn": "cn=testgroup,ou=user groups,ou=groups,dc=umich,dc=edu",
"name": "testgroup",
"description": null,
"aliases": [
"alias1",
"alias2",
"alias3"
],
"memberDn": [
"uid=testuser,ou=people,dc=umich,dc=edu"
],
"ownerDn": [
"uid=testuser,ou=people,dc=umich,dc=edu",
"cn=controller-group,ou=user groups,ou=groups,dc=umich,dc=edu"
],
"owners": [
{
"dn": "uid=testuser,ou=people,dc=umich,dc=edu",
"naming": "testuser",
"displayName": "Test Usersson",
"email": "testuser@umich.edu",
"displayTitle": "Application Operations System Administrator Senior",
"title": [
"Application Operations System Administrator Senior"
],
"affiliation": [
"ITS Infra Sys Application Ops - Faculty and Staff",
"ITS Infrastrc - Systems - Faculty and Staff"
],
"description": null,
"member": false,
"owner": false,
"moderator": false,
"person": true,
"group": false,
"external": false,
"securityEquals": null,
"groupMembership": null,
"role": null
}
],
"expiredDate": "02/05/2020",
"email": "testgroup",
"isSpamBlocked": true,
"isEmailWarningSuppressed": true,
"isJoinable": false,
"externalSystems": [
"Box",
"Google"
],
"isPrivate": true,
"isEmailableByMembersOnly": false,
"xmlAssociations": null,
"moderatorRaw": null,
"moderator": null,
"memberGroupDn": null,
"groupMemberDnRaw": null,
"memberExternalRaw": null,
"memberExternal": null,
"renewAuthority": null,
"disabled": false,
"disabledBy": null,
"disabledMessage": null,
"disabledDate": null,
"purgeDate": null,
"notice": null,
"acl": null,
"equivalentToMe": null,
"descriptionLevel": "PUBLIC",
"noticeLevel": "PUBLIC",
"urlLevel": "PUBLIC",
"errorsTo": null,
"errorsToExternalRaw": null,
"errorsToExternal": null,
"requestTo": null,
"requestToExternalRaw": null,
"requestToExternal": null,
"gidNumber": "2280774",
"editable": false,
"urlLinks": null,
"labeledUri": null,
"authenticatedUserRole": null,
"authenticatedUserRoles": null,
"renewable": true,
"moderated": false
}
],
"error": null
}
#!/usr/bin/env python
import json
import os
from flask import Flask
app = Flask(__name__)
def get_testdata(base, name):
fname = os.path.join(os.path.dirname(__file__), 'data/{}_{}.json'.format(base, name))
if os.path.exists(fname):
with open(fname, 'r') as f:
return f.read()
else:
return '{}'
@app.route("/iamGroups/create", methods=['POST'])
@app.route("/iamGroups/delete/<dn>", methods=['GET'])
@app.route("/iamGroups/renew/<dn>", methods=['GET'])
......@@ -13,26 +24,22 @@ app = Flask(__name__)
def return_success(attrib=False, dn=False):
return '{"status": "success"}'
@app.route("/iamGroups/profile/dn/<dn>", methods=['GET'])
def get_group(dn):
return '{"group":[{"objectClass":["top","groupofnames","umichgroup","rfc822mailgroup","umichexpire","dirxml-entitlementrecipient","posixgroup","ndsloginproperties"],"dn":"cn=testgroup,ou=user groups,ou=groups,dc=umich,dc=edu","name":"testgroup","description":null,"aliases":["alias1","alias2","alias3"],"memberDn":["uid=testuser,ou=people,dc=umich,dc=edu"],"ownerDn":["uid=testuser,ou=people,dc=umich,dc=edu","cn=controller-group,ou=user groups,ou=groups,dc=umich,dc=edu"],"owners":[{"dn":"uid=testuser,ou=people,dc=umich,dc=edu","naming":"testuser","displayName":"Test Usersson","email":"testuser@umich.edu","displayTitle":"Application Operations System Administrator Senior","title":["Application Operations System Administrator Senior"],"affiliation":["ITS Infra Sys Application Ops - Faculty and Staff","ITS Infrastrc - Systems - Faculty and Staff"],"description":null,"member":false,"owner":false,"moderator":false,"person":true,"group":false,"external":false,"securityEquals":null,"groupMembership":null,"role":null}],"expiredDate":"02/05/2020","email":"testgroup","isSpamBlocked":true,"isEmailWarningSuppressed":true,"isJoinable":false,"externalSystems":["Box","Google"],"isPrivate":true,"isEmailableByMembersOnly":false,"xmlAssociations":null,"moderatorRaw":null,"moderator":null,"memberGroupDn":null,"groupMemberDnRaw":null,"memberExternalRaw":null,"memberExternal":null,"renewAuthority":null,"disabled":false,"disabledBy":null,"disabledMessage":null,"disabledDate":null,"purgeDate":null,"notice":null,"acl":null,"equivalentToMe":null,"descriptionLevel":"PUBLIC","noticeLevel":"PUBLIC","urlLevel":"PUBLIC","errorsTo":null,"errorsToExternalRaw":null,"errorsToExternal":null,"requestTo":null,"requestToExternalRaw":null,"requestToExternal":null,"gidNumber":"2280774","editable":false,"urlLinks":null,"labeledUri":null,"authenticatedUserRole":null,"authenticatedUserRoles":null,"renewable":true,"moderated":false}],"error":null}'
cn = dn.split(',')[0].split('=')[1]
return get_testdata('profile', cn)
@app.route("/iamGroups/find/both/<name>", methods=['GET'])
def get_both(name):
if name == 'testuser':
return '[{"dn":"uid=testuser,ou=People,dc=umich,dc=edu","naming":"testuser","displayName":"Test Usersson","email":"testuser@umich.edu","displayTitle":"Application Operations System Administrator Senior","title":["Application Operations System Administrator Senior"],"affiliation":["ITS Infra Sys Application Ops - Faculty and Staff","ITS Infrastrc - Systems - Faculty and Staff"],"description":null,"member":false,"owner":false,"moderator":false,"person":true,"group":false,"external":false,"securityEquals":null,"groupMembership":null,"role":null},{"dn":"cn=testuser-group,ou=User Groups,ou=Groups,dc=umich,dc=edu","naming":null,"displayName":"testuser-group","email":null,"displayTitle":null,"title":null,"affiliation":null,"description":null,"member":false,"owner":false,"moderator":false,"person":false,"group":true,"external":false,"securityEquals":null,"groupMembership":null,"role":null},{"dn":"cn=testuser-dev,ou=User Groups,ou=Groups,dc=umich,dc=edu","naming":null,"displayName":"testuser-dev","email":null,"displayTitle":null,"title":null,"affiliation":null,"description":null,"member":false,"owner":false,"moderator":false,"person":false,"group":true,"external":false,"securityEquals":null,"groupMembership":null,"role":null},{"dn":"cn=test-testuser,ou=User Groups,ou=Groups,dc=umich,dc=edu","naming":null,"displayName":"test-testuser","email":null,"displayTitle":null,"title":null,"affiliation":null,"description":null,"member":false,"owner":false,"moderator":false,"person":false,"group":true,"external":false,"securityEquals":null,"groupMembership":null,"role":null}]'
elif name == 'testuser2':
return '[{"dn":"uid=testuser2,ou=People,dc=umich,dc=edu","naming":"testuser2","displayName":"Test Usersson Jr.","email":"testuser2@umich.edu","displayTitle":"Application Operations System Administrator Senior","title":["Application Operations System Administrator Senior"],"affiliation":["ITS Infra Sys Application Ops - Faculty and Staff","ITS Infrastrc - Systems - Faculty and Staff"],"description":null,"member":false,"owner":false,"moderator":false,"person":true,"group":false,"external":false,"securityEquals":null,"groupMembership":null,"role":null}]'
elif name =='testgroup':
return '[{"dn":"cn=testgroup,ou=User Groups,ou=Groups,dc=umich,dc=edu","naming":null,"displayName":"testgroup","email":null,"displayTitle":null,"title":null,"affiliation":null,"description":null,"member":false,"owner":false,"moderator":false,"person":false,"group":true,"external":false,"securityEquals":null,"groupMembership":null,"role":null}]'
elif name =='testgroup2':
return '[{"dn":"cn=testgroup2,ou=User Groups,ou=Groups,dc=umich,dc=edu","naming":null,"displayName":"testgroup2","email":null,"displayTitle":null,"title":null,"affiliation":null,"description":null,"member":false,"owner":false,"moderator":false,"person":false,"group":true,"external":false,"securityEquals":null,"groupMembership":null,"role":null}]'
else:
return {}
return get_testdata('find_both', name)
@app.route("/iamGroups/find/person/<uid>", methods=['GET'])
def get_user(uid):
return '{"dn":"uid=testuser,ou=People,dc=umich,dc=edu","naming":"testuser","displayName":"Test Usersson","email":"testuser@umich.edu","displayTitle":"Application Operations System Administrator Senior","title":["Application Operations System Administrator Senior"],"affiliation":["ITS Infra Sys Application Ops - Faculty and Staff","ITS Infrastrc - Systems - Faculty and Staff"],"description":null,"member":false,"owner":false,"moderator":false,"person":true,"group":false,"external":false,"securityEquals":null,"groupMembership":null,"role":null}'
return get_testdata('find_person', uid)
@app.route("/iamGroups/isValidName/<name>", methods=['GET'])
def is_valid_name(name):
......@@ -41,6 +48,14 @@ def is_valid_name(name):
else:
return '{"valid": "false"}'
@app.route("/inst/oauth2/token", methods=['POST'])
def return_token():
return '{"access_token": "a1b2c3d4c5d6e7f8g9h10i11j12k13l14"}'
def main():
app.run()
if __name__ == '__main__':
main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment