From d725903c565f03c000df7fccc808233fcaee32e6 Mon Sep 17 00:00:00 2001 From: Joe Fong Date: Fri, 17 May 2024 17:44:37 +0100 Subject: [PATCH] [PRMDR-873] improve coverage --- .../services/test_mock_pds_api_service.py | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/lambdas/tests/unit/services/test_mock_pds_api_service.py b/lambdas/tests/unit/services/test_mock_pds_api_service.py index 528f6f3e1..5fe0a4253 100644 --- a/lambdas/tests/unit/services/test_mock_pds_api_service.py +++ b/lambdas/tests/unit/services/test_mock_pds_api_service.py @@ -1,25 +1,13 @@ -import json - +import pytest from models.pds_models import PatientDetails -from requests.models import Response from services.mock_pds_service import MockPdsApiService -from tests.unit.helpers.data.pds.pds_patient_response import PDS_PATIENT - -pds_service = MockPdsApiService() - - -def test_fetch_patient_details_valid_returns_PatientDetails(mocker): - nhs_number = "9000000025" +from utils.exceptions import PatientNotFoundException - response = Response() - response.status_code = 200 - response._content = json.dumps(PDS_PATIENT).encode("utf-8") - mocker.patch( - "services.mock_pds_service.MockPdsApiService.pds_request", - return_value=response, - ) +def test_fetch_patient_details_valid_returns_PatientDetails(): + nhs_number = "9000000002" + pds_service = MockPdsApiService() actual = pds_service.fetch_patient_details(nhs_number) expected = PatientDetails( @@ -27,11 +15,19 @@ def test_fetch_patient_details_valid_returns_PatientDetails(mocker): familyName="Smith", birthDate="2010-10-22", postalCode="LS1 6AE", - nhsNumber="9000000009", + nhsNumber="9000000002", superseded=False, restricted=False, - generalPracticeOds="Y12345", + generalPracticeOds="H81109", active=True, ) assert actual == expected + + +def test_fetch_patient_details_valid_raise_patient_not_found_exception_if_mock_patient_not_exist(): + nhs_number = "987654321" + + pds_service = MockPdsApiService() + with pytest.raises(PatientNotFoundException): + pds_service.fetch_patient_details(nhs_number)