def test_denied_key_not_found(module_client, function_empty_db): # Arrange error = None # Act try: deny_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_denied(module_client, module_db, fake_auth_from_oc): client = module_client apikey = get_api_key(client) deny_key(apikey, True, module_db.session) try: response = client.post('api/v1/apikey', follow_redirects=True, json=dict(email="*****@*****.**", password="******")) assert_correct_response(response, 401) finally: deny_key(apikey, False, module_db.session)
def reactivate(apikey_or_email): try: key = deny_key(apikey_or_email, False, db.session) except ApiKeyError as error: print(error.message) return error.error_code print(f'Reactivated {key}')
def deny(apikey_or_email): try: key = deny_key(apikey_or_email, True, db.session) except ApiKeyError as error: print(error.message) return error.error_code print(f'Denied {key}')
def test_deny_key_set_denied_off(module_client, function_empty_db): # Arrange key = create_fake_key(function_empty_db.session, denied=True) # Act key1 = deny_key(FAKE_APIKEY, False, function_empty_db.session) # Assert assert not key.denied assert key == key1
def test_deny_key_already_denied(module_client, function_empty_db): # Arrange error = None key1 = None create_fake_key(function_empty_db.session, denied=True) # Act try: key1 = deny_key(FAKE_APIKEY, True, function_empty_db.session) except ApiKeyError as e: error = e # Assert assert error.error_code == ApiKeyErrorCode.ALREADY_DENIED assert key1 is None