Skip to content

Commit e3832c3

Browse files
committed
rebuild
1 parent 59bf020 commit e3832c3

File tree

3 files changed

+200
-91
lines changed

3 files changed

+200
-91
lines changed

e2e_batch/clients.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
dynamodb = boto3_resource("dynamodb", region_name=REGION)
1616
table_name = f"imms-{environment}-imms-events"
1717
table = dynamodb.Table(table_name)
18+
audit_table_name = f"immunisation-batch-{environment}-audit-table"
19+
audit_table = dynamodb.Table(audit_table_name)
1820
# Logger
1921
logging.basicConfig(level="INFO")
2022
logger = logging.getLogger()

e2e_batch/test_e2e_batch.py

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
from utils import (
44
upload_file_to_s3,
55
get_file_content_from_s3,
6-
check_ack_file_content,
7-
validate_row_count,
6+
# check_ack_file_content,
7+
check_inf_file_content,
8+
# validate_row_count,
89
generate_csv_files,
10+
# OpMsgs,
911
TestData,
1012
DestinationType,
13+
# BusRowResult,
14+
cleanup
1115
)
12-
import logging
16+
from clients import logger
1317

1418

1519
from constants import (
@@ -19,64 +23,73 @@
1923
environment
2024
)
2125

22-
CREATE = "CREATE"
26+
NEW = "NEW"
2327
UPDATE = "UPDATE"
2428
DELETE = "DELETE"
2529

2630

27-
seed_datas = [
28-
TestData("Create", "V0V8L", [CREATE]),
29-
TestData("Update", "8HK48", [CREATE, UPDATE]),
30-
TestData("Delete", "8HA94", [CREATE, UPDATE, DELETE]),
31-
TestData("Reinstate", "X26", [CREATE, DELETE, UPDATE]),
32-
TestData("Update no Create", "YGM41", [UPDATE], success=False),
33-
TestData("Delete no Create", "YGJ", [DELETE], success=False),
34-
TestData("Create with extended ascii characters in name", "YGA", [CREATE], inject_char=True),
35-
]
36-
37-
logging.basicConfig(level="INFO")
38-
logger = logging.getLogger()
39-
logger.setLevel("INFO")
40-
41-
4231
class TestE2EBatch(unittest.TestCase):
4332

33+
def setUp(self):
34+
self.seed_datas = [
35+
TestData("Create", "V0V8L", ["CREATE"]),
36+
TestData("Update", "8HK48", ["CREATE", UPDATE]),
37+
# TestData("Delete", "8HA94", [NEW, UPDATE, DELETE]),
38+
# TestData("Reinstate", "X26", [NEW, DELETE, UPDATE]),
39+
# TestData("Update no Create", "YGM41", [UPDATE], expected=BusRowResult.FATAL_ERROR,
40+
# operation_outcome=OpMsgs.IMM_NOT_EXIST),
41+
# TestData("Delete no Create", "YGJ", [DELETE], expected=BusRowResult.FATAL_ERROR,
42+
# operation_outcome=OpMsgs.IMM_NOT_EXIST),
43+
# TestData("Create with extended ascii characters in name", "YGA", [NEW], inject_char=True),
44+
]
45+
46+
def tearDown(self):
47+
# loop through all files and delete them from s3
48+
cleanup(self.seed_datas)
49+
4450
@unittest.skipIf(environment == "ref", "Skip for ref")
4551
def test_create_success(self):
4652
"""Test CREATE scenario."""
4753
start_time = time.time()
4854
max_timeout = 1200 # seconds
4955

50-
test_datas: list[TestData] = generate_csv_files(seed_datas)
56+
tests: list[TestData] = generate_csv_files(self.seed_datas)
5157

52-
for test_data in test_datas:
53-
logging.info(f"Upload {test_data.file_name}")
54-
key = upload_file_to_s3(test_data.file_name, SOURCE_BUCKET, INPUT_PREFIX)
55-
test_data.key = key
58+
for test in tests:
59+
logger.info(f"Upload for Test: {test.name} ")
60+
key = upload_file_to_s3(test.file_name, SOURCE_BUCKET, INPUT_PREFIX)
61+
test.key = key
5662

63+
logger.info(f"Uploaded all files. Time: {time.time() - start_time:.1f} seconds")
64+
logger.info("Waiting while processing...")
5765
# dictionary of file name to track whether inf and bus acks have been received
5866
start_time = time.time()
5967
# while there are still pending files, poll for acks and forwarded files
6068
pending = True
6169
while pending and (time.time() - start_time) < max_timeout:
6270
pending = False
63-
for test_data in test_datas:
64-
pending = test_data.poll_destination(pending, logging)
71+
for test in tests:
72+
pending = test.poll_destination(pending)
6573
if pending:
66-
time.sleep(1)
74+
print(".", end="")
75+
time.sleep(5)
6776

68-
logging.info(f"Finished polling for acks. Time taken: {time.time() - start_time:.1f} seconds")
77+
logger.info(f"Files Processed. Time: {time.time() - start_time:.1f} seconds")
6978

7079
# Now validate all files have been processed correctly
71-
for test_data in test_datas:
80+
for test in tests:
81+
logger.info(f"Validation for Test: {test.name} ")
7282
# Validate the ACK file
73-
inf_ack_content = get_file_content_from_s3(ACK_BUCKET, test_data.ack_keys[DestinationType.INF])
83+
# inf_ack_content = get_file_content_from_s3(ACK_BUCKET, test.ack_keys[DestinationType.INF])
7484

75-
check_ack_file_content(inf_ack_content, "Success", None, test_data.actions)
76-
validate_row_count(test_data.file_name, test_data.ack_keys[DestinationType.BUS])
85+
# check_ack_file_content(test.name, inf_ack_content, "Success", None, test.actions)
86+
# validate_row_count(f"{test.name} - inf", test.file_name, test.ack_keys[DestinationType.BUS])
7787
# check row after header
88+
# bus_ack_content = get_file_content_from_s3(ACK_BUCKET, test.ack_keys[DestinationType.BUS])
89+
# loop through each line in the bus ack content
7890

79-
# how to validate bus ack content?
80-
# bus_ack_content = get_file_content_from_s3(ACK_BUCKET, test_data.ack_keys[DestinationType.BUS])
91+
# sometimes OK and sometimes CREATE
92+
# check_inf_file_content(f"{test.name} - bus", bus_ack_content, "OK", test.operation_outcome,
93+
# test.actions)
8194

82-
logging.info(f"Completed all validations. Total time taken: {time.time() - start_time:.1f} seconds")
95+
logger.info(f"Completed all validations. Total time: {time.time() - start_time:.1f} seconds")

0 commit comments

Comments
 (0)