def test_invalid_token(self): """Test the response we get for invalid token (using pool)""" global user, auth_url token = "skaksaFlBl+fasFdaf24sx" try: client = AstakosClient(token, auth_url) client.get_uuids([user['name']]) 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 (using pool)""" global user_1 token = "skaksaFlBl+fasFdaf24sx" _mock_request([_request_ok]) try: client = AstakosClient("https://example.com") client.get_uuids(token, [user_1['username']]) 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_uuids(token, displaynames, return_dict=False, fail_silently=True): astakos = AstakosClient(token, ASTAKOS_AUTH_URL, retry=2, use_pool=True, logger=logger) catalog = astakos.get_uuids(displaynames) or {} missing = list(set(displaynames) - set(catalog)) if missing and not fail_silently: raise ItemNotExists("Unknown uuids: %s" % ", ".join(missing)) return catalog if return_dict else [catalog.get(i) for i in displaynames]
def test_get_uuid(self): """Test get_uuid""" global token, user, auth_url try: client = AstakosClient(token['id'], auth_url, retry=1) catalog = client.get_uuids([user['name']]) except: self.fail("Shouldn't raise an Exception") self.assertEqual(catalog[user['name']], user['id'])
def retrieve_uuids(token, displaynames, return_dict=False, fail_silently=True): astakos = AstakosClient(token, ASTAKOS_AUTH_URL, retry=2, use_pool=True, logger=logger) catalog = astakos.get_uuids(displaynames) or {} missing = list(set(displaynames) - set(catalog)) if missing and not fail_silently: raise ItemNotExists('Unknown uuids: %s' % ', '.join(missing)) return catalog if return_dict else [catalog.get(i) for i in displaynames]
def test_uuids(self): """Test get_uuids with both users""" global token_1, user_1, user_2 _mock_request([_request_ok]) try: client = AstakosClient("https://example.com") catalog = client.get_uuids( token_1, [user_1['username'], user_2['username']]) except: self.fail("Shouldn't raise an Exception") self.assertEqual(catalog[user_1['username']], user_1['uuid']) self.assertEqual(catalog[user_2['username']], user_2['uuid'])