@@ -139,7 +139,8 @@ def test_pre_validation_failed(self):
139139 self .assertEqual (error .exception .message , expected_msg )
140140 self .imms_repo .update_immunization .assert_not_called ()
141141
142- def test_post_validation_failed_get_by_all (self ):
142+ def test_post_validation_failed_get_by_all_invalid_target_disease (self ):
143+ """it should raise CustomValidationError for invalid target disease code"""
143144 self .mock_redis_client .hget .return_value = None
144145 valid_imms = create_covid_19_immunization_dict ("an-id" , VALID_NHS_NUMBER )
145146
@@ -150,29 +151,31 @@ def test_post_validation_failed_get_by_all(self):
150151 + ".code - ['bad-code'] is not a valid combination of disease codes for this service"
151152 )
152153
153- bad_patient_name_imms = deepcopy (valid_imms )
154- del bad_patient_name_imms ["contained" ][1 ]["name" ][0 ]["given" ]
155- bad_patient_name_msg = ("contained[?(@.resourceType=='Patient')].name[0].given is a mandatory field" )
156-
157154 fhir_service = FhirService (self .imms_repo , self .pds_service )
158155
159- # Invalid target_disease
160156 with self .assertRaises (CustomValidationError ) as error :
161157 fhir_service .get_immunization_by_id_all ("an-id" , bad_target_disease_imms )
162158
163159 self .assertEqual (bad_target_disease_msg , error .exception .message )
164-
165160 self .imms_repo .get_immunization_by_id_all .assert_not_called ()
161+
162+ def test_post_validation_failed_get_by_all_missing_patient_name (self ):
163+ """it should raise CustomValidationError for missing patient name"""
166164 self .mock_redis_client .hget .return_value = 'COVID-19'
165+ valid_imms = create_covid_19_immunization_dict ("an-id" , VALID_NHS_NUMBER )
166+
167+ bad_patient_name_imms = deepcopy (valid_imms )
168+ del bad_patient_name_imms ["contained" ][1 ]["name" ][0 ]["given" ]
169+ bad_patient_name_msg = "contained[?(@.resourceType=='Patient')].name[0].given is a mandatory field"
170+
171+ fhir_service = FhirService (self .imms_repo , self .pds_service )
167172
168- # Missing patient name (Mandatory field)
169173 with self .assertRaises (CustomValidationError ) as error :
170174 fhir_service .get_immunization_by_id_all ("an-id" , bad_patient_name_imms )
171175
172176 self .assertTrue (bad_patient_name_msg in error .exception .message )
173177 self .imms_repo .get_immunization_by_id_all .assert_not_called ()
174178
175-
176179class TestGetImmunization (TestFhirServiceBase ):
177180 """Tests for FhirService.get_immunization_by_id"""
178181
0 commit comments