@@ -88,6 +88,14 @@ 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 ):
92
+ chunks = list (application_result )
93
+ assert len (chunks ) > 0 , "invocation returned no output"
94
+ complete_value = b'' .join (chunks )
95
+ decoded_value = codecs .decode (complete_value , 'utf8' )
96
+ return decoded_value
97
+
98
+
91
99
def create_instrumented_format_output (arranged ):
92
100
def _instrumented_format_output (
93
101
configuration ,
@@ -147,7 +155,10 @@ def create_instrumented_retrieve_handler(output_objects=None, return_value=None)
147
155
assert _is_return_value (return_value ), "return value must be present in returnvalues"
148
156
149
157
def _instrumented_retrieve_handler (* args ):
158
+ _instrumented_retrieve_handler .calls .append (tuple (args ))
150
159
return [], return_value
160
+ _instrumented_retrieve_handler .calls = []
161
+
151
162
return _instrumented_retrieve_handler
152
163
153
164
@@ -165,15 +176,23 @@ def noop(*args):
165
176
pass
166
177
167
178
168
- class MigSharedConfiguration (MigTestCase ):
169
- def assertHtmlBasics (self , value ):
179
+ class MigWsgi_binMigwsgi (MigTestCase ):
180
+ def assertInstrumentation (self ):
181
+ def was_called (fake ):
182
+ assert hasattr (fake , 'calls' )
183
+ return len (fake .calls ) > 0
184
+
185
+ self .assertTrue (was_called (self .instrumented_format_output ))
186
+ self .assertTrue (was_called (self .instrumented_retrieve_handler ))
187
+
188
+ def assertIsValidHtmlDocument (self , value ):
170
189
assert isinstance (value , type (u"" ))
171
190
assert value .startswith ("<!DOCTYPE" )
172
191
end_html_tag_idx = value .rfind ('</html>' )
173
192
maybe_document_end = value [end_html_tag_idx :].rstrip ()
174
193
self .assertEqual (maybe_document_end , '</html>' )
175
194
176
- def test_xxx (self ):
195
+ def before_each (self ):
177
196
config = _assert_local_config ()
178
197
config_global_values = _assert_local_config_global_values (config )
179
198
@@ -182,30 +201,37 @@ def fake_start_response(status, headers, exc=None):
182
201
fake_start_response .calls = []
183
202
184
203
def fake_set_environ (value ):
185
- fake_set_environ .value = value
186
- fake_set_environ .value = None
204
+ fake_set_environ .calls . append (( value ))
205
+ fake_set_environ .calls = []
187
206
188
- wsgi_environ = create_wsgi_environ (_TEST_CONF_FILE , wsgi_variables = dict (
207
+ fake_wsgi_environ = create_wsgi_environ (_TEST_CONF_FILE , wsgi_variables = dict (
189
208
http_host = 'localhost' ,
190
209
path_info = '/' ,
191
210
))
192
211
193
- instrumented_format_output = create_instrumented_format_output ('HELLO WORLD' )
194
- instrumented_retrieve_handler = create_instrumented_retrieve_handler (None , returnvalues .OK )
212
+ self . instrumented_format_output = create_instrumented_format_output ('HELLO WORLD' )
213
+ self . instrumented_retrieve_handler = create_instrumented_retrieve_handler (None , returnvalues .OK )
195
214
196
- yielder = migwsgi ._application (wsgi_environ , fake_start_response ,
197
- _format_output = instrumented_format_output ,
198
- _retrieve_handler = instrumented_retrieve_handler ,
215
+ self .application_args = (fake_wsgi_environ , fake_start_response ,)
216
+ self .application_kwargs = dict (
217
+ _format_output = self .instrumented_format_output ,
218
+ _retrieve_handler = self .instrumented_retrieve_handler ,
199
219
_set_environ = fake_set_environ ,
220
+ )
221
+
222
+ def test_creates_valid_html_page_for_return_value_ok (self ):
223
+ application_result = migwsgi ._application (
224
+ * self .application_args ,
200
225
_wrap_wsgi_errors = noop ,
201
226
_config_file = _TEST_CONF_FILE ,
202
227
_skip_log = True ,
228
+ ** self .application_kwargs
203
229
)
204
- chunks = list (yielder )
205
230
206
- self .assertGreater (len (chunks ), 0 )
207
- value = codecs .decode (chunks [0 ], 'utf8' )
208
- self .assertHtmlBasics (value )
231
+ output = _unpack_result (application_result )
232
+
233
+ self .assertInstrumentation ()
234
+ self .assertIsValidHtmlDocument (output )
209
235
210
236
211
237
if __name__ == '__main__' :
0 commit comments