From fdb5e1a055abe8b77ab5b25a52119257abf5cd5c Mon Sep 17 00:00:00 2001 From: Kyle Lawson Date: Thu, 20 Jul 2023 12:27:24 +0100 Subject: [PATCH 1/5] Remove /v1/unit_data from SDS_API_BASE_URL --- .development.env | 2 +- .functional-tests.env | 2 +- app/routes/session.py | 4 +- app/services/supplementary_data.py | 6 +-- doc/run-mock-sds-endpoint.md | 19 ++++++---- .../test_request_supplementary_data.py | 38 +++++++++---------- 6 files changed, 38 insertions(+), 33 deletions(-) diff --git a/.development.env b/.development.env index c9546f9d6a..44da8d065a 100644 --- a/.development.env +++ b/.development.env @@ -27,4 +27,4 @@ CDN_ASSETS_PATH=/design-system ADDRESS_LOOKUP_API_URL=https://whitelodge-ai-api.census-gcp.onsdigital.uk COOKIE_SETTINGS_URL=# EQ_SUBMISSION_CONFIRMATION_BACKEND=log -SDS_API_BASE_URL=http://localhost:5003/v1/unit_data +SDS_API_BASE_URL=http://localhost:5003 diff --git a/.functional-tests.env b/.functional-tests.env index 3192849c18..9da5874de6 100644 --- a/.functional-tests.env +++ b/.functional-tests.env @@ -28,4 +28,4 @@ ADDRESS_LOOKUP_API_URL=https://whitelodge-ai-api.census-gcp.onsdigital.uk COOKIE_SETTINGS_URL=# EQ_SUBMISSION_CONFIRMATION_BACKEND=log VIEW_SUBMITTED_RESPONSE_EXPIRATION_IN_SECONDS=35 -SDS_API_BASE_URL=http://localhost:5003/v1/unit_data +SDS_API_BASE_URL=http://localhost:5003 diff --git a/app/routes/session.py b/app/routes/session.py index b31bbe507f..b218d63251 100644 --- a/app/routes/session.py +++ b/app/routes/session.py @@ -27,7 +27,7 @@ ) from app.questionnaire import QuestionnaireSchema from app.routes.errors import _render_error_page -from app.services.supplementary_data import get_supplementary_data +from app.services.supplementary_data import get_supplementary_data_v1 from app.utilities.metadata_parser import validate_runner_claims from app.utilities.metadata_parser_v2 import ( validate_questionnaire_claims, @@ -157,7 +157,7 @@ def _set_questionnaire_supplementary_data( # no need to fetch again return - supplementary_data = get_supplementary_data( + supplementary_data = get_supplementary_data_v1( # Type ignore: survey_id and either ru_ref or qid are required for schemas that use supplementary data dataset_id=new_sds_dataset_id, unit_id=metadata["ru_ref"] or metadata["qid"], # type: ignore diff --git a/app/services/supplementary_data.py b/app/services/supplementary_data.py index 12bcea9bdb..8a794304af 100644 --- a/app/services/supplementary_data.py +++ b/app/services/supplementary_data.py @@ -30,8 +30,8 @@ def __str__(self) -> str: return "Supplementary Data request failed" -def get_supplementary_data(*, dataset_id: str, unit_id: str, survey_id: str) -> dict: - supplementary_data_url = current_app.config["SDS_API_BASE_URL"] +def get_supplementary_data_v1(*, dataset_id: str, unit_id: str, survey_id: str) -> dict: + supplementary_data_url = f"{current_app.config['SDS_API_BASE_URL']}/v1/unit_data" parameters = {"dataset_id": dataset_id, "unit_id": unit_id} @@ -79,7 +79,7 @@ def get_supplementary_data(*, dataset_id: str, unit_id: str, survey_id: str) -> def validate_supplementary_data( - supplementary_data: Mapping, dataset_id: str, unit_id: str, survey_id: str + supplementary_data: Mapping, dataset_id: str, unit_id: str, survey_id: str ) -> dict: try: return validate_supplementary_data_v1( diff --git a/doc/run-mock-sds-endpoint.md b/doc/run-mock-sds-endpoint.md index 25c7085fd1..1637e538ce 100644 --- a/doc/run-mock-sds-endpoint.md +++ b/doc/run-mock-sds-endpoint.md @@ -4,20 +4,25 @@ In order to test loading supplementary data, we have a development script that c returns mocked supplementary data and mock dataset metadata for that supplementary data. Ensure the following env var is set before running the script: + ```bash -SDS_API_BASE_URL=http://localhost:5003/v1/unit_data +SDS_API_BASE_URL=http://localhost:5003 ``` From the home directory, run using + ```python -python -m scripts.mock_sds_endpoint +python - m +scripts.mock_sds_endpoint ``` -The following datasets are available using the mocked endpoint. On selecting a survey that supports supplementary data, an `sds_dataset_id` dropdown will be shown in the metadata, and if you set the `survey_id` to `123`, it will be populated with the following options. +The following datasets are available using the mocked endpoint. On selecting a survey that supports supplementary data, +an `sds_dataset_id` dropdown will be shown in the metadata, and if you set the `survey_id` to `123`, it will be +populated with the following options. -| Dataset ID | Description | -|------------------------|------------------------------------------------------------| -| `c067f6de-6d64-42b1-8b02-431a3486c178` | Basic supplementary data structure with no repeating items | -| `34a80231-c49a-44d0-91a6-8fe1fb190e64` | Supplementary data structure with repeating items | +| Dataset ID | Description | +|----------------------------------------|--------------------------------------------------------------| +| `c067f6de-6d64-42b1-8b02-431a3486c178` | Basic supplementary data structure with no repeating items | +| `34a80231-c49a-44d0-91a6-8fe1fb190e64` | Supplementary data structure with repeating items | | `6b378962-f0c7-4e8c-947e-7d24ee1b6b88` | Supplementary data structure with additional repeating items | diff --git a/tests/app/services/test_request_supplementary_data.py b/tests/app/services/test_request_supplementary_data.py index dc51abfa36..9d191ef7d5 100644 --- a/tests/app/services/test_request_supplementary_data.py +++ b/tests/app/services/test_request_supplementary_data.py @@ -6,11 +6,11 @@ from app.services.supplementary_data import ( SUPPLEMENTARY_DATA_REQUEST_MAX_RETRIES, SupplementaryDataRequestFailed, - get_supplementary_data, + get_supplementary_data_v1, ) from tests.app.utilities.test_schema import get_mocked_make_request -TEST_SDS_URL = "http://test.domain/v1/unit_data" +TEST_SDS_URL = "http://test.domain" mock_supplementary_data_payload = { "dataset_id": "44f1b432-9421-49e5-bd26-e63e18a30b69", @@ -49,17 +49,17 @@ @responses.activate -def test_get_supplementary_data_200(app: Flask): +def test_get_supplementary_data_v1_200(app: Flask): with app.app_context(): current_app.config["SDS_API_BASE_URL"] = TEST_SDS_URL responses.add( responses.GET, - TEST_SDS_URL, + f"{TEST_SDS_URL}/v1/unit_data", json=mock_supplementary_data_payload, status=200, ) - loaded_supplementary_data = get_supplementary_data( + loaded_supplementary_data = get_supplementary_data_v1( dataset_id="44f1b432-9421-49e5-bd26-e63e18a30b69", unit_id="12346789012A", survey_id="123", @@ -73,19 +73,19 @@ def test_get_supplementary_data_200(app: Flask): [401, 403, 404, 501, 511], ) @responses.activate -def test_get_supplementary_data_non_200(app: Flask, status_code): +def test_get_supplementary_data_v1_non_200(app: Flask, status_code): with app.app_context(): current_app.config["SDS_API_BASE_URL"] = TEST_SDS_URL responses.add( responses.GET, - TEST_SDS_URL, + f"{TEST_SDS_URL}/v1/unit_data", json=mock_supplementary_data_payload, status=status_code, ) with pytest.raises(SupplementaryDataRequestFailed) as exc: - get_supplementary_data( + get_supplementary_data_v1( dataset_id="44f1b432-9421-49e5-bd26-e63e18a30b69", unit_id="12346789012A", survey_id="123", @@ -95,13 +95,13 @@ def test_get_supplementary_data_non_200(app: Flask, status_code): @responses.activate -def test_get_supplementary_data_request_failed(app: Flask): +def test_get_supplementary_data_v1_request_failed(app: Flask): with app.app_context(): current_app.config["SDS_API_BASE_URL"] = TEST_SDS_URL responses.add(responses.GET, TEST_SDS_URL, body=RequestException()) with pytest.raises(SupplementaryDataRequestFailed) as exc: - get_supplementary_data( + get_supplementary_data_v1( dataset_id="44f1b432-9421-49e5-bd26-e63e18a30b69", unit_id="12346789012A", survey_id="123", @@ -110,8 +110,8 @@ def test_get_supplementary_data_request_failed(app: Flask): assert str(exc.value) == "Supplementary Data request failed" -def test_get_supplementary_data_retries_timeout_error( - app: Flask, mocker, mocked_make_request_with_timeout +def test_get_supplementary_data_v1_retries_timeout_error( + app: Flask, mocker, mocked_make_request_with_timeout ): with app.app_context(): current_app.config["SDS_API_BASE_URL"] = TEST_SDS_URL @@ -121,7 +121,7 @@ def test_get_supplementary_data_retries_timeout_error( ) try: - supplementary_data = get_supplementary_data( + supplementary_data = get_supplementary_data_v1( dataset_id="44f1b432-9421-49e5-bd26-e63e18a30b69", unit_id="12346789012A", survey_id="123", @@ -132,13 +132,13 @@ def test_get_supplementary_data_retries_timeout_error( assert supplementary_data == mock_supplementary_data_payload expected_call = ( - SUPPLEMENTARY_DATA_REQUEST_MAX_RETRIES + 1 + SUPPLEMENTARY_DATA_REQUEST_MAX_RETRIES + 1 ) # Max retries + the initial request assert mocked_make_request_with_timeout.call_count == expected_call @pytest.mark.usefixtures("mocked_response_content") -def test_get_supplementary_data_retries_transient_error(app: Flask, mocker): +def test_get_supplementary_data_v1_retries_transient_error(app: Flask, mocker): with app.app_context(): current_app.config["SDS_API_BASE_URL"] = TEST_SDS_URL mocked_make_request = get_mocked_make_request( @@ -151,7 +151,7 @@ def test_get_supplementary_data_retries_transient_error(app: Flask, mocker): ) try: - supplementary_data = get_supplementary_data( + supplementary_data = get_supplementary_data_v1( dataset_id="44f1b432-9421-49e5-bd26-e63e18a30b69", unit_id="12346789012A", survey_id="123", @@ -162,13 +162,13 @@ def test_get_supplementary_data_retries_transient_error(app: Flask, mocker): assert supplementary_data == mock_supplementary_data_payload expected_call = ( - SUPPLEMENTARY_DATA_REQUEST_MAX_RETRIES + 1 + SUPPLEMENTARY_DATA_REQUEST_MAX_RETRIES + 1 ) # Max retries + the initial request assert mocked_make_request.call_count == expected_call -def test_get_supplementary_data_max_retries(app: Flask, mocker): +def test_get_supplementary_data_v1_max_retries(app: Flask, mocker): with app.app_context(): current_app.config["SDS_API_BASE_URL"] = TEST_SDS_URL @@ -177,7 +177,7 @@ def test_get_supplementary_data_max_retries(app: Flask, mocker): ) with pytest.raises(SupplementaryDataRequestFailed) as exc: - get_supplementary_data( + get_supplementary_data_v1( dataset_id="44f1b432-9421-49e5-bd26-e63e18a30b69", unit_id="12346789012A", survey_id="123", From 0eeaebde5b89e88340ee0a249f896e915a4856d7 Mon Sep 17 00:00:00 2001 From: Kyle Lawson Date: Thu, 20 Jul 2023 15:18:45 +0100 Subject: [PATCH 2/5] Updating with latest prepop branch. --- app/services/supplementary_data.py | 4 +- .../test_request_supplementary_data.py | 42 +++++++++---------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/app/services/supplementary_data.py b/app/services/supplementary_data.py index bbd3866a36..cd27b22393 100644 --- a/app/services/supplementary_data.py +++ b/app/services/supplementary_data.py @@ -41,7 +41,9 @@ class InvalidSupplementaryData(Exception): pass -def get_supplementary_data_v1(*, dataset_id: str, identifier: str, survey_id: str) -> dict: +def get_supplementary_data_v1( + *, dataset_id: str, identifier: str, survey_id: str +) -> dict: # Type ignore: current_app is a singleton in this application and has the key_store key in its eq attribute. key_store = current_app.eq["key_store"] # type: ignore if not key_store.get_key(purpose=KEY_PURPOSE_SDS, key_type="private"): diff --git a/tests/app/services/test_request_supplementary_data.py b/tests/app/services/test_request_supplementary_data.py index 4a47939eca..fe8f9d9d03 100644 --- a/tests/app/services/test_request_supplementary_data.py +++ b/tests/app/services/test_request_supplementary_data.py @@ -11,16 +11,16 @@ MissingSupplementaryDataKey, SupplementaryDataRequestFailed, decrypt_supplementary_data, - get_supplementary_data, + get_supplementary_data_v1, ) from tests.app.utilities.test_schema import get_mocked_make_request -TEST_SDS_URL = "http://test.domain/v1/unit_data" +TEST_SDS_URL = "http://test.domain" EXPECTED_SDS_DECRYPTION_VALIDATION_ERROR = "Supplementary data has no data to decrypt" @responses.activate -def test_get_supplementary_data_200( +def test_get_supplementary_data_v1_200( app: Flask, encrypted_mock_supplementary_data_payload, decrypted_mock_supplementary_data_payload, @@ -30,11 +30,11 @@ def test_get_supplementary_data_200( responses.add( responses.GET, - TEST_SDS_URL, + f"{TEST_SDS_URL}/v1/unit_data", json=encrypted_mock_supplementary_data_payload, status=200, ) - loaded_supplementary_data = get_supplementary_data( + loaded_supplementary_data = get_supplementary_data_v1( dataset_id="44f1b432-9421-49e5-bd26-e63e18a30b69", identifier="12346789012A", survey_id="123", @@ -48,7 +48,7 @@ def test_get_supplementary_data_200( [401, 403, 404, 501, 511], ) @responses.activate -def test_get_supplementary_data_non_200( +def test_get_supplementary_data_v1_non_200( app: Flask, status_code, encrypted_mock_supplementary_data_payload ): with app.app_context(): @@ -56,13 +56,13 @@ def test_get_supplementary_data_non_200( responses.add( responses.GET, - TEST_SDS_URL, + f"{TEST_SDS_URL}/v1/unit_data", json=encrypted_mock_supplementary_data_payload, status=status_code, ) with pytest.raises(SupplementaryDataRequestFailed) as exc: - get_supplementary_data( + get_supplementary_data_v1( dataset_id="44f1b432-9421-49e5-bd26-e63e18a30b69", identifier="12346789012A", survey_id="123", @@ -72,13 +72,13 @@ def test_get_supplementary_data_non_200( @responses.activate -def test_get_supplementary_data_request_failed(app: Flask): +def test_get_supplementary_data_v1_request_failed(app: Flask): with app.app_context(): current_app.config["SDS_API_BASE_URL"] = TEST_SDS_URL responses.add(responses.GET, TEST_SDS_URL, body=RequestException()) with pytest.raises(SupplementaryDataRequestFailed) as exc: - get_supplementary_data( + get_supplementary_data_v1( dataset_id="44f1b432-9421-49e5-bd26-e63e18a30b69", identifier="12346789012A", survey_id="123", @@ -87,7 +87,7 @@ def test_get_supplementary_data_request_failed(app: Flask): assert str(exc.value) == "Supplementary Data request failed" -def test_get_supplementary_data_retries_timeout_error( +def test_get_supplementary_data_v1_retries_timeout_error( app: Flask, mocker, mocked_make_request_with_timeout, @@ -101,7 +101,7 @@ def test_get_supplementary_data_retries_timeout_error( ) try: - supplementary_data = get_supplementary_data( + supplementary_data = get_supplementary_data_v1( dataset_id="44f1b432-9421-49e5-bd26-e63e18a30b69", identifier="12346789012A", survey_id="123", @@ -118,7 +118,7 @@ def test_get_supplementary_data_retries_timeout_error( @pytest.mark.usefixtures("mocked_response_content") -def test_get_supplementary_data_retries_transient_error( +def test_get_supplementary_data_v1_retries_transient_error( app: Flask, mocker, decrypted_mock_supplementary_data_payload ): with app.app_context(): @@ -133,7 +133,7 @@ def test_get_supplementary_data_retries_transient_error( ) try: - supplementary_data = get_supplementary_data( + supplementary_data = get_supplementary_data_v1( dataset_id="44f1b432-9421-49e5-bd26-e63e18a30b69", identifier="12346789012A", survey_id="123", @@ -150,7 +150,7 @@ def test_get_supplementary_data_retries_transient_error( assert mocked_make_request.call_count == expected_call -def test_get_supplementary_data_max_retries(app: Flask, mocker): +def test_get_supplementary_data_v1_max_retries(app: Flask, mocker): with app.app_context(): current_app.config["SDS_API_BASE_URL"] = TEST_SDS_URL @@ -159,7 +159,7 @@ def test_get_supplementary_data_max_retries(app: Flask, mocker): ) with pytest.raises(SupplementaryDataRequestFailed) as exc: - get_supplementary_data( + get_supplementary_data_v1( dataset_id="44f1b432-9421-49e5-bd26-e63e18a30b69", identifier="12346789012A", survey_id="123", @@ -169,7 +169,7 @@ def test_get_supplementary_data_max_retries(app: Flask, mocker): assert mocked_make_request.call_count == 3 -def test_decrypt_supplementary_data_decrypts_when_encrypted_payload_is_valid( +def test_decrypt_supplementary_data_v1_decrypts_when_encrypted_payload_is_valid( app: Flask, encrypted_mock_supplementary_data_payload, decrypted_mock_supplementary_data_payload, @@ -182,7 +182,7 @@ def test_decrypt_supplementary_data_decrypts_when_encrypted_payload_is_valid( assert result == decrypted_mock_supplementary_data_payload -def test_decrypt_supplementary_data_raises_validation_error_when_encrypted_payload_missing_data( +def test_decrypt_supplementary_data_v1_raises_validation_error_when_encrypted_payload_missing_data( app: Flask, mock_supplementary_data_payload_missing_data ): with app.app_context(): @@ -194,7 +194,7 @@ def test_decrypt_supplementary_data_raises_validation_error_when_encrypted_paylo assert EXPECTED_SDS_DECRYPTION_VALIDATION_ERROR in e.value.messages -def test_decrypt_supplementary_data_raises_invalid_token_error_when_encrypted_data_kid_invalid( +def test_decrypt_supplementary_data_v1_raises_invalid_token_error_when_encrypted_data_kid_invalid( app: Flask, mock_supplementary_data_payload_invalid_kid_in_data ): with app.app_context(): @@ -205,7 +205,7 @@ def test_decrypt_supplementary_data_raises_invalid_token_error_when_encrypted_da ) -def test_get_supplementary_data_raises_missing_supplementary_data_key_error_when_key_is_missing( +def test_get_supplementary_data_v1_raises_missing_supplementary_data_key_error_when_key_is_missing( app: Flask, mocker ): with app.app_context(): @@ -215,7 +215,7 @@ def test_get_supplementary_data_raises_missing_supplementary_data_key_error_when ) with pytest.raises(MissingSupplementaryDataKey): - get_supplementary_data( + get_supplementary_data_v1( dataset_id="44f1b432-9421-49e5-bd26-e63e18a30b69", identifier="12346789012A", survey_id="123", From b4e418dd66d23686b88fbcda017a17d901e4ecd2 Mon Sep 17 00:00:00 2001 From: Kyle Lawson Date: Thu, 20 Jul 2023 16:20:03 +0100 Subject: [PATCH 3/5] Updating int test with renamed method get_supplementary_data_v1 --- tests/integration/routes/test_session.py | 36 ++++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/integration/routes/test_session.py b/tests/integration/routes/test_session.py index 6771b14688..8cc9a09dc6 100644 --- a/tests/integration/routes/test_session.py +++ b/tests/integration/routes/test_session.py @@ -94,7 +94,7 @@ def test_get_session_expiry_doesnt_extend_session(self): # ... check that the session expiry time is not affected by # the request, and is still 45mins from the start time expected_expires_at = ( - TIME_TO_FREEZE + timedelta(seconds=EQ_SESSION_TIMEOUT_SECONDS) + TIME_TO_FREEZE + timedelta(seconds=EQ_SESSION_TIMEOUT_SECONDS) ).isoformat() self.assertIn("expires_at", parsed_json) @@ -112,34 +112,34 @@ def test_patch_session_expiry_extends_session(self): # ... check that the session expiry time is reset by the request # and is now 45 mins from the request time expected_expires_at = ( - request_time + timedelta(seconds=EQ_SESSION_TIMEOUT_SECONDS) + request_time + timedelta(seconds=EQ_SESSION_TIMEOUT_SECONDS) ).isoformat() self.assertIn("expires_at", parsed_json) self.assertEqual(parsed_json["expires_at"], expected_expires_at) - @patch("app.routes.session.get_supplementary_data") + @patch("app.routes.session.get_supplementary_data_v1") @patch( "app.data_models.questionnaire_store.QuestionnaireStore.set_supplementary_data" ) def test_supplementary_data_is_loaded_when_new_sds_dataset_id_in_metadata( - self, - mock_set, - mock_get, + self, + mock_set, + mock_get, ): self.launchSupplementaryDataSurvey() self.assertStatusOK() mock_get.assert_called_once() mock_set.assert_called_once() - @patch("app.routes.session.get_supplementary_data") + @patch("app.routes.session.get_supplementary_data_v1") @patch( "app.data_models.questionnaire_store.QuestionnaireStore.set_supplementary_data" ) def test_supplementary_data_is_reloaded_when_changed_sds_dataset_id_in_metadata( - self, - mock_set, - mock_get, + self, + mock_set, + mock_get, ): self.launchSupplementaryDataSurvey(response_id="1", sds_dataset_id="first") self.assertStatusOK() @@ -150,14 +150,14 @@ def test_supplementary_data_is_reloaded_when_changed_sds_dataset_id_in_metadata( self.assertEqual(mock_get.call_count, 2) self.assertEqual(mock_set.call_count, 2) - @patch("app.routes.session.get_supplementary_data") + @patch("app.routes.session.get_supplementary_data_v1") @patch( "app.data_models.questionnaire_store.QuestionnaireStore.set_supplementary_data" ) def test_supplementary_data_is_not_reloaded_when_same_sds_dataset_id_in_metadata( - self, - mock_set, - mock_get, + self, + mock_set, + mock_get, ): self.launchSupplementaryDataSurvey(response_id="1", sds_dataset_id="same") self.assertStatusOK() @@ -170,8 +170,8 @@ def test_supplementary_data_is_not_reloaded_when_same_sds_dataset_id_in_metadata def test_supplementary_data_raises_500_error_when_sds_api_request_fails(self): with patch( - "app.routes.session.get_supplementary_data", - side_effect=SupplementaryDataRequestFailed, + "app.routes.session.get_supplementary_data_v1", + side_effect=SupplementaryDataRequestFailed, ): self.assert_supplementary_data_500_page() @@ -187,7 +187,7 @@ def test_supplementary_data_raises_500_error_when_supplementary_data_invalid(sel @responses.activate def test_supplementary_data_raises_500_error_when_supplementary_data_missing_data( - self, + self, ): responses.add( responses.GET, @@ -198,7 +198,7 @@ def test_supplementary_data_raises_500_error_when_supplementary_data_missing_dat self.assert_supplementary_data_500_page() def test_supplementary_data_raises_500_error_when_missing_supplementary_data_key( - self, + self, ): self.key_store = KeyStore( { From afa190f89f0dfd3e230ce3938eb5df6abe3e073f Mon Sep 17 00:00:00 2001 From: Kyle Lawson Date: Thu, 20 Jul 2023 16:28:14 +0100 Subject: [PATCH 4/5] Format and lint --- tests/integration/routes/test_session.py | 30 ++++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/integration/routes/test_session.py b/tests/integration/routes/test_session.py index 8cc9a09dc6..026d581d1d 100644 --- a/tests/integration/routes/test_session.py +++ b/tests/integration/routes/test_session.py @@ -94,7 +94,7 @@ def test_get_session_expiry_doesnt_extend_session(self): # ... check that the session expiry time is not affected by # the request, and is still 45mins from the start time expected_expires_at = ( - TIME_TO_FREEZE + timedelta(seconds=EQ_SESSION_TIMEOUT_SECONDS) + TIME_TO_FREEZE + timedelta(seconds=EQ_SESSION_TIMEOUT_SECONDS) ).isoformat() self.assertIn("expires_at", parsed_json) @@ -112,7 +112,7 @@ def test_patch_session_expiry_extends_session(self): # ... check that the session expiry time is reset by the request # and is now 45 mins from the request time expected_expires_at = ( - request_time + timedelta(seconds=EQ_SESSION_TIMEOUT_SECONDS) + request_time + timedelta(seconds=EQ_SESSION_TIMEOUT_SECONDS) ).isoformat() self.assertIn("expires_at", parsed_json) @@ -123,9 +123,9 @@ def test_patch_session_expiry_extends_session(self): "app.data_models.questionnaire_store.QuestionnaireStore.set_supplementary_data" ) def test_supplementary_data_is_loaded_when_new_sds_dataset_id_in_metadata( - self, - mock_set, - mock_get, + self, + mock_set, + mock_get, ): self.launchSupplementaryDataSurvey() self.assertStatusOK() @@ -137,9 +137,9 @@ def test_supplementary_data_is_loaded_when_new_sds_dataset_id_in_metadata( "app.data_models.questionnaire_store.QuestionnaireStore.set_supplementary_data" ) def test_supplementary_data_is_reloaded_when_changed_sds_dataset_id_in_metadata( - self, - mock_set, - mock_get, + self, + mock_set, + mock_get, ): self.launchSupplementaryDataSurvey(response_id="1", sds_dataset_id="first") self.assertStatusOK() @@ -155,9 +155,9 @@ def test_supplementary_data_is_reloaded_when_changed_sds_dataset_id_in_metadata( "app.data_models.questionnaire_store.QuestionnaireStore.set_supplementary_data" ) def test_supplementary_data_is_not_reloaded_when_same_sds_dataset_id_in_metadata( - self, - mock_set, - mock_get, + self, + mock_set, + mock_get, ): self.launchSupplementaryDataSurvey(response_id="1", sds_dataset_id="same") self.assertStatusOK() @@ -170,8 +170,8 @@ def test_supplementary_data_is_not_reloaded_when_same_sds_dataset_id_in_metadata def test_supplementary_data_raises_500_error_when_sds_api_request_fails(self): with patch( - "app.routes.session.get_supplementary_data_v1", - side_effect=SupplementaryDataRequestFailed, + "app.routes.session.get_supplementary_data_v1", + side_effect=SupplementaryDataRequestFailed, ): self.assert_supplementary_data_500_page() @@ -187,7 +187,7 @@ def test_supplementary_data_raises_500_error_when_supplementary_data_invalid(sel @responses.activate def test_supplementary_data_raises_500_error_when_supplementary_data_missing_data( - self, + self, ): responses.add( responses.GET, @@ -198,7 +198,7 @@ def test_supplementary_data_raises_500_error_when_supplementary_data_missing_dat self.assert_supplementary_data_500_page() def test_supplementary_data_raises_500_error_when_missing_supplementary_data_key( - self, + self, ): self.key_store = KeyStore( { From b4b5da5135d3685cfe9298106033191783bb7102 Mon Sep 17 00:00:00 2001 From: katie-gardner Date: Fri, 21 Jul 2023 11:19:11 +0100 Subject: [PATCH 5/5] Fix mock-sds-endpoint readme --- doc/run-mock-sds-endpoint.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/run-mock-sds-endpoint.md b/doc/run-mock-sds-endpoint.md index 1637e538ce..7aba12abb6 100644 --- a/doc/run-mock-sds-endpoint.md +++ b/doc/run-mock-sds-endpoint.md @@ -11,9 +11,8 @@ SDS_API_BASE_URL=http://localhost:5003 From the home directory, run using -```python -python - m -scripts.mock_sds_endpoint +```bash +python -m scripts.mock_sds_endpoint ``` The following datasets are available using the mocked endpoint. On selecting a survey that supports supplementary data,