Skip to content

Commit a78d980

Browse files
committed
fix pydentic object to use failure detail
1 parent 86ac22d commit a78d980

4 files changed

Lines changed: 162 additions & 163 deletions

File tree

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

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@
3636
scenarios("batchTests/update_batch.feature")
3737

3838

39-
@given(
40-
"batch file is created for below data as full dataset and each record has a valid update record in the same file"
41-
)
39+
@given("batch file is created for below data as full dataset and each record has a valid update record in the same file")
4240
def valid_batch_file_is_created_with_details(datatable, context):
4341
build_dataFrame_using_datatable(datatable, context)
4442
df_new = context.vaccine_df.copy()
@@ -60,9 +58,7 @@ def create_valid_vaccination_record_through_api(context):
6058
)
6159
def create_valid_vaccination_record_with_same_unique_id_as_batch_file(context):
6260
valid_json_payload_is_created(context)
63-
context.immunization_object.identifier[0].value = (
64-
f"Fail-duplicate{str(uuid.uuid4())}-duplicate"
65-
)
61+
context.immunization_object.identifier[0].value = f"Fail-duplicate{str(uuid.uuid4())}-duplicate"
6662
Trigger_the_post_create_request(context)
6763
The_request_will_have_status_code(context, 201)
6864
validateCreateLocation(context)
@@ -101,20 +97,14 @@ def upload_batch_file_to_s3_for_update(context):
10197
create_batch_file(context)
10298

10399

104-
@then(
105-
"The delta and imms event table will be populated with the correct data for api created event"
106-
)
107-
@given(
108-
"The delta and imms event table will be populated with the correct data for api created event"
109-
)
100+
@then("The delta and imms event table will be populated with the correct data for api created event")
101+
@given("The delta and imms event table will be populated with the correct data for api created event")
110102
def validate_imms_delta_table_for_api_created_event(context):
111103
validate_imms_event_table_by_operation(context, "created")
112104
validate_imms_delta_table_by_ImmsID(context)
113105

114106

115-
@when(
116-
"Send a update for Immunization event created with vaccination detail being updated through API request"
117-
)
107+
@when("Send a update for Immunization event created with vaccination detail being updated through API request")
118108
def send_update_for_immunization_event_with_vaccination_detail_updated(context):
119109
valid_json_payload_is_created(context)
120110
row = context.vaccine_df.loc[0]
@@ -123,15 +113,11 @@ def send_update_for_immunization_event_with_vaccination_detail_updated(context):
123113
context.immunization_object.contained[1].name[0].family = row["PERSON_SURNAME"]
124114
reverse_gender_map = {v.value: v.name for v in GenderCode}
125115
code = row["PERSON_GENDER_CODE"]
126-
context.immunization_object.contained[1].gender = reverse_gender_map.get(
127-
code, "unknown"
128-
)
129-
context.immunization_object.contained[1].birthDate = (
130-
f"{row['PERSON_DOB'][:4]}-{row['PERSON_DOB'][4:6]}-{row['PERSON_DOB'][6:]}"
131-
)
132-
context.immunization_object.contained[1].address[0].postalCode = row[
133-
"PERSON_POSTCODE"
134-
]
116+
context.immunization_object.contained[1].gender = reverse_gender_map.get(code, "unknown")
117+
context.immunization_object.contained[
118+
1
119+
].birthDate = f"{row['PERSON_DOB'][:4]}-{row['PERSON_DOB'][4:6]}-{row['PERSON_DOB'][6:]}"
120+
context.immunization_object.contained[1].address[0].postalCode = row["PERSON_POSTCODE"]
135121
context.immunization_object.identifier[0].value = row["UNIQUE_ID"]
136122
context.immunization_object.identifier[0].system = row["UNIQUE_ID_URI"]
137123
send_update_for_immunization_event(context)
@@ -145,9 +131,7 @@ def api_request_will_be_successful_and_tables_will_be_updated_correctly(context)
145131
validate_delta_table_for_updated_event(context)
146132

147133

148-
@when(
149-
"Update to above vaccination record is made through batch file upload with mandatory field missing"
150-
)
134+
@when("Update to above vaccination record is made through batch file upload with mandatory field missing")
151135
def upload_batch_file_to_s3_for_update_with_mandatory_field_missing(context):
152136
# Build base record
153137
record = build_batch_file(context)
@@ -164,9 +148,7 @@ def upload_batch_file_to_s3_for_update_with_mandatory_field_missing(context):
164148
"UNIQUE_ID_URI": context.create_object.identifier[0].system,
165149
}
166150
context.vaccine_df.loc[0, list(base_fields.keys())] = list(base_fields.values())
167-
context.vaccine_df = pd.concat(
168-
[context.vaccine_df.loc[[0]]] * 19, ignore_index=True
169-
)
151+
context.vaccine_df = pd.concat([context.vaccine_df.loc[[0]]] * 19, ignore_index=True)
170152
missing_cases = {
171153
0: {"SITE_CODE": "", "PERSON_SURNAME": "empty_site_code"},
172154
1: {"SITE_CODE_TYPE_URI": "", "PERSON_SURNAME": "empty_site_code_uri"},
@@ -198,18 +180,14 @@ def upload_batch_file_to_s3_for_update_with_mandatory_field_missing(context):
198180
create_batch_file(context)
199181

200182

201-
@then(
202-
"csv bus ack will have error records for all the updated records in the batch file"
203-
)
183+
@then("csv bus ack will have error records for all the updated records in the batch file")
204184
def all_records_are_processed_successfully_in_the_batch_file(context):
205185
file_rows = read_and_validate_csv_bus_ack_file_content(context, False, True)
206186
all_valid = validate_bus_ack_file_for_error_by_surname(context, file_rows)
207187
assert all_valid, "One or more records failed validation checks"
208188

209189

210-
@then(
211-
"json bus ack will have error records for all the updated records in the batch file"
212-
)
190+
@then("json bus ack will have error records for all the updated records in the batch file")
213191
def json_bus_ack_will_have_error_records_for_all_updated_records_in_batch_file(context):
214192
json_content = context.fileContentJson
215193
assert json_content is not None, "BUS Ack JSON content is None"
@@ -229,9 +207,7 @@ def validate_bus_ack_file_for_error_by_surname(context, file_rows) -> bool:
229207
bus_ack_row_number = batch_idx + 2
230208
row_data_list = file_rows.get(bus_ack_row_number)
231209
if not row_data_list:
232-
print(
233-
f"Batch row {batch_idx}: No BUS ACK entry found for row number {bus_ack_row_number}"
234-
)
210+
print(f"Batch row {batch_idx}: No BUS ACK entry found for row number {bus_ack_row_number}")
235211
overall_valid = False
236212
continue
237213
surname = str(row.get("PERSON_SURNAME", "")).strip()
Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,80 @@
11
@Update_Batch_Feature @functional
22
Feature: Create the immunization event for a patient through batch file and update the record from batch or Api calls
33

4-
@smoke
5-
@delete_cleanup_batch @vaccine_type_MMR @supplier_name_TPP
6-
Scenario: Update immunization event for a patient through batch file
7-
Given batch file is created for below data as full dataset and each record has a valid update record in the same file
8-
| patient_id | unique_id |
9-
| Random | Valid_NhsNumber |
10-
| InvalidInPDS | InvalidInPDS_NhsNumber|
11-
| SFlag | SFlag_NhsNumber |
12-
| Mod11_NHS | Mod11_NhSNumber |
13-
| OldNHSNo | OldNHSNo |
14-
When batch file is uploaded in s3 bucket
15-
Then file will be moved to destination bucket and inf ack file will be created
16-
And inf ack file has success status for processed batch file
17-
And bus ack files will be created
18-
And CSV bus ack will not have any entry of successfully processed records
19-
And Json bus ack will only contain file metadata and no failure record entry
20-
And Audit table will have correct status, queue name and record count for the processed batch file
21-
And The imms event table will be populated with the correct data for 'updated' event for records in batch file
22-
And The delta table will be populated with the correct data for all created records in batch file
23-
And The delta table will be populated with the correct data for all updated records in batch file
4+
@smoke
5+
@delete_cleanup_batch @vaccine_type_MMR @supplier_name_TPP
6+
Scenario: Update immunization event for a patient through batch file
7+
Given batch file is created for below data as full dataset and each record has a valid update record in the same file
8+
| patient_id | unique_id |
9+
| Random | Valid_NhsNumber |
10+
| InvalidInPDS | InvalidInPDS_NhsNumber |
11+
| SFlag | SFlag_NhsNumber |
12+
| Mod11_NHS | Mod11_NhSNumber |
13+
| OldNHSNo | OldNHSNo |
14+
When batch file is uploaded in s3 bucket
15+
Then file will be moved to destination bucket and inf ack file will be created
16+
And inf ack file has success status for processed batch file
17+
And bus ack files will be created
18+
And CSV bus ack will not have any entry of successfully processed records
19+
And Json bus ack will only contain file metadata and no failure record entry
20+
And Audit table will have correct status, queue name and record count for the processed batch file
21+
And The imms event table will be populated with the correct data for 'updated' event for records in batch file
22+
And The delta table will be populated with the correct data for all created records in batch file
23+
And The delta table will be populated with the correct data for all updated records in batch file
2424

25-
@Delete_cleanUp @vaccine_type_ROTAVIRUS @patient_id_Random @supplier_name_EMIS
26-
Scenario: Verify that the API vaccination record will be successful updated by batch file upload
27-
Given I have created a valid vaccination record through API
28-
And The delta and imms event table will be populated with the correct data for api created event
29-
When An update to above vaccination record is made through batch file upload
30-
And batch file is uploaded in s3 bucket
31-
Then file will be moved to destination bucket and inf ack file will be created
32-
And inf ack file has success status for processed batch file
33-
And bus ack files will be created
34-
And CSV bus ack will not have any entry of successfully processed records
35-
And Json bus ack will only contain file metadata and no failure record entry
36-
And Audit table will have correct status, queue name and record count for the processed batch file
37-
And The imms event table will be populated with the correct data for 'updated' event for records in batch file
38-
And The delta table will be populated with the correct data for all updated records in batch file
25+
@Delete_cleanUp @vaccine_type_ROTAVIRUS @patient_id_Random @supplier_name_EMIS
26+
Scenario: Verify that the API vaccination record will be successful updated by batch file upload
27+
Given I have created a valid vaccination record through API
28+
And The delta and imms event table will be populated with the correct data for api created event
29+
When An update to above vaccination record is made through batch file upload
30+
And batch file is uploaded in s3 bucket
31+
Then file will be moved to destination bucket and inf ack file will be created
32+
And inf ack file has success status for processed batch file
33+
And bus ack files will be created
34+
And CSV bus ack will not have any entry of successfully processed records
35+
And Json bus ack will only contain file metadata and no failure record entry
36+
And Audit table will have correct status, queue name and record count for the processed batch file
37+
And The imms event table will be populated with the correct data for 'updated' event for records in batch file
38+
And The delta table will be populated with the correct data for all updated records in batch file
3939

40-
@Delete_cleanUp @vaccine_type_6IN1 @patient_id_Random @supplier_name_TPP
41-
Scenario: Verify that the batch vaccination record will be successful updated by API request
42-
Given batch file is created for below data as full dataset
43-
| patient_id | unique_id |
44-
| Random | Valid_NhsNumber |
45-
When batch file is uploaded in s3 bucket
46-
Then file will be moved to destination bucket and inf ack file will be created
47-
And inf ack file has success status for processed batch file
48-
And bus ack files will be created
49-
And CSV bus ack will not have any entry of successfully processed records
50-
And Json bus ack will only contain file metadata and no failure record entry
51-
And Audit table will have correct status, queue name and record count for the processed batch file
52-
And The imms event table will be populated with the correct data for 'created' event for records in batch file
53-
And The delta table will be populated with the correct data for all created records in batch file
54-
When Send a update for Immunization event created with vaccination detail being updated through API request
55-
Then Api request will be successful and tables will be updated correctly
40+
@Delete_cleanUp @vaccine_type_6IN1 @patient_id_Random @supplier_name_TPP
41+
Scenario: Verify that the batch vaccination record will be successful updated by API request
42+
Given batch file is created for below data as full dataset
43+
| patient_id | unique_id |
44+
| Random | Valid_NhsNumber |
45+
When batch file is uploaded in s3 bucket
46+
Then file will be moved to destination bucket and inf ack file will be created
47+
And inf ack file has success status for processed batch file
48+
And bus ack files will be created
49+
And CSV bus ack will not have any entry of successfully processed records
50+
And Json bus ack will only contain file metadata and no failure record entry
51+
And Audit table will have correct status, queue name and record count for the processed batch file
52+
And The imms event table will be populated with the correct data for 'created' event for records in batch file
53+
And The delta table will be populated with the correct data for all created records in batch file
54+
When Send a update for Immunization event created with vaccination detail being updated through API request
55+
Then Api request will be successful and tables will be updated correctly
5656

57-
@Delete_cleanUp @vaccine_type_RSV @patient_id_Random @supplier_name_RAVS
58-
Scenario: Verify that the API vaccination record will be successful updated and batch file will fail upload due to mandatory field missing
59-
Given I have created a valid vaccination record through API
60-
When Update to above vaccination record is made through batch file upload with mandatory field missing
61-
And batch file is uploaded in s3 bucket
62-
Then file will be moved to destination bucket and inf ack file will be created
63-
And inf ack file has success status for processed batch file
64-
And bus ack files will be created
65-
And csv bus ack will have error records for all the updated records in the batch file
66-
And json bus ack will have error records for all the updated records in the batch file
67-
And The delta and imms event table will be populated with the correct data for api created event
57+
@Delete_cleanUp @vaccine_type_RSV @patient_id_Random @supplier_name_RAVS
58+
Scenario: Verify that the API vaccination record will be successful updated and batch file will fail upload due to mandatory field missing
59+
Given I have created a valid vaccination record through API
60+
When Update to above vaccination record is made through batch file upload with mandatory field missing
61+
And batch file is uploaded in s3 bucket
62+
Then file will be moved to destination bucket and inf ack file will be created
63+
And inf ack file has success status for processed batch file
64+
And bus ack files will be created
65+
And csv bus ack will have error records for all the updated records in the batch file
66+
And json bus ack will have error records for all the updated records in the batch file
67+
And The delta and imms event table will be populated with the correct data for api created event
6868

69-
@smoke
70-
@Delete_cleanUp @vaccine_type_HIB @patient_id_Random @supplier_name_EMIS
71-
Scenario: Verify that batch file record will ne unsuccessful if uses same or missing any unique identifier field
72-
Given I have created a valid vaccination record through API, where unique_id and unique_id_uri will be same as batch file record
73-
When batch file created for below data as full dataset and record has same or missing unique identifier for API record
74-
And batch file is uploaded in s3 bucket
75-
Then file will be moved to destination bucket and inf ack file will be created
76-
And inf ack file has success status for processed batch file
77-
And bus ack files will be created
78-
And csv bus ack will have error records for all the updated records in the batch file
79-
And json bus ack will have error records for all the updated records in the batch file
80-
And The delta and imms event table will be populated with the correct data for api created event
69+
@smoke
70+
@Delete_cleanUp @vaccine_type_HIB @patient_id_Random @supplier_name_EMIS
71+
Scenario: Verify that batch file record will ne unsuccessful if uses same or missing any unique identifier field
72+
Given I have created a valid vaccination record through API, where unique_id and unique_id_uri will be same as batch file record
73+
When batch file created for below data as full dataset and record has same or missing unique identifier for API record
74+
And batch file is uploaded in s3 bucket
75+
Then file will be moved to destination bucket and inf ack file will be created
76+
And inf ack file has success status for processed batch file
77+
And bus ack files will be created
78+
And csv bus ack will have error records for all the updated records in the batch file
79+
And json bus ack will have error records for all the updated records in the batch file
80+
And The delta and imms event table will be populated with the correct data for api created event

tests/e2e_automation/src/objectModels/batch/batch_report_object.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,13 @@
55

66

77
class IngestionTime(BaseModel):
8-
start: str
9-
end: str
10-
11-
@validator("start", "end")
12-
def validate_unix_timestamp(cls, v):
13-
# Ensure it's numeric
14-
if not v.isdigit():
15-
raise ValueError("ingestionTime values must be numeric strings")
16-
17-
# Optional: ensure it's a valid Unix timestamp
18-
try:
19-
datetime.utcfromtimestamp(int(v))
20-
except Exception:
21-
raise ValueError("Invalid Unix timestamp")
22-
23-
return v
8+
start: int
9+
end: int
2410

2511
@validator("end")
2612
def validate_order(cls, v, values):
2713
start = values.get("start")
28-
if start and int(v) <= int(start):
14+
if start is not None and v <= start:
2915
raise ValueError("ingestionTime.end must be greater than start")
3016
return v
3117

@@ -37,6 +23,15 @@ class Summary(BaseModel):
3723
ingestionTime: IngestionTime
3824

3925

26+
class FailureDetail(BaseModel):
27+
rowId: str
28+
responseCode: str
29+
responseDisplay: str
30+
severity: str
31+
localId: str
32+
operationOutcome: str
33+
34+
4035
class BatchReport(BaseModel):
4136
system: str
4237
version: int
@@ -45,12 +40,11 @@ class BatchReport(BaseModel):
4540
provider: str
4641
messageHeaderId: str
4742
summary: Summary
48-
failures: Optional[List]
43+
failures: Optional[List[FailureDetail]]
4944

5045
@validator("generatedDate")
5146
def validate_generated_date(cls, v):
5247
try:
53-
# Enforce ISO‑8601 with Z suffix
5448
datetime.strptime(v, "%Y-%m-%dT%H:%M:%S.%fZ")
5549
except ValueError:
5650
raise ValueError("generatedDate must be ISO‑8601 format ending with 'Z'")

0 commit comments

Comments
 (0)