Skip to content

Commit 7ca4ce0

Browse files
authored
fix clean up task for batch file validation and when token get expired (#1374)
* fix clean up task for batch file validation and when token get expired * update status code * simplify the code moving failed file in after scenario * added all not processed status
1 parent a1f06d8 commit 7ca4ce0

4 files changed

Lines changed: 63 additions & 28 deletions

File tree

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from pytest_bdd import given, parsers, scenarios, then
33
from src.dynamoDB.dynamo_db_helper import (
44
fetch_batch_audit_table_detail,
5-
update_audit_table_for_failed_status,
65
validate_audit_table_record,
76
)
87
from src.objectModels.batch.batch_file_builder import BatchVaccinationRecord
@@ -108,4 +107,3 @@ def validate_imms_audit_table(context, status, queue_name, error_details):
108107
sorted_items = sorted(table_query_response, key=lambda x: x["timestamp"], reverse=True)
109108
item = sorted_items[0]
110109
validate_audit_table_record(context, item, status, error_details, queue_name)
111-
update_audit_table_for_failed_status(item, context.aws_profile_name, context.S3_env)

tests/e2e_automation/features/batchTests/batch_file_validation.feature

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@Batch_File_Validation_Feature
22
Feature: Validate the file level and columns validations for vaccination batch file
33

4-
@vaccine_type_COVID @supplier_name_MAVIS
4+
@Batch_File_Validation @vaccine_type_COVID @supplier_name_MAVIS
55
Scenario Outline: verify that vaccination file will be rejected if file name format is invalid
66
Given batch file is created for below data with <invalidFilename> filename and <file_extension> extension
77
| patient_id | unique_id |
@@ -47,7 +47,7 @@ Feature: Validate the file level and columns validations for vaccination batch f
4747
And bus ack file will not be created
4848
And Audit table will have 'Not processed - Empty file', 'MAVIS_FLU' and 'None' for the processed batch file
4949

50-
@vaccine_type_MENACWY @supplier_name_TPP
50+
@Batch_File_Validation @vaccine_type_MENACWY @supplier_name_TPP
5151
Scenario: verify that vaccination file will be rejected if columns are missing
5252
Given batch file is created with missing columns for below data
5353
| patient_id | unique_id |
@@ -59,7 +59,7 @@ Feature: Validate the file level and columns validations for vaccination batch f
5959
And Audit table will have 'Failed', 'TPP_MENACWY' and 'File headers are invalid.' for the processed batch file
6060

6161
@smoke
62-
@vaccine_type_COVID @supplier_name_EMIS
62+
@Batch_File_Validation @vaccine_type_COVID @supplier_name_EMIS
6363
Scenario: verify that vaccination file will be rejected if column order is invalid
6464
Given batch file is created with invalid column order for below data
6565
| patient_id | unique_id |
@@ -71,7 +71,7 @@ Feature: Validate the file level and columns validations for vaccination batch f
7171
And Audit table will have 'Failed', 'EMIS_COVID' and 'File headers are invalid.' for the processed batch file
7272

7373
@smoke
74-
@vaccine_type_FLU @supplier_name_SONAR
74+
@Batch_File_Validation @vaccine_type_FLU @supplier_name_SONAR
7575
Scenario: verify that vaccination file will be rejected if file delimiter is invalid
7676
Given batch file is created with invalid delimiter for below data
7777
| patient_id | unique_id |
@@ -82,7 +82,7 @@ Feature: Validate the file level and columns validations for vaccination batch f
8282
And bus ack file will not be created
8383
And Audit table will have 'Failed', 'SONAR_FLU' and 'File headers are invalid.' for the processed batch file
8484

85-
@vaccine_type_3IN1 @supplier_name_TPP
85+
@Batch_File_Validation @vaccine_type_3IN1 @supplier_name_TPP
8686
Scenario: verify that vaccination file will be rejected if one of the column name is invalid
8787
Given batch file is created with invalid column name for patient surname for below data
8888
| patient_id | unique_id |
@@ -93,7 +93,7 @@ Feature: Validate the file level and columns validations for vaccination batch f
9393
And bus ack file will not be created
9494
And Audit table will have 'Failed', 'TPP_3IN1' and 'File headers are invalid.' for the processed batch file
9595

96-
@vaccine_type_3IN1 @supplier_name_EMIS
96+
@Batch_File_Validation @vaccine_type_3IN1 @supplier_name_EMIS
9797
Scenario: verify that vaccination file will be rejected if additional column is present
9898
Given batch file is created with additional column person age for below data
9999
| patient_id | unique_id |

tests/e2e_automation/features/conftest.py

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import allure
55
import pytest
66
from dotenv import load_dotenv
7+
from src.dynamoDB.dynamo_db_helper import (
8+
update_audit_table_for_failed_File_status_with_file_name,
9+
)
710
from utilities.api_fhir_immunization_helper import (
811
empty_folder,
912
get_response_body_for_display,
@@ -152,13 +155,33 @@ def pytest_bdd_after_scenario(request, feature, scenario):
152155
if context.ImmsID is not None:
153156
print(f"\n Delete Request is {context.url}/{context.ImmsID}")
154157
context.response = http_requests_session.delete(f"{context.url}/{context.ImmsID}", headers=context.headers)
155-
assert context.response.status_code == 204, (
156-
f"Expected status code 204, but got {context.response.status_code}. Response: {get_response_body_for_display(context.response)}"
157-
)
158-
if context.mns_validation_required.strip().lower() == "true":
159-
mns_event_will_be_triggered_with_correct_data_for_deleted_event(context)
158+
if context.response.status_code in [401, 403]:
159+
print(
160+
f"DELETE request returned {context.response.status_code} for ImmsID {context.ImmsID}. "
161+
f"Response: {get_response_body_for_display(context.response)}"
162+
)
163+
get_tokens(context, context.supplier_name)
164+
print(f"\n Delete Request is {context.url}/{context.ImmsID}")
165+
context.response = http_requests_session.delete(
166+
f"{context.url}/{context.ImmsID}", headers=context.headers
167+
)
168+
169+
if context.response.status_code != 204:
170+
print(
171+
f"DELETE request returned {context.response.status_code} for ImmsID {context.ImmsID} after token refresh. "
172+
f"Response: {get_response_body_for_display(context.response)}"
173+
)
174+
175+
if context.response.status_code == 204:
176+
if context.mns_validation_required.strip().lower() == "true":
177+
mns_event_will_be_triggered_with_correct_data_for_deleted_event(context)
178+
else:
179+
print("MNS validation not required, skipping MNS event verification for deleted event.")
160180
else:
161-
print("MNS validation not required, skipping MNS event verification for deleted event.")
181+
print(
182+
f"DELETE request failed with status code {context.response.status_code} for ImmsID {context.ImmsID}. "
183+
f"Response: {get_response_body_for_display(context.response)}"
184+
)
162185
else:
163186
print("Skipping delete: ImmsID is None")
164187

@@ -189,3 +212,8 @@ def pytest_bdd_after_scenario(request, feature, scenario):
189212

190213
else:
191214
print("No IMMS_ID values available — skipping delete cleanup.")
215+
216+
if "Batch_File_Validation" in tags:
217+
update_audit_table_for_failed_File_status_with_file_name(
218+
context.filename, context.aws_profile_name, context.S3_env
219+
)

tests/e2e_automation/src/dynamoDB/dynamo_db_helper.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,21 +1074,30 @@ def get_gender_code(input: str) -> GenderCode:
10741074
raise ValueError(f"Invalid gender input: {input}")
10751075

10761076

1077-
def update_audit_table_for_failed_status(item: dict, aws_profile_name: str, env: str):
1078-
if item.get("status") != "Failed":
1079-
return
1080-
1077+
def update_audit_table_for_failed_File_status_with_file_name(file_name: str, aws_profile_name: str, env: str):
10811078
db = DynamoDBHelper(aws_profile_name, env)
1082-
table = db.get_batch_audit_table()
1083-
1084-
key = {"message_id": item["message_id"]}
1079+
tableImmsAudit = db.get_batch_audit_table()
10851080

1086-
response = table.update_item(
1087-
Key=key,
1088-
UpdateExpression="SET #s = :new_status",
1089-
ExpressionAttributeNames={"#s": "status"},
1090-
ExpressionAttributeValues={":new_status": "Not processed - Automation testing"},
1091-
ReturnValues="UPDATED_NEW",
1081+
response = tableImmsAudit.query(
1082+
IndexName="filename_index",
1083+
KeyConditionExpression=Key("filename").eq(file_name),
10921084
)
1085+
items = response.get("Items", [])
1086+
1087+
if items:
1088+
print(f"\nFound Audit detail for filename={file_name}\n")
1089+
for item in items:
1090+
if item.get("status") in ["Failed", "Queued", "Processing"]:
1091+
key = {"message_id": item["message_id"]}
1092+
1093+
update_response = tableImmsAudit.update_item(
1094+
Key=key,
1095+
UpdateExpression="SET #s = :new_status",
1096+
ExpressionAttributeNames={"#s": "status"},
1097+
ExpressionAttributeValues={":new_status": "Not processed - Automation testing"},
1098+
ReturnValues="UPDATED_NEW",
1099+
)
10931100

1094-
print(f"✅ Updated audit status for message_id={key['message_id']}: {response.get('Attributes')}")
1101+
print(f"Updated audit status for message_id={key['message_id']}: {update_response.get('Attributes')}")
1102+
else:
1103+
print(f"Skipping update for message_id={item['message_id']} with status '{item.get('status')}'")

0 commit comments

Comments
 (0)