mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-03 13:14:30 +03:00
Additional test for JSON
This commit is contained in:
parent
06f69b4dce
commit
f02a4e1890
|
@ -1,12 +1,16 @@
|
||||||
from django.conf.urls.defaults import patterns, url
|
from django.conf.urls.defaults import patterns, url
|
||||||
from django import http
|
from django import http
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from djangorestframework.compat import View as DjangoView
|
from djangorestframework.compat import View as DjangoView
|
||||||
from djangorestframework.renderers import BaseRenderer, JSONRenderer
|
from djangorestframework.renderers import BaseRenderer, JSONRenderer
|
||||||
|
from djangorestframework.parsers import JSONParser
|
||||||
from djangorestframework.mixins import ResponseMixin
|
from djangorestframework.mixins import ResponseMixin
|
||||||
from djangorestframework.response import Response
|
from djangorestframework.response import Response
|
||||||
from djangorestframework.utils.mediatypes import add_media_type_param
|
from djangorestframework.utils.mediatypes import add_media_type_param
|
||||||
|
|
||||||
|
from StringIO import StringIO
|
||||||
|
|
||||||
DUMMYSTATUS = 200
|
DUMMYSTATUS = 200
|
||||||
DUMMYCONTENT = 'dummycontent'
|
DUMMYCONTENT = 'dummycontent'
|
||||||
|
|
||||||
|
@ -95,14 +99,35 @@ class JSONRendererTests(TestCase):
|
||||||
"""
|
"""
|
||||||
Tests specific to the JSON Renderer
|
Tests specific to the JSON Renderer
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def test_without_content_type_args(self):
|
def test_without_content_type_args(self):
|
||||||
|
"""
|
||||||
|
Test basic JSON rendering.
|
||||||
|
"""
|
||||||
obj = {'foo':['bar','baz']}
|
obj = {'foo':['bar','baz']}
|
||||||
renderer = JSONRenderer(None)
|
renderer = JSONRenderer(None)
|
||||||
content = renderer.render(obj, 'application/json')
|
content = renderer.render(obj, 'application/json')
|
||||||
self.assertEquals(content, _flat_repr)
|
self.assertEquals(content, _flat_repr)
|
||||||
|
|
||||||
def test_with_content_type_args(self):
|
def test_with_content_type_args(self):
|
||||||
|
"""
|
||||||
|
Test JSON rendering with additional content type arguments supplied.
|
||||||
|
"""
|
||||||
obj = {'foo':['bar','baz']}
|
obj = {'foo':['bar','baz']}
|
||||||
renderer = JSONRenderer(None)
|
renderer = JSONRenderer(None)
|
||||||
content = renderer.render(obj, 'application/json; indent=2')
|
content = renderer.render(obj, 'application/json; indent=2')
|
||||||
self.assertEquals(content, _indented_repr)
|
self.assertEquals(content, _indented_repr)
|
||||||
|
|
||||||
|
def test_render_and_parse(self):
|
||||||
|
"""
|
||||||
|
Test rendering and then parsing returns the original object.
|
||||||
|
IE obj -> render -> parse -> obj.
|
||||||
|
"""
|
||||||
|
obj = {'foo':['bar','baz']}
|
||||||
|
|
||||||
|
renderer = JSONRenderer(None)
|
||||||
|
parser = JSONParser(None)
|
||||||
|
|
||||||
|
content = renderer.render(obj, 'application/json')
|
||||||
|
(data, files) = parser.parse(StringIO(content))
|
||||||
|
self.assertEquals(obj, data)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user