Esempio n. 1
0
 def test_render_string(self):
     """
     Test XML rendering.
     """
     renderer = XMLRenderer()
     content = renderer.render({'field': 'astring'}, 'application/xml')
     self.assertXMLContains(content, '<field>astring</field>')
Esempio n. 2
0
    def render(self, data, accepted_media_type=None, renderer_context=None):
        """
        First renders `data` into serialized XML, afterwards start fop and return PDF
        """
        if data is None:
            return ''

        super(XSLFORenderer, self).render(data, accepted_media_type, renderer_context)

        xml_renderer = XMLRenderer()
        xml_string = xml_renderer.render(data, accepted_media_type, renderer_context)
        xml_file = open(renderer_context['view'].file_name, "wb+")
        xml_file.truncate()
        xml_file.write(xml_string.encode('utf-8'))
        xml_file.close()
        # perform xsl transformation
        self.perform_xsl_transformation(xml_file,
                                        self.xsl_file,
                                        self.fop_config_file,
                                        self.file_output_pdf)

        # Read file
        with open(self.file_output_pdf, 'rb') as f:
            rendered_output = f.read()

        return rendered_output
Esempio n. 3
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>')
 def test_render_none(self):
     """
     Test XML rendering.
     """
     renderer = XMLRenderer()
     content = renderer.render({"field": None}, "application/xml")
     self.assertXMLContains(content, "<field></field>")
Esempio n. 5
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>')
 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_string(self):
     """
     Test XML rendering.
     """
     renderer = XMLRenderer()
     content = renderer.render({"field": "astring"}, "application/xml")
     self.assertXMLContains(content, "<field>astring</field>")
Esempio n. 8
0
 def test_render_none(self):
     """
     Test XML rendering.
     """
     renderer = XMLRenderer()
     content = renderer.render({'field': None}, 'application/xml')
     self.assertXMLContains(content, '<field></field>')
Esempio n. 9
0
    def render(self, data, accepted_media_type=None, renderer_context=None):
        """
        First renders `data` into serialized XML, afterwards start fop and return PDF
        """
        if data is None:
            return ''

        super(XSLFORenderer, self).render(data, accepted_media_type,
                                          renderer_context)

        xml_renderer = XMLRenderer()
        xml_string = xml_renderer.render(data, accepted_media_type,
                                         renderer_context)
        xml_file = open(renderer_context['view'].file_name, "wb+")
        xml_file.truncate()
        xml_file.write(xml_string.encode('utf-8'))
        xml_file.close()
        # perform xsl transformation
        self.perform_xsl_transformation(xml_file, self.xsl_file,
                                        self.fop_config_file,
                                        self.file_output_pdf)

        # Read file
        with open(self.file_output_pdf, 'rb') as f:
            rendered_output = f.read()

        return rendered_output
Esempio n. 10
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_decimal(self):
     """
     Test XML rendering.
     """
     renderer = XMLRenderer()
     content = renderer.render(
         {"field": Decimal("111.2")}, "application/xml"
     )
     self.assertXMLContains(content, "<field>111.2</field>")
Esempio n. 12
0
 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>')
Esempio n. 13
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)
 def test_render_lazy(self):
     renderer = XMLRenderer()
     lazy = gettext_lazy("hello")
     content = renderer.render({"field": lazy}, "application/xml")
     self.assertXMLContains(content, "<field>hello</field>")
 def test_render_lazy(self):
     renderer = XMLRenderer()
     lazy = gettext_lazy('hello')
     content = renderer.render({'field': lazy}, 'application/xml')
     self.assertXMLContains(content, '<field>hello</field>')
 def test_render_list(self):
     renderer = XMLRenderer()
     content = renderer.render(self._complex_data, "application/xml")
     self.assertXMLContains(content, "<sub_data_list><list-item>")
     self.assertXMLContains(content, "</list-item></sub_data_list>")
Esempio n. 17
0
 def test_render_lazy(self):
     renderer = XMLRenderer()
     lazy = gettext_lazy('hello')
     content = renderer.render({'field': lazy}, 'application/xml')
     self.assertXMLContains(content, '<field>hello</field>')
 def test_render_list(self):
     renderer = XMLRenderer()
     content = renderer.render(self._complex_data, 'application/xml')
     self.assertXMLContains(content, '<sub_data_list><list-item>')
     self.assertXMLContains(content, '</list-item></sub_data_list>')