Skip to content

Commit 8fea20e

Browse files
committed
add validation
1 parent 06bb140 commit 8fea20e

File tree

6 files changed

+12
-9
lines changed

6 files changed

+12
-9
lines changed

lambdas/filenameprocessor/src/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
ODS_CODE_TO_SUPPLIER_SYSTEM_HASH_KEY = "ods_code_to_supplier"
2424
EXTENDED_ATTRIBUTES_FILE_PREFIX = "Vaccination_Extended_Attributes"
2525
DPS_DESTINATION_PREFIX = "dps_destination/"
26-
VALID_EA_VERSIONS = "v1_5"
26+
VALID_EA_VERSIONS = "V1_5"
2727
ERROR_TYPE_TO_STATUS_CODE_MAP = {
2828
VaccineTypePermissionsError: 403,
2929
InvalidFileKeyError: 400, # Includes invalid ODS code, therefore unable to identify supplier

lambdas/filenameprocessor/src/file_validation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ def validate_extended_attributes_file_key(file_key: str) -> str:
5151
organization_code = file_key_parts_without_extension[5]
5252
timestamp = file_key_parts_without_extension[6]
5353
supplier = get_supplier_system_from_cache(organization_code)
54+
valid_vaccine_types = get_valid_vaccine_types_from_cache()
55+
vaccine_type = "COVID"
5456

5557
if not (
56-
file_type == EXTENDED_ATTRIBUTES_FILE_PREFIX
58+
vaccine_type in valid_vaccine_types
59+
and file_type == EXTENDED_ATTRIBUTES_FILE_PREFIX.upper()
5760
and version == VALID_EA_VERSIONS
5861
and supplier # Note that if supplier could be identified, this also implies that ODS code is valid
5962
and is_valid_datetime(timestamp)

lambdas/filenameprocessor/tests/test_file_key_validation.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ def test_split_file_key(self, _):
113113
with self.subTest(f"SubTest for file key: {file_key}"):
114114
self.assertEqual(split_file_key(file_key), expected)
115115

116-
@patch("file_name_processor.get_supplier_system_from_cache", return_value="RAVS") # supplier now VALID
117-
@patch("file_validation.get")
118-
def test_validate_extended_attributes_file_key(self, _):
116+
def test_validate_extended_attributes_file_key(self, mock_get_redis_client):
119117
"""Tests that validate_extended_attributes_file_key returns organization code and COVID vaccine type if all
120118
elements pass validation, and raises an exception otherwise"""
121119
test_cases_for_success_scenarios = [
@@ -133,6 +131,10 @@ def test_validate_extended_attributes_file_key(self, _):
133131

134132
for file_key, expected_result in test_cases_for_success_scenarios:
135133
with self.subTest(f"SubTest for file key: {file_key}"):
134+
mock_redis = Mock()
135+
mock_redis.hget.side_effect = create_mock_hget(MOCK_ODS_CODE_TO_SUPPLIER, {})
136+
mock_redis.hkeys.return_value = ["COVID"]
137+
mock_get_redis_client.return_value = mock_redis
136138
self.assertEqual(
137139
validate_extended_attributes_file_key(file_key),
138140
expected_result,

lambdas/filenameprocessor/tests/test_lambda_handler.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,6 @@ def test_lambda_handler_extended_attributes_success(self):
245245
Tests that for an extended attributes file (prefix starts with 'Vaccination_Extended_Attributes'):
246246
* The file is added to the audit table with a status of 'Processing'
247247
* The queue_name stored is the extended attribute identifier
248-
* The file is moved to the destination bucket under archive/
249-
* No SQS message is sent
250-
* No ack file is created
251248
"""
252249

253250
# Build an extended attributes file.

lambdas/filenameprocessor/tests/utils_for_tests/mock_environment_variables.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Sqs:
3636
MOCK_ENVIRONMENT_DICT = {
3737
"SOURCE_BUCKET_NAME": BucketNames.SOURCE,
3838
"ACK_BUCKET_NAME": BucketNames.DESTINATION,
39+
"MOCK_MOTO_ACCOUNT_ID": "123456789012",
3940
"QUEUE_URL": "https://sqs.eu-west-2.amazonaws.com/123456789012/imms-batch-file-created-queue.fifo",
4041
"REDIS_HOST": "localhost",
4142
"REDIS_PORT": "6379",

lambdas/filenameprocessor/tests/utils_for_tests/values_for_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class MockFileDetails:
9393
emis_rsv = FileDetails("EMIS", "RSV", "YGM41")
9494
ravs_flu = FileDetails("RAVS", "FLU", "X8E5B")
9595
extended_attributes_file = FileDetails(
96-
vaccine_type="Vaccination_Extended_Attributes", file_number=1, organization_code="RJ123"
96+
vaccine_type="Vaccination_Extended_Attributes", file_number=1, organization_code="YGM41"
9797
)
9898

9999

0 commit comments

Comments
 (0)