def test_render_decimal(self):
     """
     Test XML rendering.
     """
     renderer = XMLRenderer()
     content = renderer.render({'field': Decimal('111.2')}, 'application/xml')
     self.assertXMLContains(content, '<field>111.2</field>')
 def test_render_float(self):
     """
     Test XML rendering.
     """
     renderer = XMLRenderer()
     content = renderer.render({"field": 123.4}, "application/xml")
     self.assertXMLContains(content, "<field>123.4</field>")
 def test_render_none(self):
     """
     Test XML rendering.
     """
     renderer = XMLRenderer()
     content = renderer.render({"field": None}, "application/xml")
     self.assertXMLContains(content, "<field></field>")
 def test_render_string(self):
     """
     Test XML rendering.
     """
     renderer = XMLRenderer()
     content = renderer.render({"field": "astring"}, "application/xml")
     self.assertXMLContains(content, "<field>astring</field>")
Exemplo n.º 5
0
 def test_render_float(self):
     """
     Test XML rendering.
     """
     renderer = XMLRenderer()
     content = renderer.render({'field': 123.4}, 'application/xml')
     self.assertXMLContains(content, '<field>123.4</field>')
Exemplo n.º 6
0
 def test_render_string(self):
     """
     Test XML rendering.
     """
     renderer = XMLRenderer()
     content = renderer.render({'field': 'astring'}, 'application/xml')
     self.assertXMLContains(content, '<field>astring</field>')
Exemplo n.º 7
0
 def test_render_string(self):
     """
     Test XML rendering.
     """
     renderer = XMLRenderer()
     content = renderer.render({'field': 'astring'}, 'application/xml')
     self.assertXMLContains(content, '<field>astring</field>')
Exemplo n.º 8
0
 def test_render_decimal(self):
     """
     Test XML rendering.
     """
     renderer = XMLRenderer()
     content = renderer.render({'field': Decimal('111.2')}, 'application/xml')
     self.assertXMLContains(content, '<field>111.2</field>')
Exemplo n.º 9
0
 def test_render_none(self):
     """
     Test XML rendering.
     """
     renderer = XMLRenderer()
     content = renderer.render({'field': None}, 'application/xml')
     self.assertXMLContains(content, '<field></field>')
 def test_render_none(self):
     """
     Test XML rendering.
     """
     renderer = XMLRenderer()
     content = renderer.render({'field': None}, 'application/xml')
     self.assertXMLContains(content, '<field></field>')
 def test_render_float(self):
     """
     Test XML rendering.
     """
     renderer = XMLRenderer()
     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()
     content = renderer.render({"field": Decimal("111.2")}, "application/xml")
     self.assertXMLContains(content, "<field>111.2</field>")
 def test_render_datetime(self):
     """
     Test XML rendering.
     """
     renderer = XMLRenderer()
     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_complex_data(self):
     """
     Test XML rendering.
     """
     renderer = XMLRenderer()
     content = renderer.render(self._complex_data, 'application/xml')
     self.assertXMLContains(content, '<sub_name>first</sub_name>')
     self.assertXMLContains(content, '<sub_name>second</sub_name>')
Exemplo n.º 15
0
 def test_render_complex_data(self):
     """
     Test XML rendering.
     """
     renderer = XMLRenderer()
     content = renderer.render(self._complex_data, 'application/xml')
     self.assertXMLContains(content, '<sub_name>first</sub_name>')
     self.assertXMLContains(content, '<sub_name>second</sub_name>')
 def test_render_datetime(self):
     """
     Test XML rendering.
     """
     renderer = XMLRenderer()
     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>')
Exemplo n.º 17
0
    def test_render_and_parse_complex_data(self):
        """
        Test XML rendering.
        """
        renderer = XMLRenderer()
        content = StringIO(renderer.render(self._complex_data, 'application/xml'))

        parser = XMLParser()
        complex_data_out = parser.parse(content)
        error_msg = "complex data differs!IN:\n %s \n\n OUT:\n %s" % (repr(self._complex_data), repr(complex_data_out))
        self.assertEqual(self._complex_data, complex_data_out, error_msg)
Exemplo n.º 18
0
    def test_render_and_parse_complex_data(self):
        """
        Test XML rendering.
        """
        renderer = XMLRenderer()
        content = StringIO(renderer.render(self._complex_data, 'application/xml'))

        parser = XMLParser()
        complex_data_out = parser.parse(content)
        error_msg = "complex data differs!IN:\n %s \n\n OUT:\n %s" % (repr(self._complex_data), repr(complex_data_out))
        self.assertEqual(self._complex_data, complex_data_out, error_msg)
Exemplo n.º 19
0
    def render(self, data, accepted_media_type=None, renderer_context=None):
        renderer_context = renderer_context or {}
        response = renderer_context['response']

        if response and response.exception:
            return XMLRenderer().render(data, accepted_media_type,
                                        renderer_context)

        return super(TemplateXMLRenderer,
                     self).render(data, accepted_media_type, renderer_context)
Exemplo n.º 20
0
 def get_renderer(self):
     """
     Cf from rest_framework.renderers import JSONRenderer
     """
     if ROA_FORMAT == 'json':
         return JSONRenderer()
     elif ROA_FORMAT == 'xml':
         return XMLRenderer()
     elif ROAException == 'yaml':
         return YAMLRenderer()
     else:
         raise NotImplementedError
Exemplo n.º 21
0
class XMLResponse(APIResponse):
    """
    A HttpResponse that renders its content into XML.
    """
    content_type = "application/xml"
    renderer = XMLRenderer()
Exemplo n.º 22
0
 def get_renderers(self):
     output = self.request.REQUEST.get('output', 'json')
     if output == 'xml':
         return [XMLRenderer()]
     return super(MultiRenderersAPIView, self).get_renderers()
Exemplo n.º 23
0
 def __init__(self, data, **kwargs):
     content = XMLRenderer().render(data)
     kwargs['content_type'] = 'application/xml'
     super(XMLResponse, self).__init__(content, **kwargs)