Skip to content

Commit 427a188

Browse files
authored
updated step definition to validate ACk file names (#1252)
1 parent 3717253 commit 427a188

2 files changed

Lines changed: 52 additions & 6 deletions

File tree

tests/e2e_automation/features/batchTests/Steps/batch_common_steps.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,20 @@ def batch_file_upload_in_s3_bucket(context):
110110
@then("file will be moved to destination bucket and inf ack file will be created")
111111
def ack_file_will_be_moved_to_destination_bucket(context):
112112
result = wait_and_read_ack_file(context, "ack")
113-
context.fileContent = result["csv"]
114-
assert context.fileContent, f"File not found in destination bucket after timeout: {context.forwarded_prefix}"
113+
actual_file_name = result["csv"]["key"]
114+
check.is_true(
115+
actual_file_name.endswith(".csv"),
116+
f"Expected ACK file extension is .csv but got {actual_file_name}",
117+
)
118+
check.is_true(
119+
actual_file_name.startswith(context.forwarded_prefix),
120+
f"Expected ACK file name to start with {context.forwarded_prefix} but got {actual_file_name}",
121+
)
122+
check.is_true(
123+
"_InfAck_" in actual_file_name,
124+
f"Expected ACK file name to contain '_InfAck_actual_file_name' but got {actual_file_name}",
125+
)
126+
context.fileContent = result["csv"]["content"]
115127

116128

117129
@then("inf ack file has success status for processed batch file")
@@ -124,8 +136,36 @@ def all_records_are_processed_successfully_in_the_inf_ack_file(context):
124136
def file_will_be_moved_to_destination_bucket(context):
125137
result = wait_and_read_ack_file(context, "forwardedFile")
126138
assert isinstance(result, dict), f"Expected both CSV and JSON ACK files but got: {type(result)}"
127-
context.fileContent = result.get("csv")
128-
context.fileContentJson = result.get("json")
139+
140+
actual_file_name = result["csv"]["key"]
141+
check.is_true(
142+
actual_file_name.endswith(".csv"),
143+
f"Expected ACK file extension is .csv but got {actual_file_name}",
144+
)
145+
check.is_true(
146+
actual_file_name.startswith(context.forwarded_prefix),
147+
f"Expected ACK file name to start with {context.forwarded_prefix} but got {actual_file_name}",
148+
)
149+
check.is_true(
150+
"_BusAck_" in actual_file_name,
151+
f"Expected ACK file name to contain '_BusAck_actual_file_name' but got {actual_file_name}",
152+
)
153+
context.fileContent = result["csv"]["content"]
154+
actual_file_name = result["json"]["key"]
155+
check.is_true(
156+
actual_file_name.endswith(".json"),
157+
f"Expected ACK file extension is .json but got {actual_file_name}",
158+
)
159+
check.is_true(
160+
actual_file_name.startswith(context.forwarded_prefix),
161+
f"Expected ACK file name to start with {context.forwarded_prefix} but got {actual_file_name}",
162+
)
163+
check.is_true(
164+
"_BusAck_" in actual_file_name,
165+
f"Expected ACK file name to contain '_BusAck_actual_file_name' but got {actual_file_name}",
166+
)
167+
context.fileContentJson = result["json"]["content"]
168+
129169
assert context.fileContent, (
130170
f"BUS Ack csv File not found in destination bucket after timeout: {context.forwarded_prefix}"
131171
)

tests/e2e_automation/utilities/batch_S3_buckets.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ def wait_for_file_to_move_archive(context, timeout=120, interval=5):
4747

4848

4949
def wait_and_read_ack_file(
50-
context, folderName: str, timeout=120, interval=5, duplicate_bus_files=False, duplicate_inf_files=False
50+
context,
51+
folderName: str,
52+
timeout=180,
53+
interval=5,
54+
duplicate_bus_files=False,
55+
duplicate_inf_files=False,
5156
):
5257
s3 = boto3.client("s3")
5358
destination_bucket = f"immunisation-batch-{context.S3_env}-data-destinations"
@@ -96,7 +101,8 @@ def wait_and_read_ack_file(
96101
print(f"[FOUND] {ext} file located: {key}")
97102
s3_obj = s3.get_object(Bucket=destination_bucket, Key=key)
98103
file_data = s3_obj["Body"].read().decode("utf-8")
99-
found_files[ext] = file_data
104+
found_files[ext] = {"key": key, "content": file_data}
105+
100106
print(f"[SUCCESS] Loaded {ext} file ({len(file_data)} bytes)")
101107

102108
if expected_extensions.issubset(found_files.keys()):

0 commit comments

Comments
 (0)