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

Added updating a group

parent 22a420b5
import unittest
import logging
import requests
import json
import urllib.parse
from apidirectory import ApiDirectory
logger = logging.getLogger(__name__)
class IamGroupUpdateTests(unittest.TestCase):
client_id = "e06fb405-c58e-4334-b746-dd5969575bf2"
secret = "G5oT3vL1uK8xS7rO5sJ4nH7bK5iB6hN5jN5dI0nL8tO5bG4tT5"
scope = "iamgroups"
token_url = "https://apigw-tst.it.umich.edu/um/inst/oauth2/token"
url_base = "https://apigw-tst.it.umich.edu/um/iamGroups"
groupName = "iamGroupUpdateTest"
groupDn = "cn={},ou=user groups,ou=groups,dc=umich,dc=edu".format(groupName)
# create a group for the test cases
def setUp(self):
api = ApiDirectory(self.client_id, self.secret, self.scope, self.token_url)
url_endpoint = 'create'
url = IamGroupUpdateTests.url_base + '/' + url_endpoint
print('Running setup ' + self.groupName)
data = {'name': self.groupName}
response = requests.post(
url=url,
data=json.dumps(data),
headers=api.build_headers(),
timeout=10
)
self.assertEqual(response.status_code, requests.codes.ok)
# delete the group created for the test.
def tearDown(self):
api = ApiDirectory(self.client_id, self.secret, self.scope, self.token_url)
dn = self.groupDn
encoded_dn = urllib.parse.quote(dn)
url_endpoint = 'delete'
url = IamGroupUpdateTests.url_base + '/' + url_endpoint + "/" + encoded_dn
print('Running teardown ' + self.groupName)
response = requests.get(
url=url,
headers=api.build_headers(),
timeout=10
)
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'],
'description': 'Sample test group created and updated from a unit test',
'notice': "Test notice",
'labeledUri' : [{'urlValue':'yahoo.com'},{'urlLabel':'Google','urlValue':'google.com'}],
# settings
'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'}]
}
self.apply_update(data, "update/aliases")
self.apply_update(data, "update/description")
self.apply_update(data, "update/notice")
self.apply_update(data, "update/links")
self.apply_update(data, "update/settings")
self.apply_update(data, "update/member")
self.apply_update(data, "update/groupMember")
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
# Adds a Request To attribute
def update_group_management_attributes(self):
# lookup the group.
group = self.lookup(self.groupDn)
#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")
# replace errorto
group['errorsTo'] = [personDn]
self.apply_update(group, "update/errorsTo")
if ('requestTo' in group and group['requestTo'] is not None):
group['requestTo'].append(personDn)
else:
group['requestTo'] = [personDn]
self.apply_update(group, "update/requestTo")
# updates the privacy setting for the notice
def update_privacySettings(self):
# values for level
# PUBLIC
# PROTECTED
# PRIVATE
# values for field
# description
# notice
# links
# membership
# joinable
data = {'dn': self.groupDn,
'level' : 'PUBLIC',
'field' : 'notice'
}
self.apply_update(data, 'update/privacySetting' )
def apply_update(self, data, url_endpoint):
print("updating " + url_endpoint)
api = ApiDirectory(self.client_id, self.secret, self.scope, self.token_url)
url = IamGroupUpdateTests.url_base + '/' + url_endpoint
response = requests.post(
url=url,
data=json.dumps(data),
headers=api.build_headers(),
timeout=10
)
if (response.status_code != requests.codes.ok):
print('Response: {}'.format(response))
print('JSON: {}'.format(response.json()))
raise Exception("issue with update")
map = response.json();
return map;
def lookup(self, dn):
api = ApiDirectory(self.client_id, self.secret, self.scope, self.token_url)
encoded = urllib.parse.quote(dn)
url_endpoint = 'profile/dn'
url = IamGroupUpdateTests.url_base + '/' + url_endpoint + "/" + encoded
response = requests.get(
url=url,
headers=api.build_headers(),
timeout=10
)
if (response.status_code != requests.codes.ok):
print('Response: {}'.format(response))
print('JSON: {}'.format(response.json()))
raise Exception("issue with update")
# note that the returned json is a group object which is a list of profiles
profile = response.json()['group'][0]
return profile
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