Commit 744893b4 authored by John C Boufford's avatar John C Boufford
Browse files

Added some unit test for crud operations.

parent 35768ff8
......@@ -48,7 +48,7 @@ class ApiDirectory:
if ('access_token' in token):
access_token = token['access_token']
else:
print(token)
logger.debug(token)
if ('error' in token):
err = token['error']
......
......@@ -10,18 +10,18 @@ class ApiDirectoryTest(unittest.TestCase):
def test_constructor(self):
api = ApiDirectory(self.client_id, self.secret, self.scope, self.token_url);
self.assertEquals(api.client_id, self.client_id)
self.assertEquals(api.secret, self.secret)
self.assertEquals(api.scope, self.scope)
self.assertEquals(api.token_url, self.token_url)
self.assertEquals(api.timeout, 10)
self.assertEqual(api.client_id, self.client_id)
self.assertEqual(api.secret, self.secret)
self.assertEqual(api.scope, self.scope)
self.assertEqual(api.token_url, self.token_url)
self.assertEqual(api.timeout, 10)
def test_build_header(self):
api = ApiDirectory(self.client_id, self.secret, self.scope, self.token_url);
header = api.build_headers()
map = header
self.assertEquals(map['x-ibm-client-id'], self.client_id)
self.assertEqual(map['x-ibm-client-id'], self.client_id)
self.assertTrue('authorization' in map)
......@@ -14,24 +14,24 @@ class IamGroupTests(unittest.TestCase):
token_url = "https://apigw-tst.it.umich.edu/um/inst/oauth2/token"
url_base = "https://apigw-tst.it.umich.edu/um/iamGroups"
def test_create(self):
def test_find_person(self):
api = ApiDirectory(self.client_id, self.secret, self.scope, self.token_url)
uid = "jbouffor"
url_endpoint = 'find/person'
url = IamGroupTests.url_base + '/' + url_endpoint + "/" + uid
url_endpoint = 'create'
url = IamGroupTests.url_base + '/' + url_endpoint
data = 'iamGroupTestJB'
response = requests.post(
response = requests.get(
url=url,
data=data,
headers = api.build_headers(),
timeout = 10
)
print(api.build_headers())
print('Response: {}'.format(response))
print('JSON: {}'.format(response.json()))
map = response.json();
self.assertEquals(map['status'], 200)
self.assertEqual(response.status_code, requests.codes.ok)
map = response.json()
self.assertEqual(map['naming'], "jbouffor")
import unittest
import logging
import requests
import json
from apidirectory import ApiDirectory
logger = logging.getLogger(__name__)
class IamGroupTests(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"
def test_create(self):
api = ApiDirectory(self.client_id, self.secret, self.scope, self.token_url)
url_endpoint = 'create'
url = IamGroupTests.url_base + '/' + url_endpoint
data = 'iamGroupTestJB'
response = requests.post(
url=url,
data=data,
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)
def test_read(self):
api = ApiDirectory(self.client_id, self.secret, self.scope, self.token_url)
dn = "cn=iamGroupTestJB,ou=user groups,ou=groups,dc=umich,dc=edu"
url_endpoint = 'profile'
url = IamGroupTests.url_base + '/' + url_endpoint + "/" + dn
response = requests.get(
url=url,
headers = api.build_headers(),
timeout = 10
)
print(api.build_headers())
print('Response: {}'.format(response))
print('JSON: {}'.format(response.json()))
map = response.json();self.assertEqual(response.status_code, requests.codes.ok)
self.assertEqual(response.status_code, requests.codes.ok)
self.assertEqual[map['dn'], "jbouffor"]
def test_update(self):
api = ApiDirectory(self.client_id, self.secret, self.scope, self.token_url)
url_endpoint = 'update/moderator'
url = IamGroupTests.url_base + '/' + url_endpoint
data = { 'dn' : 'cn=mye2eapitest,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,
data=json.dumps(data),
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)
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