Skip to content

Commit 0bc7e1e

Browse files
committed
Update e2e tests and utils
1 parent 71e9309 commit 0bc7e1e

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

tests/e2e_batch/scenarios.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def get_identifier_pk(self):
9696
if not self.identifier:
9797
raise Exception("Identifier not set. Generate the CSV file first.")
9898

99-
# Identifier PK will be different to Identifier in the resource due to data uplift as part of VED-893. This
99+
# Identifier PK could be different to Identifier in the resource due to data uplift as part of VED-893. This
100100
# only affects TPP and EMIS
101101
if self.ods == "YGA":
102102
return f"{TPP_V5_SUPPLIER_IDENTIFIER_SYSTEM}#{self.identifier}"
@@ -136,6 +136,7 @@ def generate_csv_file(self):
136136
for action in self.actions:
137137
row = create_row(
138138
self.identifier,
139+
self.ods,
139140
self.dose_amount,
140141
action.action,
141142
self.header,
@@ -152,7 +153,7 @@ def get_file_name(self, vax_type, ods, version="5"):
152153
return f"{vax_type}_Vaccinations_v{version}_{ods}_{timestamp}.csv"
153154

154155
def cleanup(self):
155-
aws_cleanup(self.key, self.identifier, self.ack_keys)
156+
aws_cleanup(self.key, self.get_identifier_pk(), self.ack_keys)
156157

157158

158159
def create_test_cases(test_case_dict: dict) -> list[TestCase]:

tests/e2e_batch/utils.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
ACK_BUCKET,
2727
ACK_PREFIX,
2828
DUPLICATE,
29+
EMIS_V5_SUPPLIER_IDENTIFIER_SYSTEM,
2930
FILE_NAME_VAL_ERROR,
3031
FORWARDEDFILE_PREFIX,
3132
HEADER_RESPONSE_CODE_COLUMN,
3233
RAVS_URI,
3334
SOURCE_BUCKET,
35+
TPP_V5_SUPPLIER_IDENTIFIER_SYSTEM,
3436
ActionFlag,
3537
environment,
3638
)
@@ -260,6 +262,14 @@ def extract_identifier_pk(row, index):
260262
"""Extract LOCAL_ID and convert to IdentifierPK."""
261263
try:
262264
local_id, unique_id_uri = row["LOCAL_ID"].split("^")
265+
266+
# Identifier PK will be different to Identifier in the resource due to data uplift as part of VED-893. This
267+
# only affects TPP and EMIS
268+
if unique_id_uri == "YGA":
269+
unique_id_uri = TPP_V5_SUPPLIER_IDENTIFIER_SYSTEM
270+
if unique_id_uri == "YGJ":
271+
unique_id_uri = EMIS_V5_SUPPLIER_IDENTIFIER_SYSTEM
272+
263273
return f"{unique_id_uri}#{local_id}"
264274
except ValueError:
265275
raise AssertionError(f"Row {index + 1}: Invalid LOCAL_ID format - {row['LOCAL_ID']}")
@@ -350,20 +360,23 @@ def generate_csv_with_ordered_100000_rows(file_name=None):
350360
for i in range(special_row_count // 3): # 100 sets
351361
new_row = create_row(
352362
unique_id=unique_ids[i],
363+
unique_id_uri=RAVS_URI,
353364
fore_name="PHYLIS",
354365
dose_amount="0.3",
355366
action_flag="NEW",
356367
header="NHS_NUMBER",
357368
)
358369
update_row = create_row(
359370
unique_id=unique_ids[i],
371+
unique_id_uri=RAVS_URI,
360372
fore_name="PHYLIS",
361373
dose_amount="0.4",
362374
action_flag="UPDATE",
363375
header="NHS_NUMBER",
364376
)
365377
delete_row = create_row(
366378
unique_id=unique_ids[i],
379+
unique_id_uri=RAVS_URI,
367380
fore_name="PHYLIS",
368381
dose_amount="0.1",
369382
action_flag="DELETE",
@@ -449,10 +462,9 @@ def delete_filename_from_audit_table(filename) -> bool:
449462
return False
450463

451464

452-
def delete_filename_from_events_table(identifier) -> bool:
465+
def delete_filename_from_events_table(identifier_pk) -> bool:
453466
# 1. Query the GSI to get all items with the given filename
454467
try:
455-
identifier_pk = f"{RAVS_URI}#{identifier}"
456468
response = events_table.query(
457469
IndexName="IdentifierGSI",
458470
KeyConditionExpression=Key("IdentifierPK").eq(identifier_pk),
@@ -480,13 +492,13 @@ def poll_s3_file_pattern(prefix, search_pattern):
480492
return None
481493

482494

483-
def aws_cleanup(key, identifier, ack_keys):
495+
def aws_cleanup(key, identifier_pk, ack_keys):
484496
if key:
485497
archive_file = f"archive/{key}"
486498
if not delete_file_from_s3(SOURCE_BUCKET, archive_file):
487499
logger.warning(f"S3 delete fail {SOURCE_BUCKET}: {archive_file}")
488500
delete_filename_from_audit_table(key)
489-
delete_filename_from_events_table(identifier)
501+
delete_filename_from_events_table(identifier_pk)
490502
for ack_key in ack_keys.values():
491503
if ack_key:
492504
if not delete_file_from_s3(ACK_BUCKET, ack_key):
@@ -507,7 +519,7 @@ def purge_sqs_queues() -> bool:
507519
return False
508520

509521

510-
def create_row(unique_id, dose_amount, action_flag: str, header, inject_cp1252=None):
522+
def create_row(unique_id, unique_id_uri, dose_amount, action_flag: str, header, inject_cp1252=None):
511523
"""Helper function to create a single row with the specified UNIQUE_ID and ACTION_FLAG."""
512524

513525
name = "James" if not inject_cp1252 else b"Jam\xe9s"
@@ -522,7 +534,7 @@ def create_row(unique_id, dose_amount, action_flag: str, header, inject_cp1252=N
522534
"SITE_CODE": "RVVKC",
523535
"SITE_CODE_TYPE_URI": "https://fhir.nhs.uk/Id/ods-organization-code",
524536
"UNIQUE_ID": unique_id,
525-
"UNIQUE_ID_URI": RAVS_URI,
537+
"UNIQUE_ID_URI": unique_id_uri,
526538
"ACTION_FLAG": action_flag,
527539
"PERFORMING_PROFESSIONAL_FORENAME": "PHYLIS",
528540
"PERFORMING_PROFESSIONAL_SURNAME": name,

0 commit comments

Comments
 (0)