aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/tests/content.py
diff options
context:
space:
mode:
authorTom Drummond2011-07-15 17:19:12 +0100
committerTom Drummond2011-07-15 17:19:12 +0100
commita53101bea9f6fbf7d7528a7c4aba3d83e3dbc241 (patch)
treecabd32b0dba3013b812182ca1b845655fd013dfc /djangorestframework/tests/content.py
parent7e2e3cbf6e4b13979ddc7e827f8b25b6aaae93c3 (diff)
downloaddjango-rest-framework-a53101bea9f6fbf7d7528a7c4aba3d83e3dbc241.tar.bz2
More tests for overloaded json requests and normal json requests
Diffstat (limited to 'djangorestframework/tests/content.py')
-rw-r--r--djangorestframework/tests/content.py40
1 files changed, 38 insertions, 2 deletions
diff --git a/djangorestframework/tests/content.py b/djangorestframework/tests/content.py
index 02982004..0764d12b 100644
--- a/djangorestframework/tests/content.py
+++ b/djangorestframework/tests/content.py
@@ -114,7 +114,7 @@ class TestContentParsing(TestCase):
self.assertEqual(view.DATA.items(), form_data.items())
self.assertEqual(view.request.POST.items(), form_data.items())
- def test_empty_post_after_data_for_json(self):
+ def test_accessing_post_after_data_for_json(self):
"""Ensures request.POST can be accessed after request.DATA in json request"""
from django.utils import simplejson as json
@@ -125,6 +125,22 @@ class TestContentParsing(TestCase):
view = RequestMixin()
view.parsers = (JSONParser,)
+ view.request = self.req.post('/', content, content_type=content_type)
+
+ self.assertEqual(view.DATA.items(), data.items())
+ self.assertEqual(view.request.POST.items(), [])
+
+ def test_accessing_post_after_data_for_overloaded_json(self):
+ """Ensures request.POST can be accessed after request.DATA in overloaded json request"""
+ from django.utils import simplejson as json
+
+ data = {'qwerty': 'uiop'}
+ content = json.dumps(data)
+ content_type = 'application/json'
+
+ view = RequestMixin()
+ view.parsers = (JSONParser,)
+
form_data = {view._CONTENT_PARAM: content,
view._CONTENTTYPE_PARAM: content_type}
@@ -143,7 +159,7 @@ class TestContentParsing(TestCase):
self.assertEqual(view.request.POST.items(), form_data.items())
self.assertEqual(view.DATA.items(), form_data.items())
- def test_accessing_data_after_post_json(self):
+ def test_accessing_data_after_post_for_json(self):
"""Ensures request.DATA can be accessed after request.POST in json request"""
from django.utils import simplejson as json
@@ -154,6 +170,26 @@ class TestContentParsing(TestCase):
view = RequestMixin()
view.parsers = (JSONParser,)
+ view.request = self.req.post('/', content, content_type=content_type)
+
+ post_items = view.request.POST.items()
+
+ self.assertEqual(len(post_items), 1)
+ self.assertEqual(len(post_items[0]), 2)
+ self.assertEqual(post_items[0][0], content)
+ self.assertEqual(view.DATA.items(), data.items())
+
+ def test_accessing_data_after_post_for_overloaded_json(self):
+ """Ensures request.DATA can be accessed after request.POST in overloaded json request"""
+ from django.utils import simplejson as json
+
+ data = {'qwerty': 'uiop'}
+ content = json.dumps(data)
+ content_type = 'application/json'
+
+ view = RequestMixin()
+ view.parsers = (JSONParser,)
+
form_data = {view._CONTENT_PARAM: content,
view._CONTENTTYPE_PARAM: content_type}