def test_invalid_token(self): """Test the response we get for invalid token (without pool)""" global auth_url token = "skaksaFlBl+fasFdaf24sx" try: client = AstakosClient(token, auth_url) client.get_usernames(["12412351"]) except Unauthorized: pass except Exception: self.fail("Should have returned 401 (Invalid X-Auth-Token)") else: self.fail("Should have returned 401 (Invalid X-Auth-Token)")
def test_invalid_token(self): """Test the response we get for invalid token (without pool)""" global auth_url token = "skaksaFlBl+fasFdaf24sx" try: client = AstakosClient(token, auth_url) client.get_usernames(["12412351"]) except Unauthorized: pass except Exception: self.fail("Should have returned 401 (Invalid X-Auth-Token)") else: self.fail("Should have returned 401 (Invalid X-Auth-Token)")
def test_invalid_token(self): """Test the response we get for invalid token (without pool)""" global user_1 token = "skaksaFlBl+fasFdaf24sx" _mock_request([_request_ok]) try: client = AstakosClient("https://example.com") client.get_usernames(token, [user_1['uuid']]) except Unauthorized: pass except Exception: self.fail("Should have returned 401 (Invalid X-Auth-Token)") else: self.fail("Should have returned 401 (Invalid X-Auth-Token)")
def retrieve_displaynames(token, uuids, return_dict=False, fail_silently=True): astakos = AstakosClient(token, ASTAKOS_AUTH_URL, retry=2, use_pool=True, logger=logger) catalog = astakos.get_usernames(uuids) or {} missing = list(set(uuids) - set(catalog)) if missing and not fail_silently: raise ItemNotExists("Unknown displaynames: %s" % ", ".join(missing)) return catalog if return_dict else [catalog.get(i) for i in uuids]
def retrieve_displaynames(token, uuids, return_dict=False, fail_silently=True): astakos = AstakosClient(token, ASTAKOS_AUTH_URL, retry=2, use_pool=True, logger=logger) catalog = astakos.get_usernames(uuids) or {} missing = list(set(uuids) - set(catalog)) if missing and not fail_silently: raise ItemNotExists('Unknown displaynames: %s' % ', '.join(missing)) return catalog if return_dict else [catalog.get(i) for i in uuids]
def test_usernames(self): """Test get_usernames with both users""" global token_1, user_1, user_2 _mock_request([_request_ok]) try: client = AstakosClient("https://example.com") catalog = client.get_usernames( token_1, [user_1['uuid'], user_2['uuid']]) except: self.fail("Shouldn't raise an Exception") self.assertEqual(catalog[user_1['uuid']], user_1['username']) self.assertEqual(catalog[user_2['uuid']], user_2['username'])