Commit ca6ba0b4 authored by Ilias Tsitsimpis's avatar Ilias Tsitsimpis Committed by Christos Stavrakakis

Implement getUUIDs/getUUID methods

parent e35a3608
......@@ -228,6 +228,37 @@ class AstakosClient():
# XXX: check if exists
return uuid_dict.get(uuid)
# ----------------------------------
def getUUIDs(self, token, display_names):
"""Return a displayname_catalog for the given names
Keyword arguments:
token -- user's token (string)
display_names -- list of user names (list of strings)
The returned displayname_catalog is a dictionary with
the names as keys and the corresponding uuids as values
req_headers = {'content-type': 'application/json'}
req_body = simplejson.dumps({'displaynames': display_names})
req_path = "/user_catalogs"
data = self._callAstakos(
token, req_path, req_headers, req_body, "POST")
# XXX: check if exists
return data.get("displayname_catalog")
def getUUID(self, token, display_name):
"""Return the uuid of a name (see getUUIDs)"""
if not display_name:
m = "No display_name was given"
raise ValueError(m)
name_dict = self.getUUIDs(token, [display_name])
# XXX: check if exists
return name_dict.get(display_name)
# --------------------------------------------------------------------
# Private functions
......@@ -153,6 +153,8 @@ def _reqCatalogs(conn, method, url, **kwargs):
# Return
body = simplejson.loads(kwargs['body'])
if 'uuids' in body:
# Return uuid_catalog
uuids = body['uuids']
catalogs = {}
if user_1['uuid'] in uuids:
......@@ -160,6 +162,17 @@ def _reqCatalogs(conn, method, url, **kwargs):
if user_2['uuid'] in uuids:
catalogs[user_2['uuid']] = user_2['username']
return_catalog = {"displayname_catalog": {}, "uuid_catalog": catalogs}
elif 'displaynames' in body:
# Return displayname_catalog
names = body['displaynames']
catalogs = {}
if user_1['username'] in names:
catalogs[user_1['username']] = user_1['uuid']
if user_2['username'] in names:
catalogs[user_2['username']] = user_2['uuid']
return_catalog = {"displayname_catalog": catalogs, "uuid_catalog": {}}
return_catalog = {"displayname_catalog": {}, "uuid_catalog": {}}
return (simplejson.dumps(return_catalog), 200)
......@@ -527,7 +540,7 @@ class TestDisplayNames(unittest.TestCase):
# ----------------------------------
# Get Info for both users
def test_DisplayNamesWithGet(self):
def test_DisplayNames(self):
"""Test getDisplayNames with both users"""
global token_1, user_1, user_2
......@@ -555,6 +568,54 @@ class TestDisplayNames(unittest.TestCase):
self.assertEqual(info, user_1['username'])
class TestGetUUIDs(unittest.TestCase):
"""Test cases for functions getUUIDs/getUUID"""
# ----------------------------------
# Test the response we get for invalid token
def test_InvalidToken(self):
"""Test the response we get for invalid token (using pool)"""
global user_1
token = "skaksaFlBl+fasFdaf24sx=="
client = AstakosClient("")
client.getUUIDs(token, [user_1['username']])
except AstakosClientException as err:
if err.status != 401:"Should have returned 401 (Invalid X-Auth-Token)")
else:"Should have returned 401 (Invalid X-Auth-Token)")
# ----------------------------------
# Get info for both users
def test_UUIDs(self):
"""Test getUUIDs with both users"""
global token_1, user_1, user_2
client = AstakosClient("")
catalog = client.getUUIDs(
token_1, [user_1['username'], user_2['username']])
except:"Shouldn't raise an Exception")
self.assertEqual(catalog[user_1['username']], user_1['uuid'])
self.assertEqual(catalog[user_2['username']], user_2['uuid'])
# ----------------------------------
# Get uuid for user 2
def test_GetUUIDUserTwo(self):
"""Test getUUID for User Two"""
global token_1, user_2
_mockRequest([_requestOffline, _requestOk])
client = AstakosClient("", retry=1)
info = client.getUUID(token_2, user_1['username'])
except:"Shouldn't raise an Exception")
self.assertEqual(info, user_1['uuid'])
# ----------------------------
# Run tests
if __name__ == "__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