Skip to content

Commit 5ade9df

Browse files
committed
assert the response status
1 parent bbbaaaa commit 5ade9df

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

tests/test_mig_wsgi-bin_migwsgi.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,17 @@ def was_called(fake):
185185
self.assertTrue(was_called(self.instrumented_format_output))
186186
self.assertTrue(was_called(self.instrumented_retrieve_handler))
187187

188+
def assertResponseStatus(self, expected_status_code):
189+
def called_once(fake):
190+
assert hasattr(fake, 'calls')
191+
return len(fake.calls) == 1
192+
193+
self.assertTrue(called_once(self.fake_start_response))
194+
thecall = self.fake_start_response.calls[0]
195+
wsgi_status = thecall[0]
196+
actual_status_code = int(wsgi_status[0:3])
197+
self.assertEqual(actual_status_code, expected_status_code)
198+
188199
def assertIsValidHtmlDocument(self, value):
189200
assert isinstance(value, type(u""))
190201
assert value.startswith("<!DOCTYPE")
@@ -199,10 +210,12 @@ def before_each(self):
199210
def fake_start_response(status, headers, exc=None):
200211
fake_start_response.calls.append((status, headers, exc))
201212
fake_start_response.calls = []
213+
self.fake_start_response = fake_start_response
202214

203215
def fake_set_environ(value):
204216
fake_set_environ.calls.append((value))
205217
fake_set_environ.calls = []
218+
self.fake_set_environ = fake_set_environ
206219

207220
fake_wsgi_environ = create_wsgi_environ(_TEST_CONF_FILE, wsgi_variables=dict(
208221
http_host='localhost',
@@ -219,7 +232,21 @@ def fake_set_environ(value):
219232
_set_environ=fake_set_environ,
220233
)
221234

222-
def test_creates_valid_html_page_for_return_value_ok(self):
235+
def test_return_value_ok_returns_status_200(self):
236+
application_result = migwsgi._application(
237+
*self.application_args,
238+
_wrap_wsgi_errors=noop,
239+
_config_file=_TEST_CONF_FILE,
240+
_skip_log=True,
241+
**self.application_kwargs
242+
)
243+
244+
output = _unpack_result(application_result)
245+
246+
self.assertInstrumentation()
247+
self.assertResponseStatus(200)
248+
249+
def test_return_value_ok_creates_valid_html_page(self):
223250
application_result = migwsgi._application(
224251
*self.application_args,
225252
_wrap_wsgi_errors=noop,

0 commit comments

Comments
 (0)