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,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" )
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 )
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)
139117def 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)
158134def 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" )
175149def 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" )
286230def 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 (
0 commit comments