summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLie Ryan <lie.1296@gmail.com>2014-06-20 22:01:26 +0100
committerLie Ryan <lie.1296@gmail.com>2014-06-20 22:01:26 +0100
commit371f54f6ab65b133112d5cfc0da39eb77963e702 (patch)
tree485eb2a014ff306f0948c5427de15a4f5924ff3a
parentc30de67b37be996105dda65dd1338c493fb50575 (diff)
downloadwebtest-371f54f6ab65b133112d5cfc0da39eb77963e702.tar.gz
add support for checking custom reason phrase using status parameter
-rw-r--r--docs/testapp.rst3
-rw-r--r--tests/test_app.py7
-rw-r--r--webtest/app.py3
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(