Skip to content

Commit

Permalink
PRMDR-0000: Fix LG stitch document query
Browse files Browse the repository at this point in the history
  • Loading branch information
abbas-khan10 authored Dec 22, 2023
1 parent 02cae4e commit 2949f8c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lambdas/services/lloyd_george_stitch_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
)
from utils.lambda_response import ApiGatewayResponse

# Constants and fixtures

MOCK_CLIENT_ERROR = ClientError(
{"Error": {"Code": "500", "Message": "test error"}}, "testing"
)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
):
Expand Down
16 changes: 8 additions & 8 deletions lambdas/tests/unit/services/test_lloyd_george_stitch_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

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
from services.lloyd_george_stitch_service import LloydGeorgeStitchService
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)
Expand Down Expand Up @@ -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 []

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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):
Expand Down

0 comments on commit 2949f8c

Please sign in to comment.