Skip to content

Commit ab6564a

Browse files
[PRMP-434] Bulk upload not reporting patient not found errors (#797)
1 parent ba24ee0 commit ab6564a

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lambdas/services/bulk_upload_service.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
DocumentInfectedException,
2424
InvalidMessageException,
2525
InvalidNhsNumberException,
26+
PatientNotFoundException,
2627
PatientRecordAlreadyExistException,
2728
PdsErrorException,
2829
PdsTooManyRequestsException,
@@ -180,6 +181,7 @@ def handle_sqs_message(self, message: dict):
180181
except (
181182
InvalidNhsNumberException,
182183
LGInvalidFilesException,
184+
PatientNotFoundException,
183185
PatientRecordAlreadyExistException,
184186
) as error:
185187
logger.info(

lambdas/tests/unit/services/test_bulk_upload_service.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
BulkUploadException,
4747
DocumentInfectedException,
4848
InvalidMessageException,
49+
PatientNotFoundException,
4950
PatientRecordAlreadyExistException,
5051
PdsTooManyRequestsException,
5152
S3FileNotFoundException,
@@ -1069,3 +1070,25 @@ def test_concatenate_acceptance_reason(repo_under_test):
10691070
actual_reason, another_test_reason
10701071
)
10711072
assert another_actual_reason == test_reason + ", " + another_test_reason
1073+
1074+
1075+
def test_patient_not_found_is_caught_and_written_to_dynamo(
1076+
repo_under_test, mock_validate_files, mocker
1077+
):
1078+
expected_error_message = "Could not find the given patient on PDS"
1079+
mocker.patch(
1080+
"services.bulk_upload_service.getting_patient_info_from_pds",
1081+
side_effect=PatientNotFoundException(expected_error_message),
1082+
)
1083+
1084+
repo_under_test.handle_sqs_message(message=TEST_SQS_MESSAGE)
1085+
1086+
repo_under_test.dynamo_repository.write_report_upload_to_dynamo.assert_called_once()
1087+
1088+
call_metadata, call_status, call_reason, call_ods_code = (
1089+
repo_under_test.dynamo_repository.write_report_upload_to_dynamo.call_args[0]
1090+
)
1091+
1092+
assert call_status == UploadStatus.FAILED
1093+
assert call_reason == expected_error_message
1094+
assert call_metadata == TEST_STAGING_METADATA

0 commit comments

Comments
 (0)