-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
49 additions
and
93 deletions.
There are no files selected for viewing
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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
116 changes: 40 additions & 76 deletions
116
lambdas/tests/unit/handlers/test_nrl_get_document_reference_handler.py
This file contains 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 |
---|---|---|
@@ -1,85 +1,49 @@ | ||
from tests.unit.conftest import FAKE_URL, TEST_UUID | ||
from tests.unit.services.test_authoriser_service import MOCK_SESSION_ID | ||
import json | ||
|
||
import pytest | ||
from enums.lambda_error import LambdaError | ||
from handlers.nrl_get_document_reference_handler import lambda_handler | ||
from tests.unit.conftest import TEST_UUID | ||
from utils.lambda_exceptions import NRLGetDocumentReferenceException | ||
|
||
MOCK_VALID_EVENT = { | ||
"resource": "/DocumentReference/{id}", | ||
"path": "/DocumentReference/2", | ||
"httpMethod": "GET", | ||
"headers": { | ||
"Accept": "*/*", | ||
"Accept-Encoding": "gzip, deflate, br", | ||
"Authorization": f"Bearer {TEST_UUID}", | ||
"Cache-Control": "no-cache", | ||
"Host": FAKE_URL, | ||
"NHSD-Correlation-ID": TEST_UUID, | ||
"NHSD-ID-Token": f"MOCK_JWT{TEST_UUID}", | ||
"NHSD-Request-ID": "", | ||
"NHSD-Session-URID": MOCK_SESSION_ID, | ||
"NHSD-Session-UUID": MOCK_SESSION_ID, | ||
"Postman-Token": TEST_UUID, | ||
"User-Agent": "PostmanRuntime", | ||
"X-Amzn-Trace-Id": f"Root={TEST_UUID}", | ||
"X-API-Key": TEST_UUID, | ||
"X-Forwarded-For": "num", | ||
"X-Forwarded-Port": "port", | ||
"X-Forwarded-Proto": "https", | ||
}, | ||
"multiValueHeaders": { | ||
"Accept": ["*/*"], | ||
"Accept-Encoding": ["gzip, deflate, br"], | ||
"Authorization": [f"Bearer {TEST_UUID}"], | ||
"Cache-Control": ["no-cache"], | ||
"Host": [FAKE_URL], | ||
"NHSD-Correlation-ID": [TEST_UUID], | ||
"NHSD-ID-Token": [f"MOCK_JWT{TEST_UUID}"], | ||
"NHSD-Request-ID": [""], | ||
"NHSD-Session-URID": [MOCK_SESSION_ID], | ||
"NHSD-Session-UUID": [MOCK_SESSION_ID], | ||
"Postman-Token": [TEST_UUID], | ||
"User-Agent": ["PostmanRuntime"], | ||
"X-Amzn-Trace-Id": [f"Root={TEST_UUID}"], | ||
"X-API-Key": [TEST_UUID], | ||
"X-Forwarded-For": ["num"], | ||
"X-Forwarded-Port": ["num"], | ||
"X-Forwarded-Proto": ["https"], | ||
}, | ||
"queryStringParameters": None, | ||
"multiValueQueryStringParameters": None, | ||
"pathParameters": {"id": TEST_UUID}, | ||
"stageVariables": None, | ||
"requestContext": { | ||
"resourceId": TEST_UUID, | ||
"resourcePath": "/DocumentReference/{id}", | ||
"httpMethod": "GET", | ||
"extendedRequestId": "", | ||
"requestTime": "05/Dec/2024:15:36:37 +0000", | ||
"path": f"/DocumentReference/{TEST_UUID}", | ||
"accountId": TEST_UUID, | ||
"protocol": "HTTP/1.1", | ||
"stage": "dev", | ||
"domainPrefix": "ndr-", | ||
"requestTimeEpoch": 1733412997840, | ||
"requestId": TEST_UUID, | ||
"identity": { | ||
"cognitoIdentityPoolId": None, | ||
"cognitoIdentityId": None, | ||
"apiKey": TEST_UUID, | ||
"principalOrgId": None, | ||
"cognitoAuthenticationType": None, | ||
"userArn": None, | ||
"apiKeyId": TEST_UUID, | ||
"userAgent": "PostmanRuntime", | ||
"accountId": None, | ||
"caller": None, | ||
"sourceIp": "IP", | ||
"accessKey": None, | ||
"cognitoAuthenticationProvider": None, | ||
"user": None, | ||
}, | ||
"domainName": FAKE_URL, | ||
"deploymentId": "????", | ||
"apiId": TEST_UUID, | ||
}, | ||
"body": None, | ||
"isBase64Encoded": False, | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def mock_service(mocker): | ||
mocked_class = mocker.patch( | ||
"handlers.nrl_get_document_reference_handler.NRLGetDocumentReferenceService" | ||
) | ||
mocker.patch( | ||
"handlers.nrl_get_document_reference_handler.DynamicConfigurationService" | ||
) | ||
mocked_instance = mocked_class.return_value | ||
mocked_class.return_value.handle_get_document_reference_request.return_value = ( | ||
"test_document_reference" | ||
) | ||
return mocked_instance | ||
|
||
|
||
def test_lambda_handler_happy_path(set_env, mock_service, context): | ||
response = lambda_handler(MOCK_VALID_EVENT, context) | ||
assert response["statusCode"] == 200 | ||
|
||
|
||
def test_lambda_handler_error(set_env, mock_service, context): | ||
expected_exception = { | ||
"resourceType": "OperationOutcome", | ||
"issue": [{"severity": "error", "code": "AB_XXXX", "details": "Client error"}], | ||
} | ||
mock_service.handle_get_document_reference_request.side_effect = ( | ||
NRLGetDocumentReferenceException(400, LambdaError.MockError) | ||
) | ||
response = lambda_handler(MOCK_VALID_EVENT, context) | ||
assert response["statusCode"] == 400 | ||
assert response["body"] == json.dumps(expected_exception) |
This file contains 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