Skip to content

Commit 0afb45f

Browse files
committed
fix the broken test
1 parent d1cd0ab commit 0afb45f

5 files changed

Lines changed: 65 additions & 106 deletions

File tree

tests/e2e_automation/features/APITests/search.feature

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,14 @@ Feature: Search the immunization of a patient
272272
@Delete_cleanUp @supplier_name_TPP
273273
Scenario: Verify that Search API returns immunization events when searching by target-disease (GET)
274274
Given Valid vaccination record is created with Patient 'Random' and vaccine_type 'MMRV'
275-
When Send a search request with GET method using target-disease for Immunization event created
275+
When Send a search request with 'GET' method using target-disease for Immunization event created
276276
Then The request will be successful with the status code '200'
277277
And The Search Response JSONs should contain the detail of the immunization events created above
278278

279279
@Delete_cleanUp @supplier_name_EMIS
280280
Scenario: Verify that Search API returns immunization events when searching by target-disease (POST)
281281
Given Valid vaccination record is created with Patient 'Random' and vaccine_type '3IN1'
282-
When Send a search request with POST method using target-disease for Immunization event created
282+
When Send a search request with 'POST' method using target-disease for Immunization event created
283283
Then The request will be successful with the status code '200'
284284
And The Search Response JSONs should contain the detail of the immunization events created above
285285

@@ -304,14 +304,14 @@ Feature: Search the immunization of a patient
304304
@Delete_cleanUp @supplier_name_Postman_Auth
305305
Scenario: Verify that Search API returns immunization events when searching by comma-separated target-disease (GET)
306306
Given Valid vaccination record is created with Patient 'Random' and vaccine_type 'HEPB'
307-
When Send a search request with GET method using comma-separated target-disease for Immunization event created
307+
When Send a search request with 'GET' method using comma-separated target-disease for Immunization event created
308308
Then The request will be successful with the status code '200'
309309
And The Search Response JSONs should contain the detail of the immunization events created above
310310

311311
@Delete_cleanUp @supplier_name_Postman_Auth
312312
Scenario: Verify that Search API returns immunization events when searching by comma-separated target-disease (POST)
313313
Given Valid vaccination record is created with Patient 'Random' and vaccine_type 'COVID'
314-
When Send a search request with POST method using comma-separated target-disease for Immunization event created
314+
When Send a search request with 'POST' method using comma-separated target-disease for Immunization event created
315315
Then The request will be successful with the status code '200'
316316
And The Search Response JSONs should contain the detail of the immunization events created above
317317

@@ -334,20 +334,20 @@ Feature: Search the immunization of a patient
334334

335335
@supplier_name_Postman_Auth
336336
Scenario: Verify that Search API returns 400 when all target-disease values are invalid SNOMED codes
337-
When Send a search request with GET method with valid NHS Number and all invalid target-disease codes
337+
When Send a search request with 'GET' method with valid NHS Number and all invalid target-disease codes
338338
Then The request will be unsuccessful with the status code '400'
339339
And The Response JSONs should contain correct error message for invalid target-disease codes
340-
When Send a search request with POST method with valid NHS Number and all invalid target-disease codes
340+
When Send a search request with 'POST' method with valid NHS Number and all invalid target-disease codes
341341
Then The request will be unsuccessful with the status code '400'
342342
And The Response JSONs should contain correct error message for invalid target-disease codes
343343

344344
@smoke
345345
@Delete_cleanUp @supplier_name_Postman_Auth
346346
Scenario: Verify that Search API returns 200 with results and OperationOutcome when some target-disease values are invalid
347347
Given Valid vaccination record is created with Patient 'Random' and vaccine_type '6IN1'
348-
When Send a search request with GET method using mixed valid and invalid target-disease codes for Immunization event created
348+
When Send a search request with 'GET' method using mixed valid and invalid target-disease codes for Immunization event created
349349
Then The request will be successful with the status code '200'
350350
And The Search Response should contain search results and OperationOutcome for invalid target-disease codes
351-
When Send a search request with POST method using mixed valid and invalid target-disease codes for Immunization event created
351+
When Send a search request with 'POST' method using mixed valid and invalid target-disease codes for Immunization event created
352352
Then The request will be successful with the status code '200'
353353
And The Search Response should contain search results and OperationOutcome for invalid target-disease codes

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

Lines changed: 32 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
validate_error_response,
1414
validate_to_compare_request_and_response,
1515
)
16-
from utilities.api_get_header import get_search_get_url_header, get_search_post_url_header
16+
from utilities.api_get_header import (
17+
get_search_get_url_header,
18+
get_search_post_url_header,
19+
)
1720
from utilities.date_helper import iso_to_compact
1821
from utilities.http_requests_session import http_requests_session
1922

@@ -66,78 +69,52 @@ def trigger_search_request(context, httpMethod):
6669
trigger_search_request_by_httpMethod(context, httpMethod=httpMethod)
6770

6871

69-
@when("Send a search request with GET method using target-disease for Immunization event created")
70-
def send_search_get_with_target_disease(context):
71-
get_search_get_url_header(context)
72-
patient_ident = context.create_object.contained[1].identifier[0]
73-
target = context.create_object.protocolApplied[0].targetDisease[0].coding[0]
74-
context.params = {
75-
"patient.identifier": f"{patient_ident.system}|{patient_ident.value}",
76-
"target-disease": f"{target.system}|{target.code}",
77-
}
78-
print(f"\n Search Get parameters (target-disease) - \n {context.params}")
79-
context.response = http_requests_session.get(context.url, params=context.params, headers=context.headers)
80-
81-
8272
@when("Send a search request with POST method for Immunization event created")
8373
def TriggerSearchPostRequest(context):
84-
get_search_post_url_header(context)
8574
context.request = convert_to_form_data(
8675
set_request_data(
87-
context.patient.identifier[0].value, context.vaccine_type, datetime.today().strftime("%Y-%m-%d")
76+
context.patient.identifier[0].value,
77+
context.vaccine_type,
78+
datetime.today().strftime("%Y-%m-%d"),
8879
)
8980
)
9081
print(f"\n Search Post Request - \n {context.request}")
91-
context.response = http_requests_session.post(context.url, headers=context.headers, data=context.request)
92-
print(f"\n Search Post Response - \n {context.response.json()}")
82+
trigger_search_request_by_httpMethod(context, httpMethod="POST")
9383

9484

95-
@when("Send a search request with POST method using target-disease for Immunization event created")
96-
def send_search_post_with_target_disease(context):
97-
get_search_post_url_header(context)
85+
@when(
86+
parsers.parse("Send a search request with '{httpMethod}' method using target-disease for Immunization event created")
87+
)
88+
def send_search_with_target_disease(context, httpMethod):
9889
patient_ident = context.create_object.contained[1].identifier[0]
9990
target = context.create_object.protocolApplied[0].targetDisease[0].coding[0]
10091
context.request = {
10192
"patient.identifier": f"{patient_ident.system}|{patient_ident.value}",
10293
"target-disease": f"{target.system}|{target.code}",
10394
}
104-
print(f"\n Search Post request (target-disease) - \n {context.request}")
105-
context.response = http_requests_session.post(context.url, headers=context.headers, data=context.request)
106-
107-
108-
@when("Send a search request with GET method using comma-separated target-disease for Immunization event created")
109-
def send_search_get_with_comma_separated_target_disease(context):
110-
get_search_get_url_header(context)
111-
patient_ident = context.create_object.contained[1].identifier[0]
112-
targets = context.create_object.protocolApplied[0].targetDisease
113-
target_parts = [f"{t.coding[0].system}|{t.coding[0].code}" for t in targets[:2]]
114-
context.params = {
115-
"patient.identifier": f"{patient_ident.system}|{patient_ident.value}",
116-
"target-disease": ",".join(target_parts),
117-
}
118-
print(f"\n Search Get parameters (comma-separated target-disease) - \n {context.params}")
119-
context.response = http_requests_session.get(context.url, params=context.params, headers=context.headers)
95+
trigger_search_request_by_httpMethod(context, httpMethod=httpMethod)
12096

12197

122-
@when("Send a search request with POST method using comma-separated target-disease for Immunization event created")
123-
def send_search_post_with_comma_separated_target_disease(context):
124-
get_search_post_url_header(context)
98+
@when(
99+
parsers.parse(
100+
"Send a search request with '{httpMethod}' method using comma-separated target-disease for Immunization event created"
101+
)
102+
)
103+
def send_search_post_with_comma_separated_target_disease(context, httpMethod):
125104
patient_ident = context.create_object.contained[1].identifier[0]
126105
targets = context.create_object.protocolApplied[0].targetDisease
127106
target_parts = [f"{t.coding[0].system}|{t.coding[0].code}" for t in targets[:2]]
128107
context.request = {
129108
"patient.identifier": f"{patient_ident.system}|{patient_ident.value}",
130109
"target-disease": ",".join(target_parts),
131110
}
132-
print(f"\n Search Post request (comma-separated target-disease) - \n {context.request}")
133-
context.response = http_requests_session.post(context.url, headers=context.headers, data=context.request)
111+
trigger_search_request_by_httpMethod(context, httpMethod=httpMethod)
134112

135113

136114
@when(
137115
"Send a search request with GET method using target-disease and Date From and Date To for Immunization event created"
138116
)
139117
def send_search_get_with_target_disease_and_dates(context):
140-
get_search_get_url_header(context)
141118
patient_ident = context.create_object.contained[1].identifier[0]
142119
target = context.create_object.protocolApplied[0].targetDisease[0].coding[0]
143120
context.DateFrom = "2023-01-01"
@@ -148,15 +125,13 @@ def send_search_get_with_target_disease_and_dates(context):
148125
"-date.from": context.DateFrom,
149126
"-date.to": context.DateTo,
150127
}
151-
print(f"\n Search Get parameters (target-disease with dates) - \n {context.params}")
152-
context.response = http_requests_session.get(context.url, params=context.params, headers=context.headers)
128+
trigger_search_request_by_httpMethod(context, httpMethod="GET")
153129

154130

155131
@when(
156132
"Send a search request with POST method using target-disease and Date From and Date To for Immunization event created"
157133
)
158134
def send_search_post_with_target_disease_and_dates(context):
159-
get_search_post_url_header(context)
160135
patient_ident = context.create_object.contained[1].identifier[0]
161136
target = context.create_object.protocolApplied[0].targetDisease[0].coding[0]
162137
context.DateFrom = "2023-01-01"
@@ -167,72 +142,41 @@ def send_search_post_with_target_disease_and_dates(context):
167142
"-date.from": context.DateFrom,
168143
"-date.to": context.DateTo,
169144
}
170-
print(f"\n Search Post request (target-disease with dates) - \n {context.request}")
171-
context.response = http_requests_session.post(context.url, headers=context.headers, data=context.request)
145+
trigger_search_request_by_httpMethod(context, httpMethod="POST")
172146

173147

174148
@when("Send a search request with GET method using target-disease for Immunization event created with valid NHS Number")
175149
def send_search_get_with_target_disease_unauthorised_supplier(context):
176-
get_search_get_url_header(context)
177150
nhs_number = "9000000009"
178151
context.params = {
179152
"patient.identifier": f"{PATIENT_IDENTIFIER_SYSTEM}|{nhs_number}",
180153
"target-disease": f"{TARGET_DISEASE_SYSTEM}|14189004",
181154
}
182-
print(f"\n Search Get parameters (target-disease, 403 check) - \n {context.params}")
183-
context.response = http_requests_session.get(context.url, params=context.params, headers=context.headers)
155+
trigger_search_request_by_httpMethod(context, httpMethod="GET")
184156

185157

186-
@when("Send a search request with GET method with valid NHS Number and all invalid target-disease codes")
187-
def send_search_get_with_all_invalid_target_disease_codes(context):
188-
get_search_get_url_header(context)
189-
context.params = {
190-
"patient.identifier": f"{PATIENT_IDENTIFIER_SYSTEM}|9000000009",
191-
"target-disease": "invalid-no-pipe,wrong_system|123",
192-
}
193-
print(f"\n Search Get parameters (all invalid target-disease) - \n {context.params}")
194-
context.response = http_requests_session.get(context.url, params=context.params, headers=context.headers)
195-
196-
197-
@when("Send a search request with POST method with valid NHS Number and all invalid target-disease codes")
198-
def send_search_post_with_all_invalid_target_disease_codes(context):
199-
get_search_post_url_header(context)
158+
@when("Send a search request with '{httpMethod}' method with valid NHS Number and all invalid target-disease codes")
159+
def send_search_request_with_all_invalid_target_disease_codes(context, httpMethod):
200160
context.request = {
201161
"patient.identifier": f"{PATIENT_IDENTIFIER_SYSTEM}|9000000009",
202162
"target-disease": "invalid-no-pipe,wrong_system|123",
203163
}
204-
print(f"\n Search Post request (all invalid target-disease) - \n {context.request}")
205-
context.response = http_requests_session.post(context.url, headers=context.headers, data=context.request)
206-
207-
208-
@when(
209-
"Send a search request with GET method using mixed valid and invalid target-disease codes for Immunization event created"
210-
)
211-
def send_search_get_with_mixed_valid_and_invalid_target_disease_codes(context):
212-
get_search_get_url_header(context)
213-
patient_ident = context.create_object.contained[1].identifier[0]
214-
target = context.create_object.protocolApplied[0].targetDisease[0].coding[0]
215-
context.params = {
216-
"patient.identifier": f"{patient_ident.system}|{patient_ident.value}",
217-
"target-disease": f"{target.system}|{target.code},{TARGET_DISEASE_SYSTEM}|{INVALID_TARGET_DISEASE_CODE}",
218-
}
219-
print(f"\n Search Get parameters (mixed valid/invalid target-disease) - \n {context.params}")
220-
context.response = http_requests_session.get(context.url, params=context.params, headers=context.headers)
164+
trigger_search_request_by_httpMethod(context, httpMethod=httpMethod)
221165

222166

223167
@when(
224-
"Send a search request with POST method using mixed valid and invalid target-disease codes for Immunization event created"
168+
parsers.parse(
169+
"Send a search request with '{httpMethod}' method using mixed valid and invalid target-disease codes for Immunization event created"
170+
)
225171
)
226-
def send_search_post_with_mixed_valid_and_invalid_target_disease_codes(context):
227-
get_search_post_url_header(context)
172+
def send_search_post_with_mixed_valid_and_invalid_target_disease_codes(context, httpMethod):
228173
patient_ident = context.create_object.contained[1].identifier[0]
229174
target = context.create_object.protocolApplied[0].targetDisease[0].coding[0]
230175
context.request = {
231176
"patient.identifier": f"{patient_ident.system}|{patient_ident.value}",
232177
"target-disease": f"{target.system}|{target.code},{TARGET_DISEASE_SYSTEM}|{INVALID_TARGET_DISEASE_CODE}",
233178
}
234-
print(f"\n Search Post request (mixed valid/invalid target-disease) - \n {context.request}")
235-
context.response = http_requests_session.post(context.url, headers=context.headers, data=context.request)
179+
trigger_search_request_by_httpMethod(context, httpMethod=httpMethod)
236180

237181

238182
@when(
@@ -284,16 +228,14 @@ def send_search_with_target_disease_and_immunization_target(context, httpMethod)
284228

285229
@when("Send a search request with GET method using target-disease and identifier for Immunization event created")
286230
def send_search_get_with_target_disease_and_identifier(context):
287-
get_search_get_url_header(context)
288231
patient_ident = context.create_object.contained[1].identifier[0]
289232
target = context.create_object.protocolApplied[0].targetDisease[0].coding[0]
290233
context.params = {
291234
"patient.identifier": f"{patient_ident.system}|{patient_ident.value}",
292235
"target-disease": f"{target.system}|{target.code}",
293236
"identifier": "https://example.org|abc-123",
294237
}
295-
print(f"\n Search Get parameters (target-disease with identifier) - \n {context.params}")
296-
context.response = http_requests_session.get(context.url, params=context.params, headers=context.headers)
238+
trigger_search_request_by_httpMethod(context, httpMethod="GET")
297239

298240

299241
@when(

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
from utilities.batch_file_helper import validate_inf_ack_file
1010
from utilities.batch_S3_buckets import wait_and_read_ack_file
1111

12-
from .batch_common_steps import build_dataFrame_using_datatable, create_batch_file, ignore_if_local_run
12+
from .batch_common_steps import (
13+
build_dataFrame_using_datatable,
14+
create_batch_file,
15+
ignore_if_local_run,
16+
)
1317

1418
scenarios("batchTests/batch_file_validation.feature")
1519

@@ -77,7 +81,7 @@ def batch_file_with_additional_column_is_created(datatable, context):
7781
def file_will_be_moved_to_destination_bucket(context):
7882
result = wait_and_read_ack_file(context, "ack", duplicate_inf_files=True)
7983
assert result is not None, f"File not found in destination bucket after timeout: {context.forwarded_prefix}"
80-
context.fileContent = result["csv"]
84+
context.fileContent = result["csv"]["content"]
8185
assert context.fileContent, f"File not found in destination bucket after timeout: {context.forwarded_prefix}"
8286

8387

tests/e2e_automation/utilities/batch_S3_buckets.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,27 @@ def wait_and_read_ack_file(
8383
if not contents:
8484
print(f"[WAIT] No files found yet... ({elapsed}s)")
8585
else:
86+
contents = sorted(contents, key=lambda x: x["LastModified"], reverse=True)
87+
8688
if duplicate_inf_files and len(contents) == 1:
8789
print(f"[WAIT] Waiting for more INF files... ({elapsed}s)")
90+
time.sleep(interval)
91+
elapsed += interval
92+
continue
8893

8994
elif duplicate_bus_files:
9095
if len(contents) > len(expected_extensions):
9196
print(f"[ERROR] Unexpected extra BUS files detected: {contents}")
9297
return "Unexpected duplicate BUS file found"
93-
elif len(contents) < len(expected_extensions):
94-
print(f"[WAIT] Not all BUS ACK files arrived yet... ({elapsed}s)")
98+
99+
print("[INFO] BUS mode: expected files already exist — skipping processing")
100+
return None
101+
102+
if len(contents) < len(expected_extensions):
103+
print(f"[WAIT] Not all BUS ACK files arrived yet... ({elapsed}s)")
104+
time.sleep(interval)
105+
elapsed += interval
106+
continue
95107

96108
for obj in contents:
97109
key = obj["Key"]
@@ -111,10 +123,10 @@ def wait_and_read_ack_file(
111123
if expected_extensions == {".csv"}:
112124
return {"csv": found_files[".csv"]}
113125

114-
return {"csv": found_files[".csv"], "json": found_files[".json"]}
115-
116-
time.sleep(interval)
117-
elapsed += interval
126+
return {
127+
"csv": found_files[".csv"],
128+
"json": found_files[".json"],
129+
}
118130

119131
except ClientError as e:
120132
print(f"[ERROR] S3 access failed: {e}")

tests/e2e_automation/utilities/batch_file_helper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def validate_bus_ack_file_for_successful_records(context, file_rows) -> bool:
3232

3333
def validate_inf_ack_file(context, success: bool = True) -> bool:
3434
content = context.fileContent
35+
content = content.replace("\r\n", "\n")
3536
lines = content.strip().split("\n")
3637
header = lines[0].split("|")
3738
row = lines[1].split("|")

0 commit comments

Comments
 (0)