diff options
author | Gael Pasgrimaud <gael@gawel.org> | 2014-06-20 23:41:24 +0200 |
---|---|---|
committer | Gael Pasgrimaud <gael@gawel.org> | 2014-06-20 23:41:24 +0200 |
commit | b2743e76ba6482ac531420f9021c71a9baffaf01 (patch) | |
tree | 485eb2a014ff306f0948c5427de15a4f5924ff3a | |
parent | c30de67b37be996105dda65dd1338c493fb50575 (diff) | |
parent | 371f54f6ab65b133112d5cfc0da39eb77963e702 (diff) | |
download | webtest-b2743e76ba6482ac531420f9021c71a9baffaf01.tar.gz |
Merge pull request #121 from lieryan/master
add support for checking custom reason phrase using status parameter
-rw-r--r-- | docs/testapp.rst | 3 | ||||
-rw-r--r-- | tests/test_app.py | 7 | ||||
-rw-r--r-- | webtest/app.py | 3 |
3 files changed, 12 insertions, 1 deletions
diff --git a/docs/testapp.rst b/docs/testapp.rst index fb7066e..5fb5a78 100644 --- a/docs/testapp.rst +++ b/docs/testapp.rst @@ -146,6 +146,7 @@ you are testing is something you should avoid). To indicate another status is expected, use the keyword argument ``status=404`` to (for example) check that it is a 404 status, or -``status="*"`` to allow any status. +``status="*"`` to allow any status, or ``status="400 Custom Bad Request"`` +to use custom reason phrase. If you expect errors to be printed, use ``expect_errors=True``. diff --git a/tests/test_app.py b/tests/test_app.py index db94c87..5e249cc 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -109,6 +109,13 @@ class TestStatus(unittest.TestCase): self.assertEqual(self.check_status('200 Ok', None), None) self.assertRaises(webtest.AppError, self.check_status, '400 Ok') + def test_check_status_with_custom_reason(self): + self.assertEqual(self.check_status('200 Ok', '200 Ok'), None) + self.assertRaises(webtest.AppError, + self.check_status, '200 Ok', '200 Good Response') + self.assertRaises(webtest.AppError, + self.check_status, '200 Ok', '400 Bad Request') + class TestParserFeature(unittest.TestCase): diff --git a/webtest/app.py b/webtest/app.py index d66d871..4be6eda 100644 --- a/webtest/app.py +++ b/webtest/app.py @@ -643,6 +643,9 @@ class TestApp(object): if (isinstance(status, string_types) and '*' in status): if re.match(fnmatch.translate(status), res_status, re.I): return + if isinstance(status, string_types): + if status == res_status: + return if isinstance(status, (list, tuple)): if res.status_int not in status: raise AppError( |