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 148aeed8 authored by John C Boufford's avatar John C Boufford
Browse files

flake8 fixes

parent 515b36d2
[flake8]
ignore = E501
# W503
\ No newline at end of file
......@@ -4,6 +4,7 @@ import logging
logger = logging.getLogger(__name__)
class ApiDirectory:
def __init__(self, client_id, secret, scope, token_url, timeout=10):
......@@ -14,10 +15,10 @@ class ApiDirectory:
self.timeout = timeout
def _validate_initialization(self):
if (self.client_id == None
or self.secret == None
or self.scope == None
or self.token_url == None):
if (self.client_id is None
or self.secret is None
or self.scope is None
or self.token_url is None):
raise Exception("Invalid class configuration")
def _find_token(self):
......
......@@ -9,7 +9,7 @@ class ApiDirectoryTest(unittest.TestCase):
token_url = "https://apigw-tst.it.umich.edu/um/inst/oauth2/token"
def test_constructor(self):
api = ApiDirectory(self.client_id, self.secret, self.scope, self.token_url);
api = ApiDirectory(self.client_id, self.secret, self.scope, self.token_url)
self.assertEqual(api.client_id, self.client_id)
self.assertEqual(api.secret, self.secret)
self.assertEqual(api.scope, self.scope)
......@@ -17,11 +17,9 @@ class ApiDirectoryTest(unittest.TestCase):
self.assertEqual(api.timeout, 10)
def test_build_header(self):
api = ApiDirectory(self.client_id, self.secret, self.scope, self.token_url);
api = ApiDirectory(self.client_id, self.secret, self.scope, self.token_url)
header = api.build_headers()
map = header
self.assertEqual(map['x-ibm-client-id'], self.client_id)
self.assertTrue('authorization' in map)
......@@ -8,8 +8,9 @@ from apidirectory import ApiDirectory
logger = logging.getLogger(__name__)
#This test class test Create, Read, Update, and Delete (CRUD) oeprations.
#The first test has a one because when I run the test they run in alphbetic order
# This test class test Create, Read, Update, and Delete (CRUD) oeprations.
# The first test has a one because when I run the test they run in alphbetic order
# which may be different in your IDE, or command line.
class IamGroupCRUDTests(unittest.TestCase):
......@@ -29,18 +30,17 @@ class IamGroupCRUDTests(unittest.TestCase):
url_endpoint = 'create'
url = IamGroupCRUDTests.url_base + '/' + url_endpoint
data = {'name':'iamGroupTestJB'}
data = {'name': 'iamGroupTestJB'}
response = requests.post(
url=url,
data=json.dumps(data),
headers = api.build_headers(),
timeout = 10
headers=api.build_headers(),
timeout=10
)
print('Response: {}'.format(response))
print('JSON: {}'.format(response.json()))
map = response.json();
self.assertEqual(response.status_code, requests.codes.ok)
# The Read operation take a dn on the url. Because a dn contains spaces, commas and equals it
......@@ -54,8 +54,8 @@ class IamGroupCRUDTests(unittest.TestCase):
response = requests.get(
url=url,
headers = api.build_headers(),
timeout = 10
headers=api.build_headers(),
timeout=10
)
print('Response: {}'.format(response))
......@@ -74,9 +74,9 @@ class IamGroupCRUDTests(unittest.TestCase):
url_endpoint = 'update/moderator'
url = IamGroupCRUDTests.url_base + '/' + url_endpoint
data = { 'dn' : 'cn=iamGroupTestJB,ou=user groups,ou=groups,dc=umich,dc=edu',
'moderator' : [{'email': 'john.boufford@yahoo.com'},
{'name':'John Boufford','email':'jbouffor@yahoo.com'}]}
data = {'dn': 'cn=iamGroupTestJB,ou=user groups,ou=groups,dc=umich,dc=edu',
'moderator': [{'email': 'john.boufford@yahoo.com'},
{'name': 'John Boufford', 'email': 'jbouffor@yahoo.com'}]}
response = requests.post(
url=url,
......@@ -106,7 +106,6 @@ class IamGroupCRUDTests(unittest.TestCase):
print('JSON: {}'.format(response.json()))
self.assertEqual(response.status_code, requests.codes.ok)
# Note that I used urllib.parse.quote which converts spaces to %20.
# the urllib.parse.quote_plus converts spaces to a plus sign. Which fails in this api.
def test_urlencoding(self):
......@@ -116,7 +115,7 @@ class IamGroupCRUDTests(unittest.TestCase):
print(post)
self.assertEqual(post, expected)
#Test check if the group name is avaliable and follows all the rules.
# Test check if the group name is avaliable and follows all the rules.
# Make sure to encode the name because the name can contain spaces and other specail chars.
def test_isValid(self):
api = ApiDirectory(self.client_id, self.secret, self.scope, self.token_url)
......@@ -133,7 +132,7 @@ class IamGroupCRUDTests(unittest.TestCase):
print('Response: {}'.format(response))
print('JSON: {}'.format(response.json()))
self.assertEqual(response.status_code, requests.codes.ok)
map = response.json();
map = response.json()
self.assertTrue(map['valid'])
# Test check if the group name is avaliable and follows all the rules. fails
......@@ -153,5 +152,5 @@ class IamGroupCRUDTests(unittest.TestCase):
print('Response: {}'.format(response))
print('JSON: {}'.format(response.json()))
self.assertEqual(response.status_code, requests.codes.ok)
map = response.json();
map = response.json()
self.assertFalse(map['valid'])
import unittest
import logging
import requests
import json
import urllib.parse
from apidirectory import ApiDirectory
logger = logging.getLogger(__name__)
#This is a test of find groups that I play some role in. Owner, Member, Moderator.
# This is a test of find groups that I play some role in. Owner, Member, Moderator.
class IamGroupMyGroupsTests(unittest.TestCase):
client_id = "e06fb405-c58e-4334-b746-dd5969575bf2"
......@@ -78,7 +77,7 @@ class IamGroupMyGroupsTests(unittest.TestCase):
print('JSON: {}'.format(response.json()))
self.assertEqual(response.status_code, requests.codes.ok)
#Finds the groups that I am both a direct owner and an indirect owner.
# Finds the groups that I am both a direct owner and an indirect owner.
def test_ownership(self):
api = ApiDirectory(self.client_id, self.secret, self.scope, self.token_url)
url_endpoint = 'mygroup/allownership'
......@@ -107,4 +106,3 @@ class IamGroupMyGroupsTests(unittest.TestCase):
print('Response: {}'.format(response))
print('JSON: {}'.format(response.json()))
self.assertEqual(response.status_code, requests.codes.ok)
......@@ -26,6 +26,7 @@ from apidirectory import ApiDirectory
logger = logging.getLogger(__name__)
class IamGroupSearchTests(unittest.TestCase):
client_id = "e06fb405-c58e-4334-b746-dd5969575bf2"
......@@ -34,14 +35,13 @@ class IamGroupSearchTests(unittest.TestCase):
token_url = "https://apigw-tst.it.umich.edu/um/inst/oauth2/token"
url_base = "https://apigw-tst.it.umich.edu/um/iamGroups"
# Search for a group that contains ITS somewhere in the name.
def test_search(self):
api = ApiDirectory(self.client_id, self.secret, self.scope, self.token_url)
url_endpoint = 'search'
url = IamGroupSearchTests.url_base + '/' + url_endpoint
data = {'cn': 'ITS', "cnSearchType":"contains" }
data = {'cn': 'ITS', "cnSearchType": "contains"}
response = requests.post(
url=url,
......@@ -55,7 +55,6 @@ class IamGroupSearchTests(unittest.TestCase):
self.assertEqual(response.status_code, requests.codes.ok)
# Search for a group ITS. Same behavior if you type a name in the quick search box.
def test_simple_search(self):
api = ApiDirectory(self.client_id, self.secret, self.scope, self.token_url)
......@@ -76,7 +75,6 @@ class IamGroupSearchTests(unittest.TestCase):
self.assertEqual(response.status_code, requests.codes.ok)
# Search for a member in the groups Im an owner.
def test_search_mygroups_for_member(self):
api = ApiDirectory(self.client_id, self.secret, self.scope, self.token_url)
......@@ -98,13 +96,11 @@ class IamGroupSearchTests(unittest.TestCase):
self.assertEqual(response.status_code, requests.codes.ok)
# Search for a member in the groups Im an owner.
def test_find_person_by_uniqname(self):
api = ApiDirectory(self.client_id, self.secret, self.scope, self.token_url)
url_endpoint = 'find/person'
uniqname = "jbouffor"
#Since uniqname are alpha numeric without spaces this is not really needed.
# Since uniqname are alpha numeric without spaces this is not really needed.
encoded = urllib.parse.quote(uniqname)
url = IamGroupSearchTests.url_base + '/' + url_endpoint + '/' + encoded
......@@ -123,7 +119,7 @@ class IamGroupSearchTests(unittest.TestCase):
api = ApiDirectory(self.client_id, self.secret, self.scope, self.token_url)
url_endpoint = 'find/both'
uniqname = "post-its-notes"
#Since uniqname are alpha numeric without spaces this is not really needed.
# Since uniqname are alpha numeric without spaces this is not really needed.
encoded = urllib.parse.quote(uniqname)
url = IamGroupSearchTests.url_base + '/' + url_endpoint + '/' + encoded
......@@ -155,4 +151,4 @@ class IamGroupSearchTests(unittest.TestCase):
print('Response: {}'.format(response))
print('JSON: {}'.format(response.json()))
self.assertEqual(response.status_code, requests.codes.ok)
\ No newline at end of file
self.assertEqual(response.status_code, requests.codes.ok)
......@@ -8,6 +8,7 @@ from apidirectory import ApiDirectory
logger = logging.getLogger(__name__)
class IamGroupUpdateTests(unittest.TestCase):
client_id = "e06fb405-c58e-4334-b746-dd5969575bf2"
......@@ -52,29 +53,27 @@ class IamGroupUpdateTests(unittest.TestCase):
)
self.assertEqual(response.status_code, requests.codes.ok)
# This will update the group with the supplied values. These web service will replace existing value.
# For instance the update member replaces all members.
# warning if you modify the owner you could remove your access. See the example below.
def test_update_group(self):
data = {'dn': self.groupDn,
'aliases' : ['anotherNameTest'],
'aliases': ['anotherNameTest'],
'description': 'Sample test group created and updated from a unit test',
'notice': "Test notice",
'labeledUri' : [{'urlValue':'yahoo.com'},{'urlLabel':'Google','urlValue':'google.com'}],
'labeledUri': [{'urlValue': 'yahoo.com'}, {'urlLabel': 'Google', 'urlValue': 'google.com'}],
# settings
'isprivate':'true',
'isjoinable':'false',
'IsSpamBlocked':'true',
'IsEmailableByMembersOnly':'false',
'IsEmailWarningSuppressed':'true',
'isprivate': 'true',
'isjoinable': 'false',
'IsSpamBlocked': 'true',
'IsEmailableByMembersOnly': 'false',
'IsEmailWarningSuppressed': 'true',
# end settings
'memberDn': ['uid=jbouffor,ou=people,dc=umich,dc=edu'],
'memberGroupDn': ['cn=post-its-notes,ou=user groups,ou=groups,dc=umich,dc=edu'],
'moderator': [{'email': 'john.boufford@yahoo.com'},
{'name': 'John Boufford', 'email': 'jbouffor@yahoo.com'}],
'memberExternal': [{'email':'someone@google.com'}, {'email':'someone@yahoo.com', 'name':'someone'}]
'memberExternal': [{'email': 'someone@google.com'}, {'email': 'someone@yahoo.com', 'name': 'someone'}]
}
self.apply_update(data, "update/aliases")
......@@ -87,7 +86,6 @@ class IamGroupUpdateTests(unittest.TestCase):
self.apply_update(data, "update/moderator")
self.apply_update(data, "update/externalMember")
# This example updates a group owner. First it looks up the group.
# Adds an owner to the existing group.
# replace ErrorsTo attribute
......@@ -97,7 +95,7 @@ class IamGroupUpdateTests(unittest.TestCase):
# lookup the group.
group = self.lookup(self.groupDn)
#add owner to the returned group.
# add owner to the returned group.
personDn = "uid=jbouffor,ou=people,dc=umich,dc=edu"
group['ownerDn'].append(personDn)
self.apply_update(group, "update/owner")
......@@ -113,7 +111,6 @@ class IamGroupUpdateTests(unittest.TestCase):
self.apply_update(group, "update/requestTo")
# updates the privacy setting for the notice
def update_privacySettings(self):
# values for level
......@@ -129,12 +126,11 @@ class IamGroupUpdateTests(unittest.TestCase):
# joinable
data = {'dn': self.groupDn,
'level' : 'PUBLIC',
'field' : 'notice'
}
self.apply_update(data, 'update/privacySetting' )
'level': 'PUBLIC',
'field': 'notice'
}
self.apply_update(data, 'update/privacySetting')
def apply_update(self, data, url_endpoint):
print("updating " + url_endpoint)
......@@ -152,8 +148,8 @@ class IamGroupUpdateTests(unittest.TestCase):
print('JSON: {}'.format(response.json()))
raise Exception("issue with update")
map = response.json();
return map;
map = response.json()
return map
def lookup(self, dn):
api = ApiDirectory(self.client_id, self.secret, self.scope, self.token_url)
......
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