@@ -88,7 +88,7 @@ def _is_return_value(return_value):
88
88
return return_value in defined_return_values
89
89
90
90
91
- def _unpack_result (application_result ):
91
+ def _trigger_and_unpack_result (application_result ):
92
92
chunks = list (application_result )
93
93
assert len (chunks ) > 0 , "invocation returned no output"
94
94
complete_value = b'' .join (chunks )
@@ -147,17 +147,17 @@ def _instrumented_format_output(
147
147
return _instrumented_format_output
148
148
149
149
150
- def create_instrumented_retrieve_handler (output_objects = None , return_value = None ):
151
- if not output_objects :
152
- output_objects = []
153
-
154
- assert isinstance (output_objects , list )
155
- assert _is_return_value (return_value ), "return value must be present in returnvalues"
156
-
150
+ def create_instrumented_retrieve_handler ():
157
151
def _instrumented_retrieve_handler (* args ):
158
152
_instrumented_retrieve_handler .calls .append (tuple (args ))
159
- return [], return_value
153
+ return _instrumented_retrieve_handler .returning or ([], returnvalues .ERROR )
154
+ def _program (output_objects = None , return_value = None ):
155
+ assert _is_return_value (return_value ), "return value must be present in returnvalues"
156
+ assert isinstance (output_objects , list )
157
+ _instrumented_retrieve_handler .returning = (output_objects , return_value )
160
158
_instrumented_retrieve_handler .calls = []
159
+ _instrumented_retrieve_handler .returning = None
160
+ _instrumented_retrieve_handler .program = _program
161
161
162
162
return _instrumented_retrieve_handler
163
163
@@ -178,12 +178,14 @@ def noop(*args):
178
178
179
179
class MigWsgi_binMigwsgi (MigTestCase ):
180
180
def assertInstrumentation (self ):
181
+ self .assertIsNotNone (self .instrumented_retrieve_handler .returning , "no response programmed" )
182
+
181
183
def was_called (fake ):
182
184
assert hasattr (fake , 'calls' )
183
185
return len (fake .calls ) > 0
184
186
185
- self .assertTrue (was_called (self .instrumented_format_output ))
186
- self .assertTrue (was_called (self .instrumented_retrieve_handler ))
187
+ self .assertTrue (was_called (self .instrumented_format_output ), "no output generated" )
188
+ self .assertTrue (was_called (self .instrumented_retrieve_handler ), "no output generated" )
187
189
188
190
def assertResponseStatus (self , expected_status_code ):
189
191
def called_once (fake ):
@@ -223,7 +225,7 @@ def fake_set_environ(value):
223
225
))
224
226
225
227
self .instrumented_format_output = create_instrumented_format_output ('HELLO WORLD' )
226
- self .instrumented_retrieve_handler = create_instrumented_retrieve_handler (None , returnvalues . OK )
228
+ self .instrumented_retrieve_handler = create_instrumented_retrieve_handler ()
227
229
228
230
self .application_args = (fake_wsgi_environ , fake_start_response ,)
229
231
self .application_kwargs = dict (
@@ -233,6 +235,8 @@ def fake_set_environ(value):
233
235
)
234
236
235
237
def test_return_value_ok_returns_status_200 (self ):
238
+ self .instrumented_retrieve_handler .program ([], returnvalues .OK )
239
+
236
240
application_result = migwsgi ._application (
237
241
* self .application_args ,
238
242
_wrap_wsgi_errors = noop ,
@@ -241,12 +245,14 @@ def test_return_value_ok_returns_status_200(self):
241
245
** self .application_kwargs
242
246
)
243
247
244
- output = _unpack_result (application_result )
248
+ _trigger_and_unpack_result (application_result )
245
249
246
250
self .assertInstrumentation ()
247
251
self .assertResponseStatus (200 )
248
252
249
253
def test_return_value_ok_creates_valid_html_page (self ):
254
+ self .instrumented_retrieve_handler .program ([], returnvalues .OK )
255
+
250
256
application_result = migwsgi ._application (
251
257
* self .application_args ,
252
258
_wrap_wsgi_errors = noop ,
@@ -255,7 +261,7 @@ def test_return_value_ok_creates_valid_html_page(self):
255
261
** self .application_kwargs
256
262
)
257
263
258
- output = _unpack_result (application_result )
264
+ output = _trigger_and_unpack_result (application_result )
259
265
260
266
self .assertInstrumentation ()
261
267
self .assertIsValidHtmlDocument (output )
0 commit comments