Skip to content

Commit 9585507

Browse files
committed
debug
1 parent 61c0f16 commit 9585507

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

e2e_batch/test_e2e_batch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
generate_csv_files,
99
TestData,
1010
poll_destination,
11-
DestinationType
11+
DestinationType,
1212
)
1313

1414
from constants import (

e2e_batch/utils.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,8 @@ def verify_final_ack_file(file_key):
525525
def get_file_name(vax_type, ods, version="4"):
526526
timestamp = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%S00")
527527
# timestamp = timestamp[:-3]
528+
if is_valid_datetime(timestamp) is False:
529+
print("Timestamp is not valid")
528530
return f"{vax_type}_Vaccinations_v{version}_{ods}_{timestamp}.csv"
529531

530532

@@ -546,3 +548,24 @@ def generate_csv_file(seed: TestData, actions: str) -> str:
546548
file_name = get_file_name(seed.vax, seed.ods, seed.version)
547549
df.to_csv(file_name, index=False, sep="|", quoting=csv.QUOTE_MINIMAL)
548550
return file_name
551+
552+
553+
def is_valid_datetime(timestamp: str) -> bool:
554+
"""
555+
Returns a bool to indicate whether the timestamp is a valid datetime in the format 'YYYYmmddTHHMMSSzz'
556+
where 'zz' is a two digit number indicating the timezone
557+
"""
558+
# Check that datetime (excluding timezone) is a valid datetime in the expected format.
559+
print(f"Validating timestamp: {timestamp}")
560+
if len(timestamp) < 15:
561+
print("Timestamp is too short")
562+
return False
563+
564+
# Note that any digits after the seconds (i.e. from the 16th character onwards, usually expected to represent
565+
# timezone), do not need to be validated
566+
try:
567+
datetime.strptime(timestamp[:15], "%Y%m%dT%H%M%S")
568+
except ValueError:
569+
return False
570+
571+
return True

filenameprocessor/src/file_validation.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ def is_valid_datetime(timestamp: str) -> bool:
2020
where 'zz' is a two digit number indicating the timezone
2121
"""
2222
# Check that datetime (excluding timezone) is a valid datetime in the expected format.
23+
print(f"Validating timestamp: {timestamp}")
2324
if len(timestamp) < 15:
25+
print("Timestamp is too short")
2426
return False
2527

2628
# Note that any digits after the seconds (i.e. from the 16th character onwards, usually expected to represent
@@ -71,6 +73,14 @@ def validate_file_key(file_key: str) -> tuple[str, str]:
7173
print(f"supplier: {supplier} ")
7274
print(f"valid_vaccine_types: {valid_vaccine_types} ")
7375

76+
print(f"vaccine_type in valid_vaccine_types: {vaccine_type in valid_vaccine_types} ")
77+
print(f"vaccination == 'VACCINATIONS': {vaccination == 'VACCINATIONS'} ")
78+
print(f"version in VALID_VERSIONS: {version in VALID_VERSIONS} ")
79+
print(f"supplier: {supplier} ")
80+
print(f"is_valid_datetime(timestamp): {is_valid_datetime(timestamp)} ")
81+
print(f"extension check: {(extension == 'CSV') or (extension == 'DAT')} ")
82+
print("SAW ----------- END DEBUG -------------")
83+
7484
# Validate each file key element
7585
if not (
7686
vaccine_type in valid_vaccine_types

0 commit comments

Comments
 (0)