From 1bec6f2d5ed3d27b39ef543e0e4afb23678cfe4b Mon Sep 17 00:00:00 2001 From: Michele Lazzeri Date: Thu, 12 Jan 2012 18:04:18 +0100 Subject: [PATCH] add testcate XMLRendererTestCase.test_render_and_parse_complex_data --- djangorestframework/tests/renderers.py | 29 +++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/djangorestframework/tests/renderers.py b/djangorestframework/tests/renderers.py index e80f0f20a..d000df27f 100644 --- a/djangorestframework/tests/renderers.py +++ b/djangorestframework/tests/renderers.py @@ -6,7 +6,7 @@ from djangorestframework.views import View from djangorestframework.compat import View as DjangoView from djangorestframework.renderers import BaseRenderer, JSONRenderer, YAMLRenderer, \ XMLRenderer, JSONPRenderer, DocumentingHTMLRenderer -from djangorestframework.parsers import JSONParser, YAMLParser +from djangorestframework.parsers import JSONParser, YAMLParser, XMLParser from djangorestframework.mixins import ResponseMixin from djangorestframework.response import Response @@ -479,6 +479,33 @@ class XMLRendererTestCase(TestCase): content = renderer.render({'field': None}, 'application/xml') self.assertXMLContains(content, '') + def test_render_and_parse_complex_data(self): + """ + Test XML rendering. + """ + renderer = XMLRenderer(None) + complex_data_in = { + "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" + } + ] + } + + content = StringIO(renderer.render(complex_data_in, 'application/xml')) + + parser = XMLParser(None) + complex_data_out, dummy = parser.parse(content) + error_msg = "complex data differs!IN:\n %s \n\n OUT:\n %s" % (repr(complex_data_in), repr(complex_data_out)) + self.assertDictEqual(complex_data_in, complex_data_out, error_msg) + def assertXMLContains(self, xml, string): self.assertTrue(xml.startswith('\n')) self.assertTrue(xml.endswith(''))