@@ -265,39 +265,44 @@ def test_pre_validation_failed(self):
265265 self .imms_repo .update_immunization .assert_not_called ()
266266 self .pds_service .get_patient_details .assert_not_called ()
267267
268- def test_post_validation_failed_get (self ):
269- self .mock_redis_client .hget .side_effect = [None , 'COVID-19' ]
270- valid_imms = create_covid_19_immunization_dict ("an-id" , VALID_NHS_NUMBER )
268+ def test_post_validation_failed_get_invalid_target_disease (self ):
269+ """it should raise CustomValidationError for invalid target disease code on get"""
270+ self .mock_redis_client .hget .return_value = None
271+ valid_imms = create_covid_19_immunization_dict ("an-id" , VALID_NHS_NUMBER )
271272
272- bad_target_disease_imms = deepcopy (valid_imms )
273- bad_target_disease_imms ["protocolApplied" ][0 ]["targetDisease" ][0 ]["coding" ][0 ]["code" ] = "bad-code"
274- bad_target_disease_msg = (
275- "Validation errors: protocolApplied[0].targetDisease[*].coding[?(@.system=='http://snomed.info/sct')].code"
276- + " - ['bad-code'] is not a valid combination of disease codes for this service"
277- )
273+ bad_target_disease_imms = deepcopy (valid_imms )
274+ bad_target_disease_imms ["protocolApplied" ][0 ]["targetDisease" ][0 ]["coding" ][0 ]["code" ] = "bad-code"
275+ bad_target_disease_msg = (
276+ "Validation errors: protocolApplied[0].targetDisease[*].coding[?(@.system=='http://snomed.info/sct')].code"
277+ + " - ['bad-code'] is not a valid combination of disease codes for this service"
278+ )
278279
279- bad_patient_name_imms = deepcopy (valid_imms )
280- del bad_patient_name_imms ["contained" ][1 ]["name" ][0 ]["given" ]
281- bad_patient_name_msg = "contained[?(@.resourceType=='Patient')].name[0].given is a mandatory field"
280+ fhir_service = FhirService (self .imms_repo , self .pds_service )
282281
283- fhir_service = FhirService (self .imms_repo , self .pds_service )
282+ with self .assertRaises (CustomValidationError ) as error :
283+ fhir_service .get_immunization_by_id_all ("an-id" , bad_target_disease_imms )
284284
285- # Invalid target_disease
286- with self .assertRaises ( CustomValidationError ) as error :
287- fhir_service . get_immunization_by_id_all ( "an-id" , bad_target_disease_imms )
285+ self . assertEqual ( bad_target_disease_msg , error . exception . message )
286+ self .imms_repo . get_immunization_by_id_all . assert_not_called ()
287+ self . pds_service . get_patient_details . assert_not_called ( )
288288
289- self .assertEqual (bad_target_disease_msg , error .exception .message )
290- self .imms_repo .get_immunization_by_id_all .assert_not_called ()
291- self .pds_service .get_patient_details .assert_not_called ()
289+ def test_post_validation_failed_get_missing_patient_name (self ):
290+ """it should raise CustomValidationError for missing patient name on get"""
291+ self .mock_redis_client .hget .return_value = 'COVID-19'
292+ valid_imms = create_covid_19_immunization_dict ("an-id" , VALID_NHS_NUMBER )
292293
293- # Missing patient name (Mandatory field )
294- with self . assertRaises ( CustomValidationError ) as error :
295- fhir_service . get_immunization_by_id_all ( "an-id" , bad_patient_name_imms )
294+ bad_patient_name_imms = deepcopy ( valid_imms )
295+ del bad_patient_name_imms [ "contained" ][ 1 ][ "name" ][ 0 ][ "given" ]
296+ bad_patient_name_msg = "contained[?(@.resourceType=='Patient')].name[0].given is a mandatory field"
296297
297- self .assertTrue (bad_patient_name_msg in error .exception .message )
298- self .imms_repo .get_immunization_by_id_all .assert_not_called ()
299- self .pds_service .get_patient_details .assert_not_called ()
298+ fhir_service = FhirService (self .imms_repo , self .pds_service )
299+
300+ with self .assertRaises (CustomValidationError ) as error :
301+ fhir_service .get_immunization_by_id_all ("an-id" , bad_patient_name_imms )
300302
303+ self .assertTrue (bad_patient_name_msg in error .exception .message )
304+ self .imms_repo .get_immunization_by_id_all .assert_not_called ()
305+ self .pds_service .get_patient_details .assert_not_called ()
301306
302307class TestGetImmunizationIdentifier (unittest .TestCase ):
303308 """Tests for FhirService.get_immunization_by_id"""
0 commit comments