Skip to content

Commit 331ce47

Browse files
committed
Enhance API test steps by introducing a new function to populate expected MNS fields, improving data handling for SQS message validation. Updated context to include patient age and GP code. Adjusted message reading logic to allow for configurable wait times and polling limits based on action type.
1 parent 12fb807 commit 331ce47

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

tests/e2e_automation/features/APITests/steps/common_steps.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,11 @@ def normalize(value: str) -> str:
437437
return value.strip().upper() if value else ""
438438

439439

440+
def populate_expected_mns_fields(context):
441+
context.gp_code = get_gp_code_by_nhs_number(context.patient.identifier[0].value)
442+
context.patient_age = calculate_age(context.patient.birthDate, context.immunization_object.occurrenceDateTime)
443+
444+
440445
def validate_sqs_message(context, message_body, action):
441446
check.is_true(message_body.specversion == "1.0")
442447
check.is_true(message_body.source == "uk.nhs.vaccinations-data-flow-management")
@@ -511,13 +516,23 @@ def mns_event_will_be_triggered_with_correct_data_for_deleted_event(context):
511516
message_body = read_message(context, queue_type="notification", action="DELETE")
512517
print(f"Read deleted message from SQS: {message_body}")
513518
assert message_body is not None, "Expected a delete message but queue returned empty"
519+
populate_expected_mns_fields(context)
514520
validate_sqs_message(context, message_body, "DELETE")
515521

516522

517523
def mns_event_will_be_triggered_with_correct_data(context, action):
518-
message_body = read_message(context, queue_type="notification", action=action)
524+
wait_time_seconds = 20
525+
max_empty_polls = 3
526+
if action.upper() == "CREATE":
527+
max_empty_polls = 6
528+
message_body = read_message(
529+
context,
530+
queue_type="notification",
531+
action=action,
532+
wait_time_seconds=wait_time_seconds,
533+
max_empty_polls=max_empty_polls,
534+
)
519535
print(f"Read {action}d message from SQS: {message_body}")
520536
assert message_body is not None, f"Expected a {action} message but queue returned empty"
521-
context.gp_code = get_gp_code_by_nhs_number(context.patient.identifier[0].value)
522-
context.patient_age = calculate_age(context.patient.birthDate, context.immunization_object.occurrenceDateTime)
537+
populate_expected_mns_fields(context)
523538
validate_sqs_message(context, message_body, action)

tests/e2e_automation/utilities/context.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ def __init__(self):
4949
self.delta_cache = None
5050
self.aws_account_id = None
5151
self.gp_code = None
52+
self.patient_age = None

0 commit comments

Comments
 (0)