aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/tests/accept.py
diff options
context:
space:
mode:
authorTom Christie2012-02-17 09:19:13 +0000
committerTom Christie2012-02-17 09:19:13 +0000
commitfbf76c87affc88f04bb0d0acaecc6af6442ba921 (patch)
tree5a75cbb061829694c4f714ae0e8413c584131739 /djangorestframework/tests/accept.py
parent426493a78f3003fdba39053b6af23b93b312a777 (diff)
parentc04cb5145c4398cfac090ca7eef032296a04446f (diff)
downloaddjango-rest-framework-fbf76c87affc88f04bb0d0acaecc6af6442ba921.tar.bz2
Merge git://github.com/sebpiq/django-rest-framework into develop
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')