Skip to content

Commit ee5f86b

Browse files
committed
add test for file validation
1 parent 00f639f commit ee5f86b

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

lambdas/filenameprocessor/tests/test_file_key_validation.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
from file_validation import (
1616
is_file_in_directory_root,
1717
is_valid_datetime,
18+
split_file_key,
1819
validate_batch_file_key,
20+
validate_extended_attributes_file_key,
1921
)
2022
from models.errors import InvalidFileKeyError
2123

@@ -63,7 +65,7 @@ def test_is_valid_datetime(self, _):
6365
with self.subTest():
6466
self.assertEqual(is_valid_datetime(date_time_string), expected_result)
6567

66-
def test_validate_file_key(self, mock_get_redis_client):
68+
def test_validate_batch_file_key(self, mock_get_redis_client):
6769
"""Tests that file_key_validation returns True if all elements pass validation, and False otherwise"""
6870
# Test case tuples are structured as (file_key, expected_result)
6971
test_cases_for_success_scenarios = [
@@ -94,6 +96,46 @@ def test_validate_file_key(self, mock_get_redis_client):
9496
mock_redis.hkeys.assert_called_with("vacc_to_diseases")
9597
mock_redis.hget.assert_called_with("ods_code_to_supplier", ods_code)
9698

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+
97139
def test_validate_file_key_false(self, mock_get_redis_client):
98140
"""Tests that file_key_validation returns False if elements do not pass validation"""
99141
invalid_file_key_error_message = "Initial file validation failed: invalid file key"

0 commit comments

Comments
 (0)