From 65d0dc43f008dd42505747d6fc38d7937924d9a1 Mon Sep 17 00:00:00 2001 From: Ben Thorner Date: Thu, 29 Jul 2021 11:00:10 +0100 Subject: [PATCH] Move happy path request-based tests to top of file We can simplify the rest of the tests to avoid the boilerplate of making an actual request. But it's worth keeping these two to prove the wrapper work correctly for an arbitrary route. --- .../app/authentication/test_authentication.py | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/app/authentication/test_authentication.py b/tests/app/authentication/test_authentication.py index 571fef4c6..acd86bec0 100644 --- a/tests/app/authentication/test_authentication.py +++ b/tests/app/authentication/test_authentication.py @@ -50,6 +50,22 @@ def admin_jwt_token(): return create_jwt_token(admin_jwt_secret, admin_jwt_client_id) +def test_requires_auth_should_allow_valid_token_for_request_with_path_params_for_public_url( + client, + service_jwt_token, +): + response = client.get('/notifications', headers={'Authorization': 'Bearer {}'.format(service_jwt_token)}) + assert response.status_code == 200 + + +def test_requires_admin_auth_should_allow_valid_token_for_request_with_path_params( + client, + admin_jwt_token +): + response = client.get('/service', headers={'Authorization': 'Bearer {}'.format(admin_jwt_token)}) + assert response.status_code == 200 + + def test_get_auth_token_should_not_allow_request_with_no_token(client): request.headers = {} with pytest.raises(AuthError) as exc: @@ -233,22 +249,6 @@ def test_requires_auth_should_not_allow_service_id_with_the_wrong_data_type( assert data['message'] == {"token": ['Invalid token: service id is not the right data type']} -def test_requires_auth_should_allow_valid_token_for_request_with_path_params_for_public_url( - client, - service_jwt_token, -): - response = client.get('/notifications', headers={'Authorization': 'Bearer {}'.format(service_jwt_token)}) - assert response.status_code == 200 - - -def test_requires_admin_auth_should_allow_valid_token_for_request_with_path_params( - client, - admin_jwt_token -): - response = client.get('/service', headers={'Authorization': 'Bearer {}'.format(admin_jwt_token)}) - assert response.status_code == 200 - - def test_requires_auth_returns_error_when_service_doesnt_exist( client, sample_api_key