From 71d4eca4c06971e4af350f25eac643db9ff3f738 Mon Sep 17 00:00:00 2001 From: Caroline Hatwell Date: Mon, 13 Apr 2026 15:39:33 +0100 Subject: [PATCH 1/3] =?UTF-8?q?NPA-6521:=20refactor=20function=20to=20redu?= =?UTF-8?q?ce=20complexity=20and=20also=20have=20a=20change=20to=20create?= =?UTF-8?q?=20a=20PR=20=F0=9F=99=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sandbox/api/patch_consent.py | 114 ++++++++++++----------------------- 1 file changed, 38 insertions(+), 76 deletions(-) diff --git a/sandbox/api/patch_consent.py b/sandbox/api/patch_consent.py index 41899d8e..8532ab11 100644 --- a/sandbox/api/patch_consent.py +++ b/sandbox/api/patch_consent.py @@ -23,6 +23,42 @@ logger = getLogger(__name__) +PATCH_CONSENT_RESPONSES = { + "74eed847-ca25-4e76-8cf2-f2c2d7842a7a": (PATCH_CONSENT__SUCCESS, 200), + "6b71ac92-baa3-4b76-b0f5-a601257e2722": (PATCH_CONSENT__SUCCESS, 200), + "43003db8-ffcd-4bd6-ab2f-b49b9656f9e5": (PATCH_CONSENT__SUCCESS, 200), + "849ea584-2318-471b-a24c-cee1b5ad0137": (PATCH_CONSENT__INVALID_PATCH_FORMAT, 400), + "01abb0c5-b1ac-499d-9655-9cd0b8d3588f": (PATCH_CONSENT__INVALID_PATH, 400), + "78c35330-fa2f-4934-a5dd-fff847f38de5": (PATCH_CONSENT__INVALID_STATUS_CODE, 422), + "51fb4df5-815a-45cd-8427-04d6558336b7": (PATCH_CONSENT__INVALID_STATUS_REASON, 422), + "7b7f47b8-96e5-43eb-b733-283bf1449f2c": ( + PATCH_CONSENT__INVALID_STATE_TRANSITION, + 422, + ), + "d4e8a6f2-1c3b-4a7e-9d2f-8b5c7e9f1a3d": ( + PATCH_CONSENT__MISSING_FREE_TEXT_FOR_OTHER, + 400, + ), + "a1b2c3d4-e5f6-4789-a0b1-c2d3e4f5a6b7": (PATCH_CONSENT__SUCCESS, 200), + "b2c3d4e5-f6a7-4890-b1c2-d3e4f5a6b7c8": (PATCH_CONSENT__SUCCESS, 200), + "c3d4e5f6-a7b8-4901-c2d3-e4f5a6b7c8d9": (PATCH_CONSENT__SUCCESS, 200), + "90957744-b971-496e-b7c3-ab971868ce14": (PATCH_CONSENT__MISSING_GRANTOR, 400), + "b68cbfc8-ccc2-48ad-b97b-b7410d773dc1": (PATCH_CONSENT__INVALID_GRANTOR_VALUE, 422), + "fd189522-68e5-42dc-b44c-989be0eaa2bf": ( + PATCH_CONSENT__INVALID_GRANTOR_SYSTEM, + 422, + ), + "7e764160-38b6-41eb-9012-a3e476cbc517": ( + PATCH_CONSENT__MISSING_GRANTOR_REFERENCE, + 400, + ), + "faefd8c5-5e24-4415-8252-96e9241c7e78": ( + PATCH_CONSENT__MISSING_GRANTOR_IDENTIFIER, + 400, + ), +} + + def patch_consent_response(id: str) -> Union[dict, tuple]: """Sandbox API for PATCH /Consent @@ -34,84 +70,10 @@ def patch_consent_response(id: str) -> Union[dict, tuple]: """ try: logger.debug("Received request to PATCH consent") - # Validate body - validation is beyond the scope of the sandbox. - # Assume all requests are valid - - if id == "74eed847-ca25-4e76-8cf2-f2c2d7842a7a": - # Successful status update - return generate_response_from_example(PATCH_CONSENT__SUCCESS, 200) - - elif id == "6b71ac92-baa3-4b76-b0f5-a601257e2722": - # Successful end date for a role - return generate_response_from_example(PATCH_CONSENT__SUCCESS, 200) - - elif id == "43003db8-ffcd-4bd6-ab2f-b49b9656f9e5": - # Multiple valid changes - return generate_response_from_example(PATCH_CONSENT__SUCCESS, 200) - - elif id == "849ea584-2318-471b-a24c-cee1b5ad0137": - # Invalid patch format - return generate_response_from_example(PATCH_CONSENT__INVALID_PATCH_FORMAT, 400) - - elif id == "01abb0c5-b1ac-499d-9655-9cd0b8d3588f": - # Invalid path - return generate_response_from_example(PATCH_CONSENT__INVALID_PATH, 400) - - elif id == "78c35330-fa2f-4934-a5dd-fff847f38de5": - # Invalid status code - return generate_response_from_example(PATCH_CONSENT__INVALID_STATUS_CODE, 422) - - elif id == "51fb4df5-815a-45cd-8427-04d6558336b7": - # Invalid status reason - return generate_response_from_example(PATCH_CONSENT__INVALID_STATUS_REASON, 422) - - elif id == "7b7f47b8-96e5-43eb-b733-283bf1449f2c": - # Invalid state transition - return generate_response_from_example(PATCH_CONSENT__INVALID_STATE_TRANSITION, 422) - - # Mandatory free text for OTHER reason codes - elif id == "d4e8a6f2-1c3b-4a7e-9d2f-8b5c7e9f1a3d": - # Missing free text for OTHER reason code (should fail) - return generate_response_from_example(PATCH_CONSENT__MISSING_FREE_TEXT_FOR_OTHER, 400) - - elif id == "a1b2c3d4-e5f6-4789-a0b1-c2d3e4f5a6b7": - # Valid OTHER reason code WITH free text (should succeed) - return generate_response_from_example(PATCH_CONSENT__SUCCESS, 200) - - # Optional free text for non-OTHER reason codes - elif id == "b2c3d4e5-f6a7-4890-b1c2-d3e4f5a6b7c8": - # Non-OTHER reason code WITHOUT free text (should succeed) - return generate_response_from_example(PATCH_CONSENT__SUCCESS, 200) - - elif id == "c3d4e5f6-a7b8-4901-c2d3-e4f5a6b7c8d9": - # Non-OTHER reason code WITH free text (should succeed) - return generate_response_from_example(PATCH_CONSENT__SUCCESS, 200) - - elif id == "90957744-b971-496e-b7c3-ab971868ce14": - # Missing grantor extension - return generate_response_from_example(PATCH_CONSENT__MISSING_GRANTOR, 400) - - elif id == "b68cbfc8-ccc2-48ad-b97b-b7410d773dc1": - # Invalid grantor identifier value - return generate_response_from_example(PATCH_CONSENT__INVALID_GRANTOR_VALUE, 422) - - elif id == "fd189522-68e5-42dc-b44c-989be0eaa2bf": - # Invalid grantor identifier system - return generate_response_from_example(PATCH_CONSENT__INVALID_GRANTOR_SYSTEM, 422) - - elif id == "7e764160-38b6-41eb-9012-a3e476cbc517": - # Missing grantor reference - return generate_response_from_example(PATCH_CONSENT__MISSING_GRANTOR_REFERENCE, 400) - - elif id == "faefd8c5-5e24-4415-8252-96e9241c7e78": - # Missing grantor identifier - return generate_response_from_example(PATCH_CONSENT__MISSING_GRANTOR_IDENTIFIER, 400) - else: - # Resource not found - return generate_response_from_example(PATCH_CONSENT__RESOURCE_NOT_FOUND, 404) + example, status_code = PATCH_CONSENT_RESPONSES.get(id, (PATCH_CONSENT__RESOURCE_NOT_FOUND, 404)) + return generate_response_from_example(example, status_code) except Exception: - # Handle any general error logger.exception("PATCH Consent failed") return generate_response_from_example(INTERNAL_SERVER_ERROR_EXAMPLE, 500) From e38a29c4603ec45046deeb80871529dcc33c6fb4 Mon Sep 17 00:00:00 2001 From: Caroline Hatwell Date: Mon, 13 Apr 2026 15:50:21 +0100 Subject: [PATCH 2/3] NPA-6521: kill flask process fully --- .github/workflows/pr-checks.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-checks.yaml b/.github/workflows/pr-checks.yaml index d05aa7e5..92d9d1be 100644 --- a/.github/workflows/pr-checks.yaml +++ b/.github/workflows/pr-checks.yaml @@ -34,6 +34,7 @@ jobs: # 1. Run Flask in the background (using 'poetry run python -m flask') # We use FLASK_DEBUG=1 to see the 500 errors in the console cp -r $GITHUB_WORKSPACE/specification/examples/responses/. $GITHUB_WORKSPACE/sandbox/api/examples/ + set -m FLASK_DEBUG=1 poetry run python -m flask --app api.app:app run -p 9000 & FLASK_PID=$! @@ -46,4 +47,4 @@ jobs: # 4. Cleanup: Kill the Flask process using the PID we saved echo "Shutting down Flask..." - kill $FLASK_PID + kill -TERM -$FLASK_PID From 6adfaf529d890bbb5c5faa658b371f8760d3feac Mon Sep 17 00:00:00 2001 From: Caroline Hatwell Date: Mon, 13 Apr 2026 16:05:36 +0100 Subject: [PATCH 3/3] NPA-6521: revert dummy change --- sandbox/api/patch_consent.py | 114 +++++++++++++++++++++++------------ 1 file changed, 76 insertions(+), 38 deletions(-) diff --git a/sandbox/api/patch_consent.py b/sandbox/api/patch_consent.py index 8532ab11..41899d8e 100644 --- a/sandbox/api/patch_consent.py +++ b/sandbox/api/patch_consent.py @@ -23,42 +23,6 @@ logger = getLogger(__name__) -PATCH_CONSENT_RESPONSES = { - "74eed847-ca25-4e76-8cf2-f2c2d7842a7a": (PATCH_CONSENT__SUCCESS, 200), - "6b71ac92-baa3-4b76-b0f5-a601257e2722": (PATCH_CONSENT__SUCCESS, 200), - "43003db8-ffcd-4bd6-ab2f-b49b9656f9e5": (PATCH_CONSENT__SUCCESS, 200), - "849ea584-2318-471b-a24c-cee1b5ad0137": (PATCH_CONSENT__INVALID_PATCH_FORMAT, 400), - "01abb0c5-b1ac-499d-9655-9cd0b8d3588f": (PATCH_CONSENT__INVALID_PATH, 400), - "78c35330-fa2f-4934-a5dd-fff847f38de5": (PATCH_CONSENT__INVALID_STATUS_CODE, 422), - "51fb4df5-815a-45cd-8427-04d6558336b7": (PATCH_CONSENT__INVALID_STATUS_REASON, 422), - "7b7f47b8-96e5-43eb-b733-283bf1449f2c": ( - PATCH_CONSENT__INVALID_STATE_TRANSITION, - 422, - ), - "d4e8a6f2-1c3b-4a7e-9d2f-8b5c7e9f1a3d": ( - PATCH_CONSENT__MISSING_FREE_TEXT_FOR_OTHER, - 400, - ), - "a1b2c3d4-e5f6-4789-a0b1-c2d3e4f5a6b7": (PATCH_CONSENT__SUCCESS, 200), - "b2c3d4e5-f6a7-4890-b1c2-d3e4f5a6b7c8": (PATCH_CONSENT__SUCCESS, 200), - "c3d4e5f6-a7b8-4901-c2d3-e4f5a6b7c8d9": (PATCH_CONSENT__SUCCESS, 200), - "90957744-b971-496e-b7c3-ab971868ce14": (PATCH_CONSENT__MISSING_GRANTOR, 400), - "b68cbfc8-ccc2-48ad-b97b-b7410d773dc1": (PATCH_CONSENT__INVALID_GRANTOR_VALUE, 422), - "fd189522-68e5-42dc-b44c-989be0eaa2bf": ( - PATCH_CONSENT__INVALID_GRANTOR_SYSTEM, - 422, - ), - "7e764160-38b6-41eb-9012-a3e476cbc517": ( - PATCH_CONSENT__MISSING_GRANTOR_REFERENCE, - 400, - ), - "faefd8c5-5e24-4415-8252-96e9241c7e78": ( - PATCH_CONSENT__MISSING_GRANTOR_IDENTIFIER, - 400, - ), -} - - def patch_consent_response(id: str) -> Union[dict, tuple]: """Sandbox API for PATCH /Consent @@ -70,10 +34,84 @@ def patch_consent_response(id: str) -> Union[dict, tuple]: """ try: logger.debug("Received request to PATCH consent") + # Validate body - validation is beyond the scope of the sandbox. + # Assume all requests are valid + + if id == "74eed847-ca25-4e76-8cf2-f2c2d7842a7a": + # Successful status update + return generate_response_from_example(PATCH_CONSENT__SUCCESS, 200) + + elif id == "6b71ac92-baa3-4b76-b0f5-a601257e2722": + # Successful end date for a role + return generate_response_from_example(PATCH_CONSENT__SUCCESS, 200) + + elif id == "43003db8-ffcd-4bd6-ab2f-b49b9656f9e5": + # Multiple valid changes + return generate_response_from_example(PATCH_CONSENT__SUCCESS, 200) + + elif id == "849ea584-2318-471b-a24c-cee1b5ad0137": + # Invalid patch format + return generate_response_from_example(PATCH_CONSENT__INVALID_PATCH_FORMAT, 400) + + elif id == "01abb0c5-b1ac-499d-9655-9cd0b8d3588f": + # Invalid path + return generate_response_from_example(PATCH_CONSENT__INVALID_PATH, 400) + + elif id == "78c35330-fa2f-4934-a5dd-fff847f38de5": + # Invalid status code + return generate_response_from_example(PATCH_CONSENT__INVALID_STATUS_CODE, 422) + + elif id == "51fb4df5-815a-45cd-8427-04d6558336b7": + # Invalid status reason + return generate_response_from_example(PATCH_CONSENT__INVALID_STATUS_REASON, 422) + + elif id == "7b7f47b8-96e5-43eb-b733-283bf1449f2c": + # Invalid state transition + return generate_response_from_example(PATCH_CONSENT__INVALID_STATE_TRANSITION, 422) + + # Mandatory free text for OTHER reason codes + elif id == "d4e8a6f2-1c3b-4a7e-9d2f-8b5c7e9f1a3d": + # Missing free text for OTHER reason code (should fail) + return generate_response_from_example(PATCH_CONSENT__MISSING_FREE_TEXT_FOR_OTHER, 400) + + elif id == "a1b2c3d4-e5f6-4789-a0b1-c2d3e4f5a6b7": + # Valid OTHER reason code WITH free text (should succeed) + return generate_response_from_example(PATCH_CONSENT__SUCCESS, 200) + + # Optional free text for non-OTHER reason codes + elif id == "b2c3d4e5-f6a7-4890-b1c2-d3e4f5a6b7c8": + # Non-OTHER reason code WITHOUT free text (should succeed) + return generate_response_from_example(PATCH_CONSENT__SUCCESS, 200) + + elif id == "c3d4e5f6-a7b8-4901-c2d3-e4f5a6b7c8d9": + # Non-OTHER reason code WITH free text (should succeed) + return generate_response_from_example(PATCH_CONSENT__SUCCESS, 200) + + elif id == "90957744-b971-496e-b7c3-ab971868ce14": + # Missing grantor extension + return generate_response_from_example(PATCH_CONSENT__MISSING_GRANTOR, 400) + + elif id == "b68cbfc8-ccc2-48ad-b97b-b7410d773dc1": + # Invalid grantor identifier value + return generate_response_from_example(PATCH_CONSENT__INVALID_GRANTOR_VALUE, 422) + + elif id == "fd189522-68e5-42dc-b44c-989be0eaa2bf": + # Invalid grantor identifier system + return generate_response_from_example(PATCH_CONSENT__INVALID_GRANTOR_SYSTEM, 422) + + elif id == "7e764160-38b6-41eb-9012-a3e476cbc517": + # Missing grantor reference + return generate_response_from_example(PATCH_CONSENT__MISSING_GRANTOR_REFERENCE, 400) + + elif id == "faefd8c5-5e24-4415-8252-96e9241c7e78": + # Missing grantor identifier + return generate_response_from_example(PATCH_CONSENT__MISSING_GRANTOR_IDENTIFIER, 400) - example, status_code = PATCH_CONSENT_RESPONSES.get(id, (PATCH_CONSENT__RESOURCE_NOT_FOUND, 404)) - return generate_response_from_example(example, status_code) + else: + # Resource not found + return generate_response_from_example(PATCH_CONSENT__RESOURCE_NOT_FOUND, 404) except Exception: + # Handle any general error logger.exception("PATCH Consent failed") return generate_response_from_example(INTERNAL_SERVER_ERROR_EXAMPLE, 500)