Example #1
0
    def test_export_to_html_filename(self):
        # TODO: may test file contents
        temp = tempfile.NamedTemporaryFile(delete=False)
        self.files_to_delete.append(temp.name)
        rows.export_to_html(utils.table, temp.name)

        table = rows.import_from_html(temp.name)
        self.assert_table_equal(table, utils.table)
Example #2
0
    def test_export_to_html_filename(self):
        # TODO: may test file contents
        temp = tempfile.NamedTemporaryFile(delete=False)
        self.files_to_delete.append(temp.name)
        rows.export_to_html(utils.table, temp.name)

        table = rows.import_from_html(temp.name)
        self.assert_table_equal(table, utils.table)
Example #3
0
 def test_export_to_html_none(self):
     # TODO: may test with codecs.open passing an encoding
     # TODO: may test file contents
     temp = tempfile.NamedTemporaryFile(delete=False)
     self.files_to_delete.append(temp.name)
     result = rows.export_to_html(utils.table)
     rows.export_to_html(utils.table, temp.file)
     temp.file.seek(0)
     self.assertEqual(temp.file.read(), result)
Example #4
0
 def test_export_to_html_none(self):
     # TODO: may test with codecs.open passing an encoding
     # TODO: may test file contents
     temp = tempfile.NamedTemporaryFile(delete=False, mode="rb+")
     self.files_to_delete.append(temp.name)
     result = rows.export_to_html(utils.table)
     rows.export_to_html(utils.table, temp.file)
     temp.file.seek(0)
     self.assertEqual(temp.file.read(), result)
Example #5
0
    def test_export_to_html_fobj(self):
        # TODO: may test with codecs.open passing an encoding
        # TODO: may test file contents
        temp = tempfile.NamedTemporaryFile(delete=False, mode="wb")
        self.files_to_delete.append(temp.name)
        rows.export_to_html(utils.table, temp.file)

        table = rows.import_from_html(temp.name)
        self.assert_table_equal(table, utils.table)
Example #6
0
    def test_issue_168(self):
        temp = tempfile.NamedTemporaryFile(delete=False)
        filename = "{}.{}".format(temp.name, self.file_extension)
        self.files_to_delete.append(filename)

        table = rows.Table(fields=OrderedDict([("jsoncolumn", rows.fields.JSONField)]))
        table.append({"jsoncolumn": '{"python": 42}'})
        rows.export_to_html(table, filename)

        table2 = rows.import_from_html(filename)
        self.assert_table_equal(table, table2)
Example #7
0
    def test_export_to_html_uses_serialize(self, mocked_serialize):
        temp = tempfile.NamedTemporaryFile(delete=False)
        self.files_to_delete.append(temp.name)
        kwargs = {"test": 123, "parameter": 3.14}
        mocked_serialize.return_value = iter([utils.table.fields.keys()])

        rows.export_to_html(utils.table, temp.name, encoding="utf-8", **kwargs)
        self.assertTrue(mocked_serialize.called)
        self.assertEqual(mocked_serialize.call_count, 1)

        call = mocked_serialize.call_args
        self.assertEqual(call[0], (utils.table,))
        self.assertEqual(call[1], kwargs)
Example #8
0
 def test_export_to_html_unescaped_content(self):
     table = rows.Table(
         fields=OrderedDict([("unescaped_content", rows.fields.TextField)])
     )
     table.append({"unescaped_content": "<&>"})
     output = rows.export_to_html(table)
     self.assertIn(b"<td> &lt;&amp;&gt; </td>", output)
Example #9
0
 def test_export_to_html_unescaped_content(self):
     table = rows.Table(fields=OrderedDict([
         ('unescaped_content', rows.fields.TextField)
     ]))
     table.append({'unescaped_content': '<&>'})
     output = rows.export_to_html(table)
     self.assertIn(b'<td> &lt;&amp;&gt; </td>', output)
 def test_export_to_html_unescaped_content(self):
     table = rows.Table(fields=OrderedDict([
         ('unescaped_content', rows.fields.TextField)
     ]))
     table.append({'unescaped_content': '<&>'})
     output = rows.export_to_html(table)
     self.assertIn(b'<td> &lt;&amp;&gt; </td>', output)
 def __call__(self):
     view = getMultiAdapter((self.context, self.request), name='view')
     table = view.table()
     filename = "%s.html" % view.filename_prefix()
     data = rows.export_to_html(table)
     self.request.response.setHeader('Content-Type', '"%s"' % EXTENSIONS_TYPES.get('html'))
     self.request.response.setHeader('Content-Disposition', 'attachment; filename="%s"' % filename)
     return data
 def html_table(self):
     """Returns the table in Plone HTML format."""
     try:
         table = self.table()
     except:
         return ''
     html = rows.export_to_html(table)
     # Add a class Plone style (sort columns) to the HTML table
     html = html.replace('<table>', '<table class="listing">')
     return html
Example #13
0
    def test_export_to_html_uses_export_data(self, mocked_export_data):
        temp = tempfile.NamedTemporaryFile(delete=False)
        self.files_to_delete.append(temp.name)
        kwargs = {"test": 123, "parameter": 3.14, "encoding": "utf-8"}
        mocked_export_data.return_value = 42

        result = rows.export_to_html(utils.table, temp.name, **kwargs)
        self.assertTrue(mocked_export_data.called)
        self.assertEqual(mocked_export_data.call_count, 1)
        self.assertEqual(result, 42)

        call = mocked_export_data.call_args
        self.assertEqual(call[0][0], temp.name)
        self.assertEqual(call[1], {"mode": "wb"})
Example #14
0
    def test_export_to_html_uses_export_data(self, mocked_export_data):
        temp = tempfile.NamedTemporaryFile(delete=False)
        self.files_to_delete.append(temp.name)
        kwargs = {'test': 123, 'parameter': 3.14, 'encoding': 'utf-8', }
        mocked_export_data.return_value = 42

        result = rows.export_to_html(utils.table, temp.name, **kwargs)
        self.assertTrue(mocked_export_data.called)
        self.assertEqual(mocked_export_data.call_count, 1)
        self.assertEqual(result, 42)

        call = mocked_export_data.call_args
        self.assertEqual(call[0][0], temp.name)
        self.assertEqual(call[1], {'mode': 'wb'})
    def test_export_to_html_uses_export_data(self, mocked_export_data):
        temp = tempfile.NamedTemporaryFile(delete=False)
        self.files_to_delete.append(temp.name)
        kwargs = {'test': 123, 'parameter': 3.14, 'encoding': 'utf-8', }
        mocked_export_data.return_value = 42

        result = rows.export_to_html(utils.table, temp.name, **kwargs)
        self.assertTrue(mocked_export_data.called)
        self.assertEqual(mocked_export_data.call_count, 1)
        self.assertEqual(result, 42)

        call = mocked_export_data.call_args
        self.assertEqual(call[0][0], temp.name)
        self.assertEqual(call[1], {'mode': 'wb'})