aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/tests/accept.py
diff options
context:
space:
mode:
Diffstat (limited to 'djangorestframework/tests/accept.py')
-rw-r--r--djangorestframework/tests/accept.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/djangorestframework/tests/accept.py b/djangorestframework/tests/accept.py
index d66f6fb0..e7dfc303 100644
--- a/djangorestframework/tests/accept.py
+++ b/djangorestframework/tests/accept.py
@@ -1,6 +1,8 @@
from django.test import TestCase
+
from djangorestframework.compat import RequestFactory
from djangorestframework.views import View
+from djangorestframework.response import Response
# See: http://www.useragentstring.com/
@@ -21,9 +23,10 @@ class UserAgentMungingTest(TestCase):
class MockView(View):
permissions = ()
+ response_class = Response
def get(self, request):
- return {'a':1, 'b':2, 'c':3}
+ return self.response_class({'a':1, 'b':2, 'c':3})
self.req = RequestFactory()
self.MockView = MockView
@@ -37,18 +40,22 @@ class UserAgentMungingTest(TestCase):
MSIE_7_USER_AGENT):
req = self.req.get('/', HTTP_ACCEPT='*/*', HTTP_USER_AGENT=user_agent)
resp = self.view(req)
+ resp.render()
self.assertEqual(resp['Content-Type'], 'text/html')
-
+
def test_dont_rewrite_msie_accept_header(self):
"""Turn off _IGNORE_IE_ACCEPT_HEADER, send MSIE user agent strings and ensure
that we get a JSON response if we set a */* accept header."""
- view = self.MockView.as_view(_IGNORE_IE_ACCEPT_HEADER=False)
+ class IgnoreIEAcceptResponse(Response):
+ _IGNORE_IE_ACCEPT_HEADER=False
+ view = self.MockView.as_view(response_class=IgnoreIEAcceptResponse)
for user_agent in (MSIE_9_USER_AGENT,
MSIE_8_USER_AGENT,
MSIE_7_USER_AGENT):
req = self.req.get('/', HTTP_ACCEPT='*/*', HTTP_USER_AGENT=user_agent)
resp = view(req)
+ resp.render()
self.assertEqual(resp['Content-Type'], 'application/json')
def test_dont_munge_nice_browsers_accept_header(self):
@@ -61,5 +68,6 @@ class UserAgentMungingTest(TestCase):
OPERA_11_0_OPERA_USER_AGENT):
req = self.req.get('/', HTTP_ACCEPT='*/*', HTTP_USER_AGENT=user_agent)
resp = self.view(req)
+ resp.render()
self.assertEqual(resp['Content-Type'], 'application/json')