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+ )
1720from utilities .date_helper import iso_to_compact
1821from utilities .http_requests_session import http_requests_session
1922
@@ -66,78 +69,51 @@ 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" )
8373def 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 )
90- 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 ()} " )
81+ trigger_search_request_by_httpMethod (context , httpMethod = "POST" )
9382
9483
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 )
84+ @when (
85+ parsers .parse ("Send a search request with '{httpMethod}' method using target-disease for Immunization event created" )
86+ )
87+ def send_search_with_target_disease (context , httpMethod ):
9888 patient_ident = context .create_object .contained [1 ].identifier [0 ]
9989 target = context .create_object .protocolApplied [0 ].targetDisease [0 ].coding [0 ]
100- context .request = {
90+ context .params = context . request = {
10191 "patient.identifier" : f"{ patient_ident .system } |{ patient_ident .value } " ,
10292 "target-disease" : f"{ target .system } |{ target .code } " ,
10393 }
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 )
94+ trigger_search_request_by_httpMethod (context , httpMethod = httpMethod )
12095
12196
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 )
97+ @when (
98+ parsers .parse (
99+ "Send a search request with '{httpMethod}' method using comma-separated target-disease for Immunization event created"
100+ )
101+ )
102+ def send_search_post_with_comma_separated_target_disease (context , httpMethod ):
125103 patient_ident = context .create_object .contained [1 ].identifier [0 ]
126104 targets = context .create_object .protocolApplied [0 ].targetDisease
127105 target_parts = [f"{ t .coding [0 ].system } |{ t .coding [0 ].code } " for t in targets [:2 ]]
128- context .request = {
106+ context .params = context . request = {
129107 "patient.identifier" : f"{ patient_ident .system } |{ patient_ident .value } " ,
130108 "target-disease" : "," .join (target_parts ),
131109 }
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 )
110+ trigger_search_request_by_httpMethod (context , httpMethod = httpMethod )
134111
135112
136113@when (
137114 "Send a search request with GET method using target-disease and Date From and Date To for Immunization event created"
138115)
139116def send_search_get_with_target_disease_and_dates (context ):
140- get_search_get_url_header (context )
141117 patient_ident = context .create_object .contained [1 ].identifier [0 ]
142118 target = context .create_object .protocolApplied [0 ].targetDisease [0 ].coding [0 ]
143119 context .DateFrom = "2023-01-01"
@@ -148,15 +124,13 @@ def send_search_get_with_target_disease_and_dates(context):
148124 "-date.from" : context .DateFrom ,
149125 "-date.to" : context .DateTo ,
150126 }
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 )
127+ trigger_search_request_by_httpMethod (context , httpMethod = "GET" )
153128
154129
155130@when (
156131 "Send a search request with POST method using target-disease and Date From and Date To for Immunization event created"
157132)
158133def send_search_post_with_target_disease_and_dates (context ):
159- get_search_post_url_header (context )
160134 patient_ident = context .create_object .contained [1 ].identifier [0 ]
161135 target = context .create_object .protocolApplied [0 ].targetDisease [0 ].coding [0 ]
162136 context .DateFrom = "2023-01-01"
@@ -167,72 +141,45 @@ def send_search_post_with_target_disease_and_dates(context):
167141 "-date.from" : context .DateFrom ,
168142 "-date.to" : context .DateTo ,
169143 }
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 )
144+ trigger_search_request_by_httpMethod (context , httpMethod = "POST" )
172145
173146
174147@when ("Send a search request with GET method using target-disease for Immunization event created with valid NHS Number" )
175148def send_search_get_with_target_disease_unauthorised_supplier (context ):
176- get_search_get_url_header (context )
177149 nhs_number = "9000000009"
178150 context .params = {
179151 "patient.identifier" : f"{ PATIENT_IDENTIFIER_SYSTEM } |{ nhs_number } " ,
180152 "target-disease" : f"{ TARGET_DISEASE_SYSTEM } |14189004" ,
181153 }
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 )
184-
185-
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 )
200- context .request = {
201- "patient.identifier" : f"{ PATIENT_IDENTIFIER_SYSTEM } |9000000009" ,
202- "target-disease" : "invalid-no-pipe,wrong_system|123" ,
203- }
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 )
154+ trigger_search_request_by_httpMethod (context , httpMethod = "GET" )
206155
207156
208157@when (
209- "Send a search request with GET method using mixed valid and invalid target-disease codes for Immunization event created"
158+ parsers .parse (
159+ "Send a search request with '{httpMethod}' method with valid NHS Number and all invalid target-disease codes"
160+ )
210161)
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 } " ,
162+ def send_search_request_with_all_invalid_target_disease_codes (context , httpMethod ):
163+ context .params = context .request = {
164+ "patient.identifier" : f"{ PATIENT_IDENTIFIER_SYSTEM } |9000000009" ,
165+ "target-disease" : "invalid-no-pipe,wrong_system|123" ,
218166 }
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 )
167+ trigger_search_request_by_httpMethod (context , httpMethod = httpMethod )
221168
222169
223170@when (
224- "Send a search request with POST method using mixed valid and invalid target-disease codes for Immunization event created"
171+ parsers .parse (
172+ "Send a search request with '{httpMethod}' method using mixed valid and invalid target-disease codes for Immunization event created"
173+ )
225174)
226- def send_search_post_with_mixed_valid_and_invalid_target_disease_codes (context ):
227- get_search_post_url_header (context )
175+ def send_search_post_with_mixed_valid_and_invalid_target_disease_codes (context , httpMethod ):
228176 patient_ident = context .create_object .contained [1 ].identifier [0 ]
229177 target = context .create_object .protocolApplied [0 ].targetDisease [0 ].coding [0 ]
230- context .request = {
178+ context .params = context . request = {
231179 "patient.identifier" : f"{ patient_ident .system } |{ patient_ident .value } " ,
232180 "target-disease" : f"{ target .system } |{ target .code } ,{ TARGET_DISEASE_SYSTEM } |{ INVALID_TARGET_DISEASE_CODE } " ,
233181 }
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 )
182+ trigger_search_request_by_httpMethod (context , httpMethod = httpMethod )
236183
237184
238185@when (
@@ -284,16 +231,14 @@ def send_search_with_target_disease_and_immunization_target(context, httpMethod)
284231
285232@when ("Send a search request with GET method using target-disease and identifier for Immunization event created" )
286233def send_search_get_with_target_disease_and_identifier (context ):
287- get_search_get_url_header (context )
288234 patient_ident = context .create_object .contained [1 ].identifier [0 ]
289235 target = context .create_object .protocolApplied [0 ].targetDisease [0 ].coding [0 ]
290236 context .params = {
291237 "patient.identifier" : f"{ patient_ident .system } |{ patient_ident .value } " ,
292238 "target-disease" : f"{ target .system } |{ target .code } " ,
293239 "identifier" : "https://example.org|abc-123" ,
294240 }
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 )
241+ trigger_search_request_by_httpMethod (context , httpMethod = "GET" )
297242
298243
299244@when (
0 commit comments