|
5 | 5 |
|
6 | 6 | from tests.utils_for_tests.values_for_tests import MockFileDetails |
7 | 7 | from tests.utils_for_tests.mock_environment_variables import MOCK_ENVIRONMENT_DICT |
| 8 | +from tests.utils_for_tests.utils_for_filenameprocessor_tests import MOCK_ODS_CODE_TO_SUPPLIER, create_mock_hget |
8 | 9 |
|
9 | 10 | # Ensure environment variables are mocked before importing from src files |
10 | 11 | with patch.dict("os.environ", MOCK_ENVIRONMENT_DICT): |
@@ -38,25 +39,27 @@ def test_is_valid_datetime(self): |
38 | 39 | with self.subTest(): |
39 | 40 | self.assertEqual(is_valid_datetime(date_time_string), expected_result) |
40 | 41 |
|
| 42 | + @patch("elasticache.redis_client.hget", side_effect=create_mock_hget(MOCK_ODS_CODE_TO_SUPPLIER, {})) |
41 | 43 | @patch("elasticache.redis_client.hkeys", return_value=["FLU", "RSV"]) |
42 | | - def test_validate_file_key(self, _mock_hkeys): |
| 44 | + def test_validate_file_key(self, mock_hkeys, mock_hget): |
43 | 45 | """Tests that file_key_validation returns True if all elements pass validation, and False otherwise""" |
44 | 46 | # Test case tuples are structured as (file_key, expected_result) |
45 | 47 | test_cases_for_success_scenarios = [ |
46 | 48 | # Valid FLU/ EMIS file key (mixed case) |
47 | | - (VALID_FLU_EMIS_FILE_KEY, ("FLU", "EMIS")), |
| 49 | + (VALID_FLU_EMIS_FILE_KEY, "YGM41", ("FLU", "EMIS")), |
48 | 50 | # Valid FLU/ EMIS (all lowercase) |
49 | | - (VALID_FLU_EMIS_FILE_KEY.lower(), ("FLU", "EMIS")), |
| 51 | + (VALID_FLU_EMIS_FILE_KEY.lower(), "YGM41", ("FLU", "EMIS")), |
50 | 52 | # Valid FLU/ EMIS (all uppercase) |
51 | | - (VALID_FLU_EMIS_FILE_KEY.upper(), ("FLU", "EMIS")), |
| 53 | + (VALID_FLU_EMIS_FILE_KEY.upper(), "YGM41", ("FLU", "EMIS")), |
52 | 54 | # Valid RSV/ RAVS file key |
53 | | - (VALID_RSV_RAVS_FILE_KEY, ("RSV", "RAVS")), |
| 55 | + (VALID_RSV_RAVS_FILE_KEY, "X8E5B", ("RSV", "RAVS")), |
54 | 56 | ] |
55 | 57 |
|
56 | | - for file_key, expected_result in test_cases_for_success_scenarios: |
| 58 | + for file_key, ods_code, expected_result in test_cases_for_success_scenarios: |
57 | 59 | with self.subTest(f"SubTest for file key: {file_key}"): |
58 | 60 | self.assertEqual(validate_file_key(file_key), expected_result) |
59 | | - _mock_hkeys.assert_called_with("vacc_to_diseases") |
| 61 | + mock_hkeys.assert_called_with("vacc_to_diseases") |
| 62 | + mock_hget.assert_called_with("ods_code_to_supplier", ods_code) |
60 | 63 |
|
61 | 64 | key_format_error_message = "Initial file validation failed: invalid file key format" |
62 | 65 | invalid_file_key_error_message = "Initial file validation failed: invalid file key" |
@@ -102,4 +105,4 @@ def test_validate_file_key(self, _mock_hkeys): |
102 | 105 | with self.assertRaises(InvalidFileKeyError) as context: |
103 | 106 | validate_file_key(file_key) |
104 | 107 | self.assertEqual(str(context.exception), expected_result) |
105 | | - _mock_hkeys.assert_called_with("vacc_to_diseases") |
| 108 | + mock_hkeys.assert_called_with("vacc_to_diseases") |
0 commit comments