summaryrefslogtreecommitdiff
path: root/tests/responses
diff options
context:
space:
mode:
authorRyan Allen <ryan@ryangallen.com>2016-08-27 20:21:37 -0400
committerTim Graham <timograham@gmail.com>2016-08-30 21:59:43 -0400
commit190d2ff4a7a392adfe0b12552bd71871791d87aa (patch)
tree1af46128b86be17a6c89edfe016ba19bd41b58b2 /tests/responses
parent96ee486ea415a532dbded3209114b98736031118 (diff)
downloaddjango-190d2ff4a7a392adfe0b12552bd71871791d87aa.tar.gz
Fixed #27153 -- Added validation for HttpResponse status.
Diffstat (limited to 'tests/responses')
-rw-r--r--tests/responses/tests.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/tests/responses/tests.py b/tests/responses/tests.py
index 53e517496e..668d5420f0 100644
--- a/tests/responses/tests.py
+++ b/tests/responses/tests.py
@@ -63,10 +63,30 @@ class HttpResponseTests(SimpleTestCase):
self.assertEqual(resp.status_code, 503)
self.assertEqual(resp.reason_phrase, "Service Unavailable")
+ def test_valid_status_code_string(self):
+ resp = HttpResponse(status='100')
+ self.assertEqual(resp.status_code, 100)
+ resp = HttpResponse(status='404')
+ self.assertEqual(resp.status_code, 404)
+ resp = HttpResponse(status='599')
+ self.assertEqual(resp.status_code, 599)
+
+ def test_invalid_status_code(self):
+ must_be_integer = 'HTTP status code must be an integer.'
+ must_be_integer_in_range = 'HTTP status code must be an integer from 100 to 599.'
+ with self.assertRaisesMessage(TypeError, must_be_integer):
+ HttpResponse(status=object())
+ with self.assertRaisesMessage(TypeError, must_be_integer):
+ HttpResponse(status="J'attendrai")
+ with self.assertRaisesMessage(ValueError, must_be_integer_in_range):
+ HttpResponse(status=99)
+ with self.assertRaisesMessage(ValueError, must_be_integer_in_range):
+ HttpResponse(status=600)
+
def test_reason_phrase(self):
reason = "I'm an anarchist coffee pot on crack."
- resp = HttpResponse(status=814, reason=reason)
- self.assertEqual(resp.status_code, 814)
+ resp = HttpResponse(status=419, reason=reason)
+ self.assertEqual(resp.status_code, 419)
self.assertEqual(resp.reason_phrase, reason)
def test_charset_detection(self):