1717
1818class TestFileKeyValidation (TestCase ):
1919 """Tests for file_key_validation functions"""
20- def setUp (self ):
21- redis_patcher = patch ("clients.redis_client.hkeys" , return_value = ["FLU" , "COVID19" , "MMR" , "RSV" ])
22- self .addCleanup (redis_patcher .stop )
23- redis_patcher .start ()
24-
2520 def test_is_valid_datetime (self ):
2621 "Tests that is_valid_datetime returns True for valid datetimes, and false otherwise"
2722 # Test case tuples are stuctured as (date_time_string, expected_result)
@@ -43,7 +38,8 @@ def test_is_valid_datetime(self):
4338 with self .subTest ():
4439 self .assertEqual (is_valid_datetime (date_time_string ), expected_result )
4540
46- def test_validate_file_key (self ):
41+ @patch ("elasticache.redis_client.hkeys" , return_value = ["FLU" , "RSV" ])
42+ def test_validate_file_key (self , _mock_hkeys ):
4743 """Tests that file_key_validation returns True if all elements pass validation, and False otherwise"""
4844 # Test case tuples are structured as (file_key, expected_result)
4945 test_cases_for_success_scenarios = [
@@ -60,6 +56,7 @@ def test_validate_file_key(self):
6056 for file_key , expected_result in test_cases_for_success_scenarios :
6157 with self .subTest (f"SubTest for file key: { file_key } " ):
6258 self .assertEqual (validate_file_key (file_key ), expected_result )
59+ _mock_hkeys .assert_called_with ("vacc_to_diseases" )
6360
6461 key_format_error_message = "Initial file validation failed: invalid file key format"
6562 invalid_file_key_error_message = "Initial file validation failed: invalid file key"
@@ -105,3 +102,4 @@ def test_validate_file_key(self):
105102 with self .assertRaises (InvalidFileKeyError ) as context :
106103 validate_file_key (file_key )
107104 self .assertEqual (str (context .exception ), expected_result )
105+ _mock_hkeys .assert_called_with ("vacc_to_diseases" )
0 commit comments