Skip to content

Commit 46e096a

Browse files
committed
break up test_post_validation_failed
1 parent e217a24 commit 46e096a

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

backend/tests/test_fhir_service.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,9 @@ def test_pre_validation_failed(self):
417417
self.imms_repo.create_immunization.assert_not_called()
418418
self.pds_service.get_patient_details.assert_not_called()
419419

420-
def test_post_validation_failed(self):
421-
"""it should throw exception if Immunization is not valid"""
422-
self.mock_redis_client.hget.side_effect = [None, 'COVID-19']
420+
def test_post_validation_failed_create_invalid_target_disease(self):
421+
"""it should raise CustomValidationError for invalid target disease code on create"""
422+
self.mock_redis_client.hget.return_value = None
423423
valid_imms = create_covid_19_immunization_dict_no_id(VALID_NHS_NUMBER)
424424

425425
bad_target_disease_imms = deepcopy(valid_imms)
@@ -429,24 +429,28 @@ def test_post_validation_failed(self):
429429
+ ".code - ['bad-code'] is not a valid combination of disease codes for this service"
430430
)
431431

432-
bad_patient_name_imms = deepcopy(valid_imms)
433-
del bad_patient_name_imms["contained"][1]["name"][0]["given"]
434-
bad_patient_name_msg = (
435-
"contained[?(@.resourceType=='Patient')].name[0].given is a mandatory field"
436-
)
437-
438432
fhir_service = FhirService(self.imms_repo, self.pds_service)
439433

440-
# Create
441-
# Invalid target_disease
442434
with self.assertRaises(CustomValidationError) as error:
443435
fhir_service.create_immunization(bad_target_disease_imms, "COVID19:create", "Test")
444436

445437
self.assertEqual(bad_target_disease_msg, error.exception.message)
446438
self.imms_repo.create_immunization.assert_not_called()
447439
self.pds_service.get_patient_details.assert_not_called()
448440

449-
# Missing patient name (Mandatory field)
441+
def test_post_validation_failed_create_missing_patient_name(self):
442+
"""it should raise CustomValidationError for missing patient name on create"""
443+
self.mock_redis_client.hget.return_value = 'COVID-19'
444+
valid_imms = create_covid_19_immunization_dict_no_id(VALID_NHS_NUMBER)
445+
446+
bad_patient_name_imms = deepcopy(valid_imms)
447+
del bad_patient_name_imms["contained"][1]["name"][0]["given"]
448+
bad_patient_name_msg = (
449+
"contained[?(@.resourceType=='Patient')].name[0].given is a mandatory field"
450+
)
451+
452+
fhir_service = FhirService(self.imms_repo, self.pds_service)
453+
450454
with self.assertRaises(CustomValidationError) as error:
451455
fhir_service.create_immunization(bad_patient_name_imms, "COVID19:create", "Test")
452456

0 commit comments

Comments
 (0)