|
2 | 2 |
|
3 | 3 | from datetime import datetime |
4 | 4 |
|
5 | | -from constants import VALID_VERSIONS, EMPTY_BATCH_FILE_SIZE_IN_BYTES |
| 5 | +from constants import VALID_VERSIONS, EMPTY_BATCH_FILE_SIZE_IN_BYTES, EXPECTED_NUMBER_OF_FILE_KEY_PARTS, \ |
| 6 | + VALID_FILE_EXTENSIONS |
6 | 7 | from elasticache import get_valid_vaccine_types_from_cache, get_supplier_system_from_cache |
7 | 8 | from errors import InvalidFileKeyError, EmptyFileError |
8 | 9 |
|
@@ -45,7 +46,7 @@ def validate_file_key(file_key: str) -> tuple[str, str]: |
45 | 46 | raise InvalidFileKeyError("Initial file validation failed: missing file extension") |
46 | 47 |
|
47 | 48 | file_key_parts_without_extension = file_name_and_extension[0].split("_") |
48 | | - if len(file_key_parts_without_extension) < 5: |
| 49 | + if len(file_key_parts_without_extension) < EXPECTED_NUMBER_OF_FILE_KEY_PARTS: |
49 | 50 | raise InvalidFileKeyError("Initial file validation failed: not enough parts in file key") |
50 | 51 |
|
51 | 52 | vaccine_type = file_key_parts_without_extension[0] |
@@ -73,7 +74,7 @@ def validate_file_key(file_key: str) -> tuple[str, str]: |
73 | 74 | if not is_valid_datetime(timestamp): |
74 | 75 | raise InvalidFileKeyError("Initial file validation failed: invalid timestamp") |
75 | 76 |
|
76 | | - if extension not in ["CSV", "DAT"]: |
| 77 | + if extension not in VALID_FILE_EXTENSIONS: |
77 | 78 | raise InvalidFileKeyError("Initial file validation failed: unsupported file extension") |
78 | 79 |
|
79 | 80 | return vaccine_type, supplier |
|
0 commit comments