Skip to content

Commit 0e51819

Browse files
committed
Tests pass. Async-ly
1 parent 817f2f8 commit 0e51819

File tree

2 files changed

+19
-27
lines changed

2 files changed

+19
-27
lines changed

e2e_batch/test_e2e_batch.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
poll_destination,
1111
DestinationType,
1212
)
13+
import logging
14+
1315

1416
from constants import (
1517
SOURCE_BUCKET,
@@ -25,21 +27,26 @@
2527

2628
seed_datas = [
2729
TestData("Create", "V0V8L", [CREATE]),
28-
# TestData("Update", "8HK48", [CREATE, UPDATE]),
29-
# TestData("Delete", "8HA94", [CREATE, UPDATE, DELETE]),
30-
# TestData("Reinstate", "X26", [CREATE, DELETE, UPDATE]),
30+
TestData("Update", "8HK48", [CREATE, UPDATE]),
31+
TestData("Delete", "8HA94", [CREATE, UPDATE, DELETE]),
32+
TestData("Reinstate", "X26", [CREATE, DELETE, UPDATE]),
3133
# TestData("Update-Reinstate", "X8E5B", [CREATE, DELETE, UPDATE, UPDATE]),
3234
# TestData("Update-No Create", "YGM41", [UPDATE], success=False),
3335
# TestData("Delete-No Create", "YGJ", [DELETE], success=False),
3436
# TestData("Create with extended ascii characters in name", "YGA", [CREATE], inject_char=True),
3537
]
3638

39+
logging.basicConfig(level="INFO")
40+
logger = logging.getLogger()
41+
logger.setLevel("INFO")
42+
3743

3844
class TestE2EBatch(unittest.TestCase):
3945

4046
@unittest.skipIf(environment == "ref", "Skip for ref")
4147
def test_create_success(self):
4248
"""Test CREATE scenario."""
49+
start_time = time.time()
4350
max_timeout = 1200 # seconds
4451

4552
test_datas: list[TestData] = generate_csv_files(seed_datas)
@@ -62,17 +69,25 @@ def test_create_success(self):
6269
found_ack_key = poll_destination(test_data.file_name, ack_key)
6370
if found_ack_key:
6471
test_data.ack_keys[ack_key] = found_ack_key
72+
logging.info(f"Found {ack_key} ack for {test_data.file_name}: {found_ack_key}")
6573
else:
6674
pending = True
6775
if pending:
6876
time.sleep(1)
6977

78+
logging.info(f"Finished polling for acks. Time taken: {time.time() - start_time:.1f} seconds")
79+
7080
# Now validate all files have been processed correctly
7181
for test_data in test_datas:
7282
# Validate the ACK file
7383
inf_ack_content = get_file_content_from_s3(ACK_BUCKET, test_data.ack_keys[DestinationType.INF])
74-
bus_ack_content = get_file_content_from_s3(ACK_BUCKET, test_data.ack_keys[DestinationType.BUS])
7584

7685
check_ack_file_content(inf_ack_content, "Success", None, test_data.actions)
7786
validate_row_count(test_data.file_name, test_data.ack_keys[DestinationType.BUS])
87+
# check row after header
88+
7889
# how to validate bus ack content?
90+
# bus_ack_content = get_file_content_from_s3(ACK_BUCKET, test_data.ack_keys[DestinationType.BUS])
91+
92+
logging.info(f"Completed all validations. Total time taken: {time.time() - start_time:.1f} seconds")
93+

e2e_batch/utils.py

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

533531

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

0 commit comments

Comments
 (0)