summaryrefslogtreecommitdiff
path: root/tests/handlers
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2018-11-26 14:01:27 -0500
committerTim Graham <timograham@gmail.com>2018-11-27 09:49:02 -0500
commit0f212db29d361ec6219b170198b7c94d0bb3f719 (patch)
treeb4a1a93f3d5b725ed9d08896892f1a3f5e191ab7 /tests/handlers
parent7f63b894c02effb09c15ab0b40d28b89553b8e37 (diff)
downloaddjango-0f212db29d361ec6219b170198b7c94d0bb3f719.tar.gz
Made reused RequestFactory instances class attributes.
Diffstat (limited to 'tests/handlers')
-rw-r--r--tests/handlers/tests.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/tests/handlers/tests.py b/tests/handlers/tests.py
index 2edca592ab..70f0e875a5 100644
--- a/tests/handlers/tests.py
+++ b/tests/handlers/tests.py
@@ -8,6 +8,7 @@ from django.test import (
class HandlerTests(SimpleTestCase):
+ request_factory = RequestFactory()
def setUp(self):
request_started.disconnect(close_old_connections)
@@ -24,7 +25,7 @@ class HandlerTests(SimpleTestCase):
A non-UTF-8 path populates PATH_INFO with an URL-encoded path and
produces a 404.
"""
- environ = RequestFactory().get('/').environ
+ environ = self.request_factory.get('/').environ
environ['PATH_INFO'] = '\xed'
handler = WSGIHandler()
response = handler(environ, lambda *a, **k: None)
@@ -35,7 +36,7 @@ class HandlerTests(SimpleTestCase):
"""
Non-ASCII query strings are properly decoded (#20530, #22996).
"""
- environ = RequestFactory().get('/').environ
+ environ = self.request_factory.get('/').environ
raw_query_strings = [
b'want=caf%C3%A9', # This is the proper way to encode 'café'
b'want=caf\xc3\xa9', # UA forgot to quote bytes
@@ -53,7 +54,7 @@ class HandlerTests(SimpleTestCase):
def test_non_ascii_cookie(self):
"""Non-ASCII cookies set in JavaScript are properly decoded (#20557)."""
- environ = RequestFactory().get('/').environ
+ environ = self.request_factory.get('/').environ
raw_cookie = 'want="café"'.encode('utf-8').decode('iso-8859-1')
environ['HTTP_COOKIE'] = raw_cookie
request = WSGIRequest(environ)
@@ -64,7 +65,7 @@ class HandlerTests(SimpleTestCase):
Invalid cookie content should result in an absent cookie, but not in a
crash while trying to decode it (#23638).
"""
- environ = RequestFactory().get('/').environ
+ environ = self.request_factory.get('/').environ
environ['HTTP_COOKIE'] = 'x=W\x03c(h]\x8e'
request = WSGIRequest(environ)
# We don't test COOKIES content, as the result might differ between
@@ -78,7 +79,7 @@ class HandlerTests(SimpleTestCase):
Invalid boundary string should produce a "Bad Request" response, not a
server error (#23887).
"""
- environ = RequestFactory().post('/malformed_post/').environ
+ environ = self.request_factory.post('/malformed_post/').environ
environ['CONTENT_TYPE'] = 'multipart/form-data; boundary=WRONG\x07'
handler = WSGIHandler()
response = handler(environ, lambda *a, **k: None)
@@ -153,6 +154,7 @@ def empty_middleware(get_response):
@override_settings(ROOT_URLCONF='handlers.urls')
class HandlerRequestTests(SimpleTestCase):
+ request_factory = RequestFactory()
def test_suspiciousop_in_view_returns_400(self):
response = self.client.get('/suspicious/')
@@ -172,14 +174,14 @@ class HandlerRequestTests(SimpleTestCase):
self.assertContains(response, '\u260e%E2%A9\u2665', status_code=404)
def test_environ_path_info_type(self):
- environ = RequestFactory().get('/%E2%A8%87%87%A5%E2%A8%A0').environ
+ environ = self.request_factory.get('/%E2%A8%87%87%A5%E2%A8%A0').environ
self.assertIsInstance(environ['PATH_INFO'], str)
def test_handle_accepts_httpstatus_enum_value(self):
def start_response(status, headers):
start_response.status = status
- environ = RequestFactory().get('/httpstatus_enum/').environ
+ environ = self.request_factory.get('/httpstatus_enum/').environ
WSGIHandler()(environ, start_response)
self.assertEqual(start_response.status, '200 OK')