summaryrefslogtreecommitdiff
path: root/tests/middleware
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/middleware
parent7f63b894c02effb09c15ab0b40d28b89553b8e37 (diff)
downloaddjango-0f212db29d361ec6219b170198b7c94d0bb3f719.tar.gz
Made reused RequestFactory instances class attributes.
Diffstat (limited to 'tests/middleware')
-rw-r--r--tests/middleware/tests.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/tests/middleware/tests.py b/tests/middleware/tests.py
index 88e33348e6..2da1e11a4e 100644
--- a/tests/middleware/tests.py
+++ b/tests/middleware/tests.py
@@ -428,9 +428,10 @@ class BrokenLinkEmailsMiddlewareTest(SimpleTestCase):
@override_settings(ROOT_URLCONF='middleware.cond_get_urls')
class ConditionalGetMiddlewareTest(SimpleTestCase):
+ request_factory = RequestFactory()
def setUp(self):
- self.req = RequestFactory().get('/')
+ self.req = self.request_factory.get('/')
self.resp = self.client.get(self.req.path_info)
# Tests for the ETag header
@@ -569,7 +570,7 @@ class ConditionalGetMiddlewareTest(SimpleTestCase):
"""
get_response = ConditionalGetMiddleware().process_response(self.req, self.resp)
etag = get_response['ETag']
- put_request = RequestFactory().put('/', HTTP_IF_MATCH=etag)
+ put_request = self.request_factory.put('/', HTTP_IF_MATCH=etag)
put_response = HttpResponse(status=200)
conditional_get_response = ConditionalGetMiddleware().process_response(put_request, put_response)
self.assertEqual(conditional_get_response.status_code, 200) # should never be a 412
@@ -580,7 +581,7 @@ class ConditionalGetMiddlewareTest(SimpleTestCase):
HEAD request since it can't do so accurately without access to the
response body of the corresponding GET.
"""
- request = RequestFactory().head('/')
+ request = self.request_factory.head('/')
response = HttpResponse(status=200)
conditional_get_response = ConditionalGetMiddleware().process_response(request, response)
self.assertNotIn('ETag', conditional_get_response)
@@ -700,9 +701,10 @@ class GZipMiddlewareTest(SimpleTestCase):
incompressible_string = b''.join(int2byte(random.randint(0, 255)) for _ in range(500))
sequence = [b'a' * 500, b'b' * 200, b'a' * 300]
sequence_unicode = ['a' * 500, 'é' * 200, 'a' * 300]
+ request_factory = RequestFactory()
def setUp(self):
- self.req = RequestFactory().get('/')
+ self.req = self.request_factory.get('/')
self.req.META['HTTP_ACCEPT_ENCODING'] = 'gzip, deflate'
self.req.META['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 5.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1'
self.resp = HttpResponse()