@@ -17,7 +17,6 @@ def setUp(self):
1717 self .json_data = load_json_data (filename = "completed_mmr_immunization_event.json" )
1818 self .redis_patcher = patch ("models.utils.validation_utils.redis_client" )
1919 self .mock_redis_client = self .redis_patcher .start ()
20- self .mock_redis_client .hget .side_effect = mock_redis_hget
2120
2221 def tearDown (self ):
2322 """Tear down after each test. This runs after every test"""
@@ -38,6 +37,7 @@ def test_convert_disease_codes_to_vaccine_type(self):
3837 (["36653000" , "14189004" , "36989005" ], "MMR" ),
3938 (["55735004" ], "RSV" )
4039 ]
40+ self .mock_redis_client .hget .side_effect = ['COVID19' , 'FLU' , 'HPV' , 'MMR' , 'MMR' , 'MMR' , 'RSV' ]
4141
4242 for combination , vaccine_type in valid_combinations :
4343 self .assertEqual (convert_disease_codes_to_vaccine_type (combination ), vaccine_type )
@@ -50,6 +50,8 @@ def test_convert_disease_codes_to_vaccine_type(self):
5050 ["14189004" , "36989005" , "36653000" , "840539006" ],
5151 ]
5252
53+ self .mock_redis_client .hget .side_effect = None
54+ self .mock_redis_client .hget .return_value = None # Simulate no match in Redis for invalid combinations
5355 for invalid_combination in invalid_combinations :
5456 with self .assertRaises (ValueError ):
5557 convert_disease_codes_to_vaccine_type (invalid_combination )
@@ -59,12 +61,14 @@ def test_get_vaccine_type(self):
5961 Test that get_vaccine_type returns the correct vaccine type when given valid json data with a
6062 valid combination of target disease code, or raises an appropriate error otherwise
6163 """
64+ self .mock_redis_client .hget .return_value = 'RSV'
6265 # TEST VALID DATA
6366 valid_json_data = load_json_data (filename = f"completed_rsv_immunization_event.json" )
6467 # print(valid_json_data)
6568 vac_type = get_vaccine_type (valid_json_data )
6669 self .assertEqual (vac_type , "RSV" )
6770
71+ self .mock_redis_client .hget .return_value = "FLU"
6872 # VALID DATA: coding field with multiple coding systems including SNOMED
6973 flu_json_data = load_json_data (filename = f"completed_flu_immunization_event.json" )
7074 valid_target_disease_element = {
@@ -77,6 +81,7 @@ def test_get_vaccine_type(self):
7781 self .assertEqual (get_vaccine_type (flu_json_data ), "FLU" )
7882
7983 # TEST INVALID DATA FOR SINGLE TARGET DISEASE
84+ self .mock_redis_client .hget .return_value = None # Reset mock for invalid cases
8085 covid_19_json_data = load_json_data (
8186 filename = f"completed_covid19_immunization_event.json"
8287 )
0 commit comments