def test_blacklist_key_not_found(module_client, function_empty_db): # Arrange error = None # Act try: blacklist_key(FAKE_APIKEY + 'b', True, function_empty_db.session) except ApiKeyError as e: error = e # Assert assert error.error_code == ApiKeyErrorCode.NOT_FOUND
def test_get_api_key_blacklisted(module_client, module_db, fake_auth_from_oc): client = module_client apikey = get_api_key(client) blacklist_key(apikey, True, module_db.session) try: response = client.post('api/v1/apikey', follow_redirects=True, json=dict(email="*****@*****.**", password="******")) assert (response.status_code == 401) finally: blacklist_key(apikey, False, module_db.session)
def reactivate(apikey_or_email): try: key = blacklist_key(apikey_or_email, False, db.session) except ApiKeyError as error: print(error.message) return error.error_code print(f'Reactivated {key}')
def blacklist(apikey_or_email): try: key = blacklist_key(apikey_or_email, True, db.session) except ApiKeyError as error: print(error.message) return error.error_code print(f'Blacklisted {key}')
def test_blacklist_key_set_blacklisted_off(module_client, function_empty_db): # Arrange key = create_fake_key(function_empty_db.session, blacklisted=True) # Act key1 = blacklist_key(FAKE_APIKEY, False, function_empty_db.session) # Assert assert not key.blacklisted assert key == key1
def test_blacklist_key_not_blacklisted(module_client, function_empty_db): # Arrange error = None key1 = None create_fake_key(function_empty_db.session) # Act try: key1 = blacklist_key(FAKE_APIKEY, False, function_empty_db.session) except ApiKeyError as e: error = e # Assert assert error.error_code == ApiKeyErrorCode.NOT_BLACKLISTED assert key1 is None