-
Notifications
You must be signed in to change notification settings - Fork 1
[NDR-314] Move PDM tests. #884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
213f0ff
[NDR-314] PDM GET specific tests
jameslinnell 6f192dc
[NDR-314] Initial move of test files.
jameslinnell 2a01dfd
[NDR-314] Add more tests
jameslinnell 1b9d017
[NDR-314] Make commands
jameslinnell bde0950
[NDR-314] Nicer make output
jameslinnell 701d774
[NDR-314] Fix post fhri tests
jameslinnell 66687e1
[NDR-314] Add example to aws login make command
jameslinnell 77912b9
[NDR-314] Change tests to reflect changes introduced by another ticket
jameslinnell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
lambdas/tests/unit/handlers/test_pdm_get_fhir_document_reference_by_id_handler.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import pytest | ||
| from enums.snomed_codes import SnomedCodes | ||
| from handlers.get_fhir_document_reference_handler import ( | ||
| extract_document_parameters, | ||
| lambda_handler, | ||
| ) | ||
| from models.document_reference import DocumentReference | ||
| from tests.unit.conftest import TEST_UUID | ||
| from tests.unit.helpers.data.dynamo.dynamo_responses import MOCK_SEARCH_RESPONSE | ||
| from utils.lambda_handler_utils import extract_bearer_token | ||
|
|
||
| SNOMED_CODE = SnomedCodes.PATIENT_DATA.value.code | ||
|
|
||
| MOCK_MTLS_VALID_EVENT = { | ||
| "httpMethod": "GET", | ||
| "headers": {}, | ||
| "pathParameters": {"id": f"{SNOMED_CODE}~{TEST_UUID}"}, | ||
| "body": None, | ||
| "requestContext": { | ||
| "accountId": "123456789012", | ||
| "apiId": "abc123", | ||
| "domainName": "api.example.com", | ||
| "identity": { | ||
| "sourceIp": "1.2.3.4", | ||
| "userAgent": "curl/7.64.1", | ||
| "clientCert": { | ||
| "clientCertPem": "-----BEGIN CERTIFICATE-----...", | ||
| "subjectDN": "CN=ndrclient.main.int.pdm.national.nhs.uk,O=NHS,C=UK", | ||
| "issuerDN": "CN=NHS Root CA,O=NHS,C=UK", | ||
| "serialNumber": "12:34:56", | ||
| "validity": { | ||
| "notBefore": "May 10 00:00:00 2024 GMT", | ||
| "notAfter": "May 10 00:00:00 2025 GMT", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| MOCK_DOCUMENT_REFERENCE = DocumentReference.model_validate( | ||
| MOCK_SEARCH_RESPONSE["Items"][0] | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_config_service(mocker): | ||
| mock_config = mocker.patch( | ||
| "handlers.get_fhir_document_reference_handler.DynamicConfigurationService" | ||
| ) | ||
| mock_config_instance = mock_config.return_value | ||
| return mock_config_instance | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_document_service(mocker): | ||
| mock_service = mocker.patch( | ||
| "handlers.get_fhir_document_reference_handler.GetFhirDocumentReferenceService" | ||
| ) | ||
| mock_service_instance = mock_service.return_value | ||
| mock_service_instance.handle_get_document_reference_request.return_value = ( | ||
| MOCK_DOCUMENT_REFERENCE | ||
| ) | ||
| return mock_service_instance | ||
|
|
||
|
|
||
| def test_lambda_handler_happy_path_with_mtls_pdm_login( | ||
| set_env, | ||
| mock_document_service, | ||
| context, | ||
| ): | ||
| mock_document_service.create_document_reference_fhir_response.return_value = ( | ||
| "test_document_reference" | ||
| ) | ||
|
|
||
| response = lambda_handler(MOCK_MTLS_VALID_EVENT, context) | ||
|
|
||
| assert response["statusCode"] == 200 | ||
| assert response["body"] == "test_document_reference" | ||
| # Verify correct method calls | ||
| mock_document_service.handle_get_document_reference_request.assert_called_once_with( | ||
| SNOMED_CODE, TEST_UUID | ||
| ) | ||
| mock_document_service.create_document_reference_fhir_response.assert_called_once_with( | ||
| MOCK_DOCUMENT_REFERENCE | ||
| ) | ||
|
|
||
|
|
||
| def test_extract_bearer_token_when_pdm(context): | ||
| token = extract_bearer_token(MOCK_MTLS_VALID_EVENT, context) | ||
| assert token is None | ||
|
|
||
|
|
||
| def test_extract_document_parameters_valid_pdm(): | ||
| document_id, snomed_code = extract_document_parameters(MOCK_MTLS_VALID_EVENT) | ||
| assert document_id == TEST_UUID | ||
| assert snomed_code == SNOMED_CODE |
75 changes: 75 additions & 0 deletions
75
lambdas/tests/unit/handlers/test_pdm_post_fhir_document_reference_handler.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import json | ||
|
|
||
| import pytest | ||
| from handlers.post_fhir_document_reference_handler import lambda_handler | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def valid_mtls_event(): | ||
| return { | ||
| "body": json.dumps( | ||
| { | ||
| "resourceType": "DocumentReference", | ||
| "subject": { | ||
| "identifier": { | ||
| "system": "https://fhir.nhs.uk/Id/nhs-number", | ||
| "value": "9000000009", | ||
| } | ||
| }, | ||
| } | ||
| ), | ||
| "headers": json.dumps( | ||
| { | ||
| "Accept": "text/json", | ||
| "Host": "example.com", | ||
| } | ||
| ), | ||
| "requestContext": json.dumps( | ||
| { | ||
| "accountId": "123456789012", | ||
| "apiId": "abc123", | ||
| "domainName": "api.example.com", | ||
| "identity": { | ||
| "sourceIp": "1.2.3.4", | ||
| "userAgent": "curl/7.64.1", | ||
| "clientCert": { | ||
| "clientCertPem": "-----BEGIN CERTIFICATE-----...", | ||
| "subjectDN": "CN=ndrclient.main.int.pdm.national.nhs.uk,O=NHS,C=UK", | ||
| "issuerDN": "CN=NHS Root CA,O=NHS,C=UK", | ||
| "serialNumber": "12:34:56", | ||
| "validity": { | ||
| "notBefore": "May 10 00:00:00 2024 GMT", | ||
| "notAfter": "May 10 00:00:00 2025 GMT", | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| ), | ||
| } | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_service(mocker): | ||
| mock_service = mocker.patch( | ||
| "handlers.post_fhir_document_reference_handler.PostFhirDocumentReferenceService" | ||
| ) | ||
| mock_service_instance = mock_service.return_value | ||
| return mock_service_instance | ||
|
|
||
|
|
||
| def test_mtls_lambda_handler_success(valid_mtls_event, context, mock_service): | ||
| """Test successful lambda execution.""" | ||
| mock_response = {"resourceType": "DocumentReference", "id": "test-id"} | ||
|
|
||
| mock_service.process_fhir_document_reference.return_value = json.dumps( | ||
| mock_response | ||
| ) | ||
|
|
||
| result = lambda_handler(valid_mtls_event, context) | ||
|
|
||
| assert result["statusCode"] == 200 | ||
| assert json.loads(result["body"]) == mock_response | ||
|
|
||
| mock_service.process_fhir_document_reference.assert_called_once_with( | ||
| valid_mtls_event["body"], valid_mtls_event["requestContext"] | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.