From 2949f8c889cb8e82f457a0f16e7040a5bb7cfe96 Mon Sep 17 00:00:00 2001 From: abbas-khan10 <127417949+abbas-khan10@users.noreply.github.com> Date: Fri, 22 Dec 2023 12:04:51 +0000 Subject: [PATCH] PRMDR-0000: Fix LG stitch document query --- lambdas/services/lloyd_george_stitch_service.py | 2 +- .../test_lloyd_george_record_stitch_handler.py | 6 ------ .../services/test_lloyd_george_stitch_service.py | 16 ++++++++-------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/lambdas/services/lloyd_george_stitch_service.py b/lambdas/services/lloyd_george_stitch_service.py index cb0700c46..538c73e55 100644 --- a/lambdas/services/lloyd_george_stitch_service.py +++ b/lambdas/services/lloyd_george_stitch_service.py @@ -86,7 +86,7 @@ def get_lloyd_george_record_for_patient( ) -> list[DocumentReference]: try: return self.document_service.fetch_available_document_references_by_type( - nhs_number, SupportedDocumentTypes.LG.value + nhs_number, SupportedDocumentTypes.LG ) except ClientError as e: logger.error(e, {"Result": f"Unsuccessful viewing LG due to {str(e)}"}) diff --git a/lambdas/tests/unit/handlers/test_lloyd_george_record_stitch_handler.py b/lambdas/tests/unit/handlers/test_lloyd_george_record_stitch_handler.py index 4b81ea9e7..a9ed1660a 100755 --- a/lambdas/tests/unit/handlers/test_lloyd_george_record_stitch_handler.py +++ b/lambdas/tests/unit/handlers/test_lloyd_george_record_stitch_handler.py @@ -14,8 +14,6 @@ ) from utils.lambda_response import ApiGatewayResponse -# Constants and fixtures - MOCK_CLIENT_ERROR = ClientError( {"Error": {"Code": "500", "Message": "test error"}}, "testing" ) @@ -59,7 +57,6 @@ def mock_s3(mocker): mocked_instance = mocker.patch( "services.lloyd_george_stitch_service.S3Service", spec=S3Service ).return_value - # mocked_instance.download_file.return_value = mocked_instance.create_download_presigned_url.return_value = MOCK_PRESIGNED_URL yield mocked_instance @@ -95,9 +92,6 @@ def mock_get_total_file_size(mocker): ) -# Unit tests begin here - - def test_lambda_handler_respond_with_200_and_presign_url( valid_id_event_without_auth_header, context, set_env, mock_stitch_service ): diff --git a/lambdas/tests/unit/services/test_lloyd_george_stitch_service.py b/lambdas/tests/unit/services/test_lloyd_george_stitch_service.py index 48a03c7dc..3e3f93502 100644 --- a/lambdas/tests/unit/services/test_lloyd_george_stitch_service.py +++ b/lambdas/tests/unit/services/test_lloyd_george_stitch_service.py @@ -3,6 +3,7 @@ import pytest from botocore.exceptions import ClientError +from enums.supported_document_types import SupportedDocumentTypes from models.document_reference import DocumentReference from pypdf.errors import PdfReadError from services.document_service import DocumentService @@ -10,8 +11,6 @@ from tests.unit.conftest import MOCK_LG_BUCKET, TEST_NHS_NUMBER, TEST_OBJECT_KEY from utils.lambda_exceptions import LGStitchServiceException -# Constants, helper and fixtures - def build_lg_doc_ref_list(page_numbers: list[int]) -> list[DocumentReference]: total_page_number = len(page_numbers) @@ -82,7 +81,7 @@ def patched_stitch_service(set_env, mocker): @pytest.fixture def mock_fetch_doc_ref_by_type(mocker): def mocked_method(nhs_number: str, doc_type: str): - if nhs_number == TEST_NHS_NUMBER and doc_type == "LG": + if nhs_number == TEST_NHS_NUMBER and doc_type == SupportedDocumentTypes.LG: return MOCK_LLOYD_GEORGE_DOCUMENT_REFS return [] @@ -132,9 +131,6 @@ def mock_get_total_file_size(mocker): ) -# Unit tests begin here - - def test_stitch_lloyd_george_record_happy_path( mock_tempfile, mock_stitch_pdf, @@ -255,7 +251,9 @@ def test_get_lloyd_george_record_for_patient( actual = stitch_service.get_lloyd_george_record_for_patient(TEST_NHS_NUMBER) assert actual == expected - mock_fetch_doc_ref_by_type.assert_called_with(TEST_NHS_NUMBER, "LG") + mock_fetch_doc_ref_by_type.assert_called_with( + TEST_NHS_NUMBER, SupportedDocumentTypes.LG + ) def test_get_lloyd_george_record_for_patient_return_empty_list_if_no_record( @@ -269,7 +267,9 @@ def test_get_lloyd_george_record_for_patient_return_empty_list_if_no_record( ) assert actual == expected - mock_fetch_doc_ref_by_type.assert_called_with(nhs_number_with_no_record, "LG") + mock_fetch_doc_ref_by_type.assert_called_with( + nhs_number_with_no_record, SupportedDocumentTypes.LG + ) def test_sort_documents_by_filenames_base_case(stitch_service):