aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/tests
diff options
context:
space:
mode:
Diffstat (limited to 'djangorestframework/tests')
-rw-r--r--djangorestframework/tests/accept.py10
-rw-r--r--djangorestframework/tests/serializer.py21
2 files changed, 31 insertions, 0 deletions
diff --git a/djangorestframework/tests/accept.py b/djangorestframework/tests/accept.py
index 21aba589..7f4eb320 100644
--- a/djangorestframework/tests/accept.py
+++ b/djangorestframework/tests/accept.py
@@ -50,6 +50,16 @@ class UserAgentMungingTest(TestCase):
resp = self.view(req)
self.assertEqual(resp['Content-Type'], 'text/html')
+ def test_dont_munge_msie_with_x_requested_with_header(self):
+ """Send MSIE user agent strings, and an X-Requested-With header, and
+ ensure that we get a JSON response if we set a */* Accept header."""
+ 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, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
+ resp = self.view(req)
+ self.assertEqual(resp['Content-Type'], 'application/json')
+
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."""
diff --git a/djangorestframework/tests/serializer.py b/djangorestframework/tests/serializer.py
index e8580610..834a60d0 100644
--- a/djangorestframework/tests/serializer.py
+++ b/djangorestframework/tests/serializer.py
@@ -104,6 +104,27 @@ class TestFieldNesting(TestCase):
self.assertEqual(SerializerM2().serialize(self.m2), {'field': {'field1': u'foo'}})
self.assertEqual(SerializerM3().serialize(self.m3), {'field': {'field2': u'bar'}})
+ def test_serializer_no_fields(self):
+ """
+ Test related serializer works when the fields attr isn't present. Fix for
+ #178.
+ """
+ class NestedM2(Serializer):
+ fields = ('field1', )
+
+ class NestedM3(Serializer):
+ fields = ('field2', )
+
+ class SerializerM2(Serializer):
+ include = [('field', NestedM2)]
+ exclude = ('id', )
+
+ class SerializerM3(Serializer):
+ fields = [('field', NestedM3)]
+
+ self.assertEqual(SerializerM2().serialize(self.m2), {'field': {'field1': u'foo'}})
+ self.assertEqual(SerializerM3().serialize(self.m3), {'field': {'field2': u'bar'}})
+
def test_serializer_classname_nesting(self):
"""
Test related model serialization