2012-01-24 23:36:34 +04:00
|
|
|
import re
|
|
|
|
|
2011-04-29 17:32:56 +04:00
|
|
|
from django.conf.urls.defaults import patterns, url
|
|
|
|
from django.test import TestCase
|
2011-06-15 19:25:59 +04:00
|
|
|
|
2011-06-26 18:03:36 +04:00
|
|
|
from djangorestframework import status
|
2011-12-29 17:24:52 +04:00
|
|
|
from djangorestframework.views import View
|
2011-05-24 13:27:24 +04:00
|
|
|
from djangorestframework.compat import View as DjangoView
|
2011-12-29 17:24:52 +04:00
|
|
|
from djangorestframework.renderers import BaseRenderer, JSONRenderer, YAMLRenderer, \
|
2012-01-11 13:27:14 +04:00
|
|
|
XMLRenderer, JSONPRenderer, DocumentingHTMLRenderer
|
2012-01-12 21:04:18 +04:00
|
|
|
from djangorestframework.parsers import JSONParser, YAMLParser, XMLParser
|
2011-04-29 17:32:56 +04:00
|
|
|
from djangorestframework.mixins import ResponseMixin
|
|
|
|
from djangorestframework.response import Response
|
|
|
|
|
2011-06-15 19:25:59 +04:00
|
|
|
from StringIO import StringIO
|
2011-12-11 22:27:40 +04:00
|
|
|
import datetime
|
|
|
|
from decimal import Decimal
|
2011-06-15 19:25:59 +04:00
|
|
|
|
2011-06-26 18:03:36 +04:00
|
|
|
DUMMYSTATUS = status.HTTP_200_OK
|
2011-04-29 17:32:56 +04:00
|
|
|
DUMMYCONTENT = 'dummycontent'
|
|
|
|
|
|
|
|
RENDERER_A_SERIALIZER = lambda x: 'Renderer A: %s' % x
|
|
|
|
RENDERER_B_SERIALIZER = lambda x: 'Renderer B: %s' % x
|
|
|
|
|
2011-12-29 17:24:52 +04:00
|
|
|
|
2011-04-29 17:32:56 +04:00
|
|
|
class RendererA(BaseRenderer):
|
|
|
|
media_type = 'mock/renderera'
|
2011-12-29 17:24:52 +04:00
|
|
|
format = "formata"
|
2011-04-29 17:32:56 +04:00
|
|
|
|
2011-05-24 16:29:30 +04:00
|
|
|
def render(self, obj=None, media_type=None):
|
2011-05-10 15:21:48 +04:00
|
|
|
return RENDERER_A_SERIALIZER(obj)
|
2011-04-29 17:32:56 +04:00
|
|
|
|
2011-12-29 17:24:52 +04:00
|
|
|
|
2011-04-29 17:32:56 +04:00
|
|
|
class RendererB(BaseRenderer):
|
|
|
|
media_type = 'mock/rendererb'
|
2011-12-29 17:24:52 +04:00
|
|
|
format = "formatb"
|
2011-04-29 17:32:56 +04:00
|
|
|
|
2011-05-24 16:29:30 +04:00
|
|
|
def render(self, obj=None, media_type=None):
|
2011-05-10 15:21:48 +04:00
|
|
|
return RENDERER_B_SERIALIZER(obj)
|
2011-04-29 17:32:56 +04:00
|
|
|
|
2011-12-29 17:24:52 +04:00
|
|
|
|
2011-05-24 16:29:30 +04:00
|
|
|
class MockView(ResponseMixin, DjangoView):
|
|
|
|
renderers = (RendererA, RendererB)
|
|
|
|
|
2011-06-26 18:03:36 +04:00
|
|
|
def get(self, request, **kwargs):
|
2011-05-24 16:29:30 +04:00
|
|
|
response = Response(DUMMYSTATUS, DUMMYCONTENT)
|
|
|
|
return self.render(response)
|
2011-12-29 17:24:52 +04:00
|
|
|
|
|
|
|
|
|
|
|
class MockGETView(View):
|
2012-01-11 13:27:14 +04:00
|
|
|
|
2011-12-29 17:24:52 +04:00
|
|
|
def get(self, request, **kwargs):
|
|
|
|
return {'foo': ['bar', 'baz']}
|
|
|
|
|
2011-04-29 17:32:56 +04:00
|
|
|
|
2012-01-11 13:27:14 +04:00
|
|
|
class HTMLView(View):
|
|
|
|
renderers = (DocumentingHTMLRenderer, )
|
|
|
|
|
|
|
|
def get(self, request, **kwargs):
|
|
|
|
return 'text'
|
|
|
|
|
2012-01-14 00:57:49 +04:00
|
|
|
|
2012-01-11 13:27:14 +04:00
|
|
|
class HTMLView1(View):
|
|
|
|
renderers = (DocumentingHTMLRenderer, JSONRenderer)
|
|
|
|
|
|
|
|
def get(self, request, **kwargs):
|
|
|
|
return 'text'
|
|
|
|
|
2011-04-29 17:32:56 +04:00
|
|
|
urlpatterns = patterns('',
|
2011-06-26 18:03:36 +04:00
|
|
|
url(r'^.*\.(?P<format>.+)$', MockView.as_view(renderers=[RendererA, RendererB])),
|
2011-04-29 17:32:56 +04:00
|
|
|
url(r'^$', MockView.as_view(renderers=[RendererA, RendererB])),
|
2011-12-29 17:24:52 +04:00
|
|
|
url(r'^jsonp/jsonrenderer$', MockGETView.as_view(renderers=[JSONRenderer, JSONPRenderer])),
|
|
|
|
url(r'^jsonp/nojsonrenderer$', MockGETView.as_view(renderers=[JSONPRenderer])),
|
2012-01-11 13:27:14 +04:00
|
|
|
url(r'^html$', HTMLView.as_view()),
|
|
|
|
url(r'^html1$', HTMLView1.as_view()),
|
2011-04-29 17:32:56 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class RendererIntegrationTests(TestCase):
|
2011-05-10 15:21:48 +04:00
|
|
|
"""
|
|
|
|
End-to-end testing of renderers using an RendererMixin on a generic view.
|
|
|
|
"""
|
2011-04-29 17:32:56 +04:00
|
|
|
|
|
|
|
urls = 'djangorestframework.tests.renderers'
|
|
|
|
|
|
|
|
def test_default_renderer_serializes_content(self):
|
|
|
|
"""If the Accept header is not set the default renderer should serialize the response."""
|
|
|
|
resp = self.client.get('/')
|
|
|
|
self.assertEquals(resp['Content-Type'], RendererA.media_type)
|
|
|
|
self.assertEquals(resp.content, RENDERER_A_SERIALIZER(DUMMYCONTENT))
|
|
|
|
self.assertEquals(resp.status_code, DUMMYSTATUS)
|
|
|
|
|
2011-06-25 14:35:17 +04:00
|
|
|
def test_head_method_serializes_no_content(self):
|
|
|
|
"""No response must be included in HEAD requests."""
|
|
|
|
resp = self.client.head('/')
|
|
|
|
self.assertEquals(resp.status_code, DUMMYSTATUS)
|
|
|
|
self.assertEquals(resp['Content-Type'], RendererA.media_type)
|
|
|
|
self.assertEquals(resp.content, '')
|
|
|
|
|
2011-04-29 17:32:56 +04:00
|
|
|
def test_default_renderer_serializes_content_on_accept_any(self):
|
|
|
|
"""If the Accept header is set to */* the default renderer should serialize the response."""
|
|
|
|
resp = self.client.get('/', HTTP_ACCEPT='*/*')
|
|
|
|
self.assertEquals(resp['Content-Type'], RendererA.media_type)
|
|
|
|
self.assertEquals(resp.content, RENDERER_A_SERIALIZER(DUMMYCONTENT))
|
|
|
|
self.assertEquals(resp.status_code, DUMMYSTATUS)
|
|
|
|
|
|
|
|
def test_specified_renderer_serializes_content_default_case(self):
|
|
|
|
"""If the Accept header is set the specified renderer should serialize the response.
|
|
|
|
(In this case we check that works for the default renderer)"""
|
|
|
|
resp = self.client.get('/', HTTP_ACCEPT=RendererA.media_type)
|
|
|
|
self.assertEquals(resp['Content-Type'], RendererA.media_type)
|
|
|
|
self.assertEquals(resp.content, RENDERER_A_SERIALIZER(DUMMYCONTENT))
|
|
|
|
self.assertEquals(resp.status_code, DUMMYSTATUS)
|
|
|
|
|
|
|
|
def test_specified_renderer_serializes_content_non_default_case(self):
|
|
|
|
"""If the Accept header is set the specified renderer should serialize the response.
|
|
|
|
(In this case we check that works for a non-default renderer)"""
|
|
|
|
resp = self.client.get('/', HTTP_ACCEPT=RendererB.media_type)
|
|
|
|
self.assertEquals(resp['Content-Type'], RendererB.media_type)
|
|
|
|
self.assertEquals(resp.content, RENDERER_B_SERIALIZER(DUMMYCONTENT))
|
|
|
|
self.assertEquals(resp.status_code, DUMMYSTATUS)
|
2011-12-29 17:24:52 +04:00
|
|
|
|
2011-06-26 18:03:36 +04:00
|
|
|
def test_specified_renderer_serializes_content_on_accept_query(self):
|
|
|
|
"""The '_accept' query string should behave in the same way as the Accept header."""
|
|
|
|
resp = self.client.get('/?_accept=%s' % RendererB.media_type)
|
|
|
|
self.assertEquals(resp['Content-Type'], RendererB.media_type)
|
|
|
|
self.assertEquals(resp.content, RENDERER_B_SERIALIZER(DUMMYCONTENT))
|
|
|
|
self.assertEquals(resp.status_code, DUMMYSTATUS)
|
|
|
|
|
2011-04-29 17:32:56 +04:00
|
|
|
def test_unsatisfiable_accept_header_on_request_returns_406_status(self):
|
|
|
|
"""If the Accept header is unsatisfiable we should return a 406 Not Acceptable response."""
|
|
|
|
resp = self.client.get('/', HTTP_ACCEPT='foo/bar')
|
2011-06-26 18:03:36 +04:00
|
|
|
self.assertEquals(resp.status_code, status.HTTP_406_NOT_ACCEPTABLE)
|
|
|
|
|
|
|
|
def test_specified_renderer_serializes_content_on_format_query(self):
|
|
|
|
"""If a 'format' query is specified, the renderer with the matching
|
|
|
|
format attribute should serialize the response."""
|
|
|
|
resp = self.client.get('/?format=%s' % RendererB.format)
|
|
|
|
self.assertEquals(resp['Content-Type'], RendererB.media_type)
|
|
|
|
self.assertEquals(resp.content, RENDERER_B_SERIALIZER(DUMMYCONTENT))
|
|
|
|
self.assertEquals(resp.status_code, DUMMYSTATUS)
|
|
|
|
|
|
|
|
def test_specified_renderer_serializes_content_on_format_kwargs(self):
|
|
|
|
"""If a 'format' keyword arg is specified, the renderer with the matching
|
|
|
|
format attribute should serialize the response."""
|
|
|
|
resp = self.client.get('/something.formatb')
|
|
|
|
self.assertEquals(resp['Content-Type'], RendererB.media_type)
|
|
|
|
self.assertEquals(resp.content, RENDERER_B_SERIALIZER(DUMMYCONTENT))
|
|
|
|
self.assertEquals(resp.status_code, DUMMYSTATUS)
|
|
|
|
|
|
|
|
def test_specified_renderer_is_used_on_format_query_with_matching_accept(self):
|
|
|
|
"""If both a 'format' query and a matching Accept header specified,
|
|
|
|
the renderer with the matching format attribute should serialize the response."""
|
|
|
|
resp = self.client.get('/?format=%s' % RendererB.format,
|
|
|
|
HTTP_ACCEPT=RendererB.media_type)
|
|
|
|
self.assertEquals(resp['Content-Type'], RendererB.media_type)
|
|
|
|
self.assertEquals(resp.content, RENDERER_B_SERIALIZER(DUMMYCONTENT))
|
|
|
|
self.assertEquals(resp.status_code, DUMMYSTATUS)
|
|
|
|
|
|
|
|
def test_conflicting_format_query_and_accept_ignores_accept(self):
|
|
|
|
"""If a 'format' query is specified that does not match the Accept
|
|
|
|
header, we should only honor the 'format' query string."""
|
|
|
|
resp = self.client.get('/?format=%s' % RendererB.format,
|
|
|
|
HTTP_ACCEPT='dummy')
|
|
|
|
self.assertEquals(resp['Content-Type'], RendererB.media_type)
|
|
|
|
self.assertEquals(resp.content, RENDERER_B_SERIALIZER(DUMMYCONTENT))
|
|
|
|
self.assertEquals(resp.status_code, DUMMYSTATUS)
|
|
|
|
|
|
|
|
def test_bla(self):
|
|
|
|
resp = self.client.get('/?format=formatb',
|
|
|
|
HTTP_ACCEPT='text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')
|
|
|
|
self.assertEquals(resp['Content-Type'], RendererB.media_type)
|
|
|
|
self.assertEquals(resp.content, RENDERER_B_SERIALIZER(DUMMYCONTENT))
|
|
|
|
self.assertEquals(resp.status_code, DUMMYSTATUS)
|
2011-05-10 15:21:48 +04:00
|
|
|
|
|
|
|
_flat_repr = '{"foo": ["bar", "baz"]}'
|
2012-01-23 22:18:38 +04:00
|
|
|
_indented_repr = '{\n "foo": [\n "bar",\n "baz"\n ]\n}'
|
2011-05-10 15:21:48 +04:00
|
|
|
|
|
|
|
|
|
|
|
class JSONRendererTests(TestCase):
|
|
|
|
"""
|
|
|
|
Tests specific to the JSON Renderer
|
|
|
|
"""
|
2011-06-15 19:25:59 +04:00
|
|
|
|
2011-05-10 15:21:48 +04:00
|
|
|
def test_without_content_type_args(self):
|
2011-06-15 19:25:59 +04:00
|
|
|
"""
|
|
|
|
Test basic JSON rendering.
|
|
|
|
"""
|
2011-12-29 17:24:52 +04:00
|
|
|
obj = {'foo': ['bar', 'baz']}
|
2011-05-10 15:21:48 +04:00
|
|
|
renderer = JSONRenderer(None)
|
|
|
|
content = renderer.render(obj, 'application/json')
|
2012-01-24 23:36:34 +04:00
|
|
|
# Fix failing test case which depends on version of JSON library.
|
|
|
|
content = re.sub(' +\n', '\n', content)
|
2011-05-10 15:21:48 +04:00
|
|
|
self.assertEquals(content, _flat_repr)
|
|
|
|
|
|
|
|
def test_with_content_type_args(self):
|
2011-06-15 19:25:59 +04:00
|
|
|
"""
|
2011-12-29 17:24:52 +04:00
|
|
|
Test JSON rendering with additional content type arguments supplied.
|
2011-06-15 19:25:59 +04:00
|
|
|
"""
|
2011-12-29 17:24:52 +04:00
|
|
|
obj = {'foo': ['bar', 'baz']}
|
2011-05-10 15:21:48 +04:00
|
|
|
renderer = JSONRenderer(None)
|
|
|
|
content = renderer.render(obj, 'application/json; indent=2')
|
|
|
|
self.assertEquals(content, _indented_repr)
|
2011-12-29 17:24:52 +04:00
|
|
|
|
2011-06-15 19:25:59 +04:00
|
|
|
def test_render_and_parse(self):
|
|
|
|
"""
|
|
|
|
Test rendering and then parsing returns the original object.
|
|
|
|
IE obj -> render -> parse -> obj.
|
|
|
|
"""
|
2011-12-29 17:24:52 +04:00
|
|
|
obj = {'foo': ['bar', 'baz']}
|
2011-06-15 19:25:59 +04:00
|
|
|
|
|
|
|
renderer = JSONRenderer(None)
|
|
|
|
parser = JSONParser(None)
|
|
|
|
|
|
|
|
content = renderer.render(obj, 'application/json')
|
|
|
|
(data, files) = parser.parse(StringIO(content))
|
2011-12-29 17:24:52 +04:00
|
|
|
self.assertEquals(obj, data)
|
|
|
|
|
|
|
|
|
|
|
|
class JSONPRendererTests(TestCase):
|
|
|
|
"""
|
|
|
|
Tests specific to the JSONP Renderer
|
|
|
|
"""
|
|
|
|
|
|
|
|
urls = 'djangorestframework.tests.renderers'
|
|
|
|
|
|
|
|
def test_without_callback_with_json_renderer(self):
|
|
|
|
"""
|
|
|
|
Test JSONP rendering with View JSON Renderer.
|
|
|
|
"""
|
|
|
|
resp = self.client.get('/jsonp/jsonrenderer',
|
|
|
|
HTTP_ACCEPT='application/json-p')
|
|
|
|
self.assertEquals(resp.status_code, 200)
|
|
|
|
self.assertEquals(resp['Content-Type'], 'application/json-p')
|
|
|
|
self.assertEquals(resp.content, 'callback(%s);' % _flat_repr)
|
2011-07-01 20:44:08 +04:00
|
|
|
|
2011-12-29 17:24:52 +04:00
|
|
|
def test_without_callback_without_json_renderer(self):
|
|
|
|
"""
|
|
|
|
Test JSONP rendering without View JSON Renderer.
|
|
|
|
"""
|
|
|
|
resp = self.client.get('/jsonp/nojsonrenderer',
|
|
|
|
HTTP_ACCEPT='application/json-p')
|
|
|
|
self.assertEquals(resp.status_code, 200)
|
|
|
|
self.assertEquals(resp['Content-Type'], 'application/json-p')
|
|
|
|
self.assertEquals(resp.content, 'callback(%s);' % _flat_repr)
|
|
|
|
|
|
|
|
def test_with_callback(self):
|
|
|
|
"""
|
|
|
|
Test JSONP rendering with callback function name.
|
|
|
|
"""
|
|
|
|
callback_func = 'myjsonpcallback'
|
|
|
|
resp = self.client.get('/jsonp/nojsonrenderer?callback=' + callback_func,
|
|
|
|
HTTP_ACCEPT='application/json-p')
|
|
|
|
self.assertEquals(resp.status_code, 200)
|
|
|
|
self.assertEquals(resp['Content-Type'], 'application/json-p')
|
|
|
|
self.assertEquals(resp.content, '%s(%s);' % (callback_func, _flat_repr))
|
2011-07-01 20:44:08 +04:00
|
|
|
|
|
|
|
|
|
|
|
if YAMLRenderer:
|
|
|
|
_yaml_repr = 'foo: [bar, baz]\n'
|
2011-12-29 17:24:52 +04:00
|
|
|
|
2011-07-01 20:44:08 +04:00
|
|
|
class YAMLRendererTests(TestCase):
|
|
|
|
"""
|
|
|
|
Tests specific to the JSON Renderer
|
|
|
|
"""
|
2011-12-29 17:24:52 +04:00
|
|
|
|
2011-07-01 20:44:08 +04:00
|
|
|
def test_render(self):
|
|
|
|
"""
|
|
|
|
Test basic YAML rendering.
|
|
|
|
"""
|
2011-12-29 17:24:52 +04:00
|
|
|
obj = {'foo': ['bar', 'baz']}
|
2011-07-01 20:44:08 +04:00
|
|
|
renderer = YAMLRenderer(None)
|
|
|
|
content = renderer.render(obj, 'application/yaml')
|
|
|
|
self.assertEquals(content, _yaml_repr)
|
2011-12-29 17:24:52 +04:00
|
|
|
|
2011-07-01 20:44:08 +04:00
|
|
|
def test_render_and_parse(self):
|
|
|
|
"""
|
|
|
|
Test rendering and then parsing returns the original object.
|
|
|
|
IE obj -> render -> parse -> obj.
|
|
|
|
"""
|
2011-12-29 17:24:52 +04:00
|
|
|
obj = {'foo': ['bar', 'baz']}
|
|
|
|
|
2011-07-01 20:44:08 +04:00
|
|
|
renderer = YAMLRenderer(None)
|
|
|
|
parser = YAMLParser(None)
|
2011-12-29 17:24:52 +04:00
|
|
|
|
2011-07-01 20:44:08 +04:00
|
|
|
content = renderer.render(obj, 'application/yaml')
|
|
|
|
(data, files) = parser.parse(StringIO(content))
|
2011-12-29 17:24:52 +04:00
|
|
|
self.assertEquals(obj, data)
|
2011-12-11 22:27:40 +04:00
|
|
|
|
2011-12-11 22:30:43 +04:00
|
|
|
|
2012-01-11 13:27:14 +04:00
|
|
|
|
|
|
|
class XMLRendererTestCase(TestCase):
|
|
|
|
"""
|
|
|
|
Tests specific to the XML Renderer
|
|
|
|
"""
|
|
|
|
|
2012-01-13 13:11:34 +04:00
|
|
|
_complex_data = {
|
|
|
|
"creation_date": datetime.datetime(2011, 12, 25, 12, 45, 00),
|
|
|
|
"name": "name",
|
|
|
|
"sub_data_list": [
|
|
|
|
{
|
|
|
|
"sub_id": 1,
|
|
|
|
"sub_name": "first"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"sub_id": 2,
|
|
|
|
"sub_name": "second"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2012-01-11 13:27:14 +04:00
|
|
|
def test_render_string(self):
|
|
|
|
"""
|
|
|
|
Test XML rendering.
|
|
|
|
"""
|
|
|
|
renderer = XMLRenderer(None)
|
|
|
|
content = renderer.render({'field': 'astring'}, 'application/xml')
|
|
|
|
self.assertXMLContains(content, '<field>astring</field>')
|
|
|
|
|
|
|
|
def test_render_integer(self):
|
|
|
|
"""
|
|
|
|
Test XML rendering.
|
|
|
|
"""
|
|
|
|
renderer = XMLRenderer(None)
|
|
|
|
content = renderer.render({'field': 111}, 'application/xml')
|
|
|
|
self.assertXMLContains(content, '<field>111</field>')
|
|
|
|
|
|
|
|
def test_render_datetime(self):
|
|
|
|
"""
|
|
|
|
Test XML rendering.
|
|
|
|
"""
|
|
|
|
renderer = XMLRenderer(None)
|
|
|
|
content = renderer.render({
|
|
|
|
'field': datetime.datetime(2011, 12, 25, 12, 45, 00)
|
|
|
|
}, 'application/xml')
|
|
|
|
self.assertXMLContains(content, '<field>2011-12-25 12:45:00</field>')
|
|
|
|
|
|
|
|
def test_render_float(self):
|
|
|
|
"""
|
|
|
|
Test XML rendering.
|
|
|
|
"""
|
|
|
|
renderer = XMLRenderer(None)
|
|
|
|
content = renderer.render({'field': 123.4}, 'application/xml')
|
|
|
|
self.assertXMLContains(content, '<field>123.4</field>')
|
|
|
|
|
|
|
|
def test_render_decimal(self):
|
|
|
|
"""
|
|
|
|
Test XML rendering.
|
|
|
|
"""
|
|
|
|
renderer = XMLRenderer(None)
|
|
|
|
content = renderer.render({'field': Decimal('111.2')}, 'application/xml')
|
|
|
|
self.assertXMLContains(content, '<field>111.2</field>')
|
|
|
|
|
|
|
|
def test_render_none(self):
|
|
|
|
"""
|
|
|
|
Test XML rendering.
|
|
|
|
"""
|
|
|
|
renderer = XMLRenderer(None)
|
|
|
|
content = renderer.render({'field': None}, 'application/xml')
|
|
|
|
self.assertXMLContains(content, '<field></field>')
|
2012-01-13 13:11:34 +04:00
|
|
|
|
|
|
|
def test_render_complex_data(self):
|
|
|
|
"""
|
|
|
|
Test XML rendering.
|
|
|
|
"""
|
|
|
|
renderer = XMLRenderer(None)
|
|
|
|
content = renderer.render(self._complex_data, 'application/xml')
|
|
|
|
self.assertXMLContains(content, '<sub_name>first</sub_name>')
|
|
|
|
self.assertXMLContains(content, '<sub_name>second</sub_name>')
|
2012-01-11 13:27:14 +04:00
|
|
|
|
2012-01-12 21:04:18 +04:00
|
|
|
def test_render_and_parse_complex_data(self):
|
|
|
|
"""
|
|
|
|
Test XML rendering.
|
|
|
|
"""
|
2012-01-13 13:11:34 +04:00
|
|
|
renderer = XMLRenderer(None)
|
|
|
|
content = StringIO(renderer.render(self._complex_data, 'application/xml'))
|
2012-01-12 21:04:18 +04:00
|
|
|
|
|
|
|
parser = XMLParser(None)
|
|
|
|
complex_data_out, dummy = parser.parse(content)
|
2012-01-13 13:11:34 +04:00
|
|
|
error_msg = "complex data differs!IN:\n %s \n\n OUT:\n %s" % (repr(self._complex_data), repr(complex_data_out))
|
2012-01-14 02:01:16 +04:00
|
|
|
self.assertEqual(self._complex_data, complex_data_out, error_msg)
|
2012-01-12 21:04:18 +04:00
|
|
|
|
2012-01-11 13:27:14 +04:00
|
|
|
def assertXMLContains(self, xml, string):
|
|
|
|
self.assertTrue(xml.startswith('<?xml version="1.0" encoding="utf-8"?>\n<root>'))
|
|
|
|
self.assertTrue(xml.endswith('</root>'))
|
2012-01-14 00:57:49 +04:00
|
|
|
self.assertTrue(string in xml, '%r not in %r' % (string, xml))
|
|
|
|
|
|
|
|
|
|
|
|
class Issue122Tests(TestCase):
|
|
|
|
"""
|
|
|
|
Tests that covers #122.
|
|
|
|
"""
|
|
|
|
urls = 'djangorestframework.tests.renderers'
|
|
|
|
|
|
|
|
def test_only_html_renderer(self):
|
|
|
|
"""
|
|
|
|
Test if no infinite recursion occurs.
|
|
|
|
"""
|
|
|
|
resp = self.client.get('/html')
|
|
|
|
|
|
|
|
def test_html_renderer_is_first(self):
|
|
|
|
"""
|
|
|
|
Test if no infinite recursion occurs.
|
|
|
|
"""
|
|
|
|
resp = self.client.get('/html1')
|