|
15 | 15 | from file_validation import ( |
16 | 16 | is_file_in_directory_root, |
17 | 17 | is_valid_datetime, |
| 18 | + split_file_key, |
18 | 19 | validate_batch_file_key, |
| 20 | + validate_extended_attributes_file_key, |
19 | 21 | ) |
20 | 22 | from models.errors import InvalidFileKeyError |
21 | 23 |
|
@@ -63,7 +65,7 @@ def test_is_valid_datetime(self, _): |
63 | 65 | with self.subTest(): |
64 | 66 | self.assertEqual(is_valid_datetime(date_time_string), expected_result) |
65 | 67 |
|
66 | | - def test_validate_file_key(self, mock_get_redis_client): |
| 68 | + def test_validate_batch_file_key(self, mock_get_redis_client): |
67 | 69 | """Tests that file_key_validation returns True if all elements pass validation, and False otherwise""" |
68 | 70 | # Test case tuples are structured as (file_key, expected_result) |
69 | 71 | test_cases_for_success_scenarios = [ |
@@ -94,6 +96,46 @@ def test_validate_file_key(self, mock_get_redis_client): |
94 | 96 | mock_redis.hkeys.assert_called_with("vacc_to_diseases") |
95 | 97 | mock_redis.hget.assert_called_with("ods_code_to_supplier", ods_code) |
96 | 98 |
|
| 99 | + def test_split_file_key(self, _): |
| 100 | + """Tests that split_file_key splits the file key into parts correctly""" |
| 101 | + test_cases = [ |
| 102 | + ( |
| 103 | + "FLU_Vaccinations_V5_YGM41_20000101T00000001.csv", |
| 104 | + (["FLU", "VACCINATIONS", "V5", "YGM41", "20000101T00000001"], "CSV"), |
| 105 | + ), |
| 106 | + ( |
| 107 | + "Vaccination_Extended_Attributes_V1_5_X8E5B_20000101T00000001.csv", |
| 108 | + (["VACCINATION", "EXTENDED", "ATTRIBUTES", "V1", "5", "X8E5B", "20000101T00000001"], "CSV"), |
| 109 | + ), |
| 110 | + ] |
| 111 | + |
| 112 | + for file_key, expected in test_cases: |
| 113 | + with self.subTest(f"SubTest for file key: {file_key}"): |
| 114 | + self.assertEqual(split_file_key(file_key), expected) |
| 115 | + |
| 116 | + def test_validate_extended_attributes_file_key(self, _): |
| 117 | + """Tests that validate_extended_attributes_file_key returns organization code and COVID vaccine type if all |
| 118 | + elements pass validation, and raises an exception otherwise""" |
| 119 | + test_cases_for_success_scenarios = [ |
| 120 | + # Valid extended attributes file key |
| 121 | + ( |
| 122 | + "Vaccination_Extended_Attributes_v1_5_X8E5B_20000101T00000001.csv", |
| 123 | + "X8E5B_COVID", |
| 124 | + ), |
| 125 | + # Valid extended attributes file key with different organization code |
| 126 | + ( |
| 127 | + "Vaccination_Extended_Attributes_v1_5_YGM41_20221231T23595999.csv", |
| 128 | + "YGM41_COVID", |
| 129 | + ), |
| 130 | + ] |
| 131 | + |
| 132 | + for file_key, expected_result in test_cases_for_success_scenarios: |
| 133 | + with self.subTest(f"SubTest for file key: {file_key}"): |
| 134 | + self.assertEqual( |
| 135 | + validate_extended_attributes_file_key(file_key), |
| 136 | + expected_result, |
| 137 | + ) |
| 138 | + |
97 | 139 | def test_validate_file_key_false(self, mock_get_redis_client): |
98 | 140 | """Tests that file_key_validation returns False if elements do not pass validation""" |
99 | 141 | invalid_file_key_error_message = "Initial file validation failed: invalid file key" |
|
0 commit comments