Skip to content

Commit c62e364

Browse files
authored
Ved 1145 VED-1141 VED-1150 update test coverage (#1359)
* initial commit * final changes * fix broken tests * fix test data * pr comment fixes
1 parent 481bd3f commit c62e364

15 files changed

Lines changed: 563 additions & 203 deletions

File tree

.github/workflows/run-e2e-automation-tests.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ on:
6868
- sandbox
6969
- proxy_smoke
7070
- Batch_File_Validation_Feature
71+
mns_validation_required:
72+
description: Set to true if you want the MNS validation to be performed as part of the tests. please keep in mind it will increase execution time.
73+
default: "false"
74+
type: boolean
7175

7276
env:
7377
APIGEE_AUTH_ENV: ${{ inputs.apigee_environment == 'int' && inputs.apigee_environment || 'internal-dev' }}
@@ -235,6 +239,7 @@ jobs:
235239
MEDICUS_client_Id: ${{ secrets.MEDICUS_client_Id }}
236240
MEDICUS_client_Secret: ${{ secrets.MEDICUS_client_Secret }}
237241
aws_account_id: ${{ vars.AWS_ACCOUNT_ID }}
242+
mns_validation_required: ${{ inputs.mns_validation_required || startsWith(inputs.sub_environment, 'pr-') || inputs.apigee_environment == 'internal-dev' }}
238243
TEST_PATH: ${{ inputs.service_under_test == 'batch' && 'features/batchTests' || inputs.service_under_test == 'fhir_api' && 'features/APITests' || 'features' }}
239244
TEST_FILTER: ${{ inputs.suite_to_run == 'proxy_smoke' && 'Status_feature' || inputs.suite_to_run }}
240245
run: poetry run pytest "$TEST_PATH" -m "$TEST_FILTER" --junitxml=output/test-results.xml --alluredir=output/allure-results

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

Lines changed: 63 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,10 @@ def send_update_for_immunization_event(context):
351351
def created_event_is_being_updated_twice(context):
352352
send_update_for_immunization_event(context)
353353
The_request_will_have_status_code(context, 200)
354+
mns_event_will_be_triggered_with_correct_data(context=context, action="UPDATE")
354355
send_update_for_vaccination_detail(context)
355356
The_request_will_have_status_code(context, 200)
357+
mns_event_will_be_triggered_with_correct_data(context=context, action="UPDATE")
356358

357359

358360
@given("created event is being deleted")
@@ -379,9 +381,8 @@ def mns_event_will_not_be_triggered_for_the_event(context):
379381
message_body = read_message(
380382
context,
381383
queue_type="notification",
382-
action="CREATE",
383384
wait_time_seconds=5,
384-
max_empty_polls=1,
385+
max_total_wait_seconds=20,
385386
)
386387
print("No MNS create event is created")
387388
assert message_body is None, "Not expected a message but queue returned a message"
@@ -392,9 +393,8 @@ def validate_mns_event_not_triggered_for_updated_event(context):
392393
message_body = read_message(
393394
context,
394395
queue_type="notification",
395-
action="UPDATE",
396396
wait_time_seconds=5,
397-
max_empty_polls=3,
397+
max_total_wait_seconds=20,
398398
)
399399
print("no MNS update event is created")
400400
assert message_body is None, "Not expected a message but queue returned a message"
@@ -417,14 +417,23 @@ def normalize_param(value: str) -> str:
417417

418418

419419
def calculate_age(birth_date_str: str, occurrence_datetime_str: str) -> int:
420-
birth = datetime.strptime(birth_date_str, "%Y-%m-%d").date()
420+
birth = parse_birth_date(birth_date_str)
421421
occurrence = datetime.fromisoformat(occurrence_datetime_str).date()
422422
age = occurrence.year - birth.year
423423
if (occurrence.month, occurrence.day) < (birth.month, birth.day):
424424
age -= 1
425425
return age
426426

427427

428+
def parse_birth_date(date_str: str) -> datetime.date:
429+
for fmt in ("%Y-%m-%d", "%Y%m%d"):
430+
try:
431+
return datetime.strptime(date_str, fmt).date()
432+
except ValueError:
433+
pass
434+
raise ValueError(f"Invalid birth date format: {date_str}")
435+
436+
428437
def is_valid_uuid(value: str) -> bool:
429438
try:
430439
uuid.UUID(value)
@@ -462,62 +471,77 @@ def validate_sqs_message(context, message_body, action):
462471
f"msn event for {action} DataRef mismatch: expected {context.url}/{context.ImmsID}, got {message_body.dataref}",
463472
)
464473

465-
check.is_true(
466-
normalize(message_body.filtering.generalpractitioner) == normalize(context.gp_code),
467-
f"msn event for {action} GP code mismatch: expected {context.gp_code}, got {message_body.filtering.generalpractitioner}",
468-
)
474+
if context.S3_env not in ["int", "preprod"]:
475+
check.is_true(
476+
message_body.filtering is not None,
477+
f"msn event for {action} Filtering is missing in the message body",
478+
)
469479

470-
expected_org = context.create_object.performer[1].actor.identifier.value
471-
check.is_true(
472-
normalize(message_body.filtering.sourceorganisation) == normalize(expected_org),
473-
f"msn event for {action} Source org mismatch: expected {expected_org}, got {message_body.filtering.sourceorganisation}",
474-
)
480+
check.is_true(
481+
normalize(message_body.filtering.generalpractitioner) == normalize(context.gp_code),
482+
f"msn event for {action} GP code mismatch: expected {context.gp_code}, got {message_body.filtering.generalpractitioner}",
483+
)
475484

476-
check.is_true(
477-
message_body.filtering.sourceapplication.upper() == context.supplier_name.upper(),
478-
f"msn event for {action} Source application mismatch: expected {context.supplier_name}, got {message_body.filtering.sourceapplication}",
479-
)
485+
expected_org = context.immunization_object.performer[1].actor.identifier.value
486+
check.is_true(
487+
normalize(message_body.filtering.sourceorganisation) == normalize(expected_org),
488+
f"msn event for {action} Source org mismatch: expected {expected_org}, got {message_body.filtering.sourceorganisation}",
489+
)
480490

481-
check.is_true(
482-
message_body.filtering.subjectage == context.patient_age,
483-
f"msn event for {action} Age mismatch: expected {context.patient_age}, got {message_body.filtering.subjectage}",
484-
)
491+
check.is_true(
492+
message_body.filtering.sourceapplication.upper() == context.supplier_name.upper(),
493+
f"msn event for {action} Source application mismatch: expected {context.supplier_name}, got {message_body.filtering.sourceapplication}",
494+
)
485495

486-
check.is_true(
487-
message_body.filtering.immunisationtype == context.vaccine_type.upper(),
488-
f"msn event for {action} Immunisation type mismatch: expected {context.vaccine_type.upper()}, got {message_body.filtering.immunisationtype}",
489-
)
496+
check.is_true(
497+
message_body.filtering.subjectage == context.patient_age,
498+
f"msn event for {action} Age mismatch: expected {context.patient_age}, got {message_body.filtering.subjectage}",
499+
)
490500

491-
check.is_true(
492-
message_body.filtering.action == action.upper(),
493-
f"msn event for {action} Action mismatch: expected {action.upper()}, got {message_body.filtering.action}",
494-
)
501+
check.is_true(
502+
message_body.filtering.immunisationtype == context.vaccine_type.upper(),
503+
f"msn event for {action} Immunisation type mismatch: expected {context.vaccine_type.upper()}, got {message_body.filtering.immunisationtype}",
504+
)
505+
506+
check.is_true(
507+
message_body.filtering.action == action.upper(),
508+
f"msn event for {action} Action mismatch: expected {action.upper()}, got {message_body.filtering.action}",
509+
)
510+
else:
511+
check.is_true(
512+
message_body.filtering is None,
513+
f"msn event for {action} Filtering is present in the message body when it shouldn't be for int environment",
514+
)
495515

496516

497517
def mns_event_will_be_triggered_with_correct_data_for_deleted_event(context):
498518
if context.patient.identifier[0].value is None:
499519
message_body = read_message(
500520
context,
501521
queue_type="notification",
502-
action="DELETE",
503522
wait_time_seconds=5,
504-
max_empty_polls=3,
523+
max_total_wait_seconds=20,
505524
)
506525
print(
507526
"No MNS delete event is created as expected since NHS number is not present in the original immunization event"
508527
)
509528
assert message_body is None, "Not expected a message but queue returned a message"
510529
else:
511-
message_body = read_message(context, queue_type="notification", action="DELETE")
530+
message_body = read_message(context, queue_type="notification")
512531
print(f"Read deleted message from SQS: {message_body}")
513532
assert message_body is not None, "Expected a delete message but queue returned empty"
514533
validate_sqs_message(context, message_body, "DELETE")
515534

516535

517536
def mns_event_will_be_triggered_with_correct_data(context, action):
518-
message_body = read_message(context, queue_type="notification", action=action)
519-
print(f"Read {action}d message from SQS: {message_body}")
520-
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)
523-
validate_sqs_message(context, message_body, action)
537+
if context.mns_validation_required.strip().lower() == "true":
538+
message_body = read_message(context, queue_type="notification")
539+
print(f"Read {action}d message from SQS: {message_body}")
540+
assert message_body is not None, f"Expected a {action} message but queue returned empty"
541+
context.gp_code = get_gp_code_by_nhs_number(context.patient.identifier[0].value)
542+
context.patient_age = calculate_age(context.patient.birthDate, context.immunization_object.occurrenceDateTime)
543+
validate_sqs_message(context, message_body, action)
544+
else:
545+
print(
546+
f"MNS event validation is skipped since mns_validation_required is set to {context.mns_validation_required}"
547+
)

0 commit comments

Comments
 (0)