summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBaptiste Mispelon <bmispelon@gmail.com>2013-11-16 00:54:20 +0100
committerBaptiste Mispelon <bmispelon@gmail.com>2013-11-16 01:09:35 +0100
commitceecc962ad8f6bbbc2b989aec53eee6c6cca04b9 (patch)
treea0f1cf6de7185658e3ed13e6fdf27e1cb9d5c793 /tests
parentd011714002d4d8d73440149f24aa86142caf886f (diff)
Fixed #21447 -- Restored code erroneously removed in 20472aa827669d2b83b74e521504e88e18d086a1.
Also added some tests for HttpRequest.__repr__. Note that the added tests don't actually catch the accidental code removal (see ticket) but they do cover a codepath that wasn't tested before. Thanks to Tom Christie for the report and the original patch.
Diffstat (limited to 'tests')
-rw-r--r--tests/requests/tests.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/requests/tests.py b/tests/requests/tests.py
index 2a69638260..850cf70c2f 100644
--- a/tests/requests/tests.py
+++ b/tests/requests/tests.py
@@ -42,6 +42,22 @@ class RequestsTests(SimpleTestCase):
self.assertEqual(build_request_repr(request, path_override='/otherpath/', GET_override={'a': 'b'}, POST_override={'c': 'd'}, COOKIES_override={'e': 'f'}, META_override={'g': 'h'}),
str_prefix("<HttpRequest\npath:/otherpath/,\nGET:{%(_)s'a': %(_)s'b'},\nPOST:{%(_)s'c': %(_)s'd'},\nCOOKIES:{%(_)s'e': %(_)s'f'},\nMETA:{%(_)s'g': %(_)s'h'}>"))
+ def test_bad_httprequest_repr(self):
+ """
+ If an exception occurs when parsing GET, POST, COOKIES, or META, the
+ repr of the request should show it.
+ """
+ class Bomb(object):
+ """An object that raises an exception when printed out."""
+ def __repr__(self):
+ raise Exception('boom!')
+
+ bomb = Bomb()
+ for attr in ['GET', 'POST', 'COOKIES', 'META']:
+ request = HttpRequest()
+ setattr(request, attr, {'bomb': bomb})
+ self.assertIn('%s:<could not parse>' % attr, repr(request))
+
def test_wsgirequest(self):
request = WSGIRequest({'PATH_INFO': 'bogus', 'REQUEST_METHOD': 'bogus', 'wsgi.input': BytesIO(b'')})
self.assertEqual(list(request.GET.keys()), [])