def test_render_empty_table(self): """ An empty table should render okay. """ block = TableBlock() result = block.render(self.default_value) self.assertHTMLEqual(result, self.default_expected)
def test_row_and_column_headers(self): """ Test row and column headers at the same time. """ value = {'first_row_is_table_header': True, 'first_col_is_header': True, 'data': [['Foo', 'Bar', 'Baz'], ['one', 'two', 'three'], ['four', 'five', 'six']]} expected = get_test_html_from_value(value) block = TableBlock() result = block.render(value) self.assertHTMLEqual(result, expected)
def test_column_headers(self): """ Ensure that column headers are properly rendered. """ value = {'first_row_is_table_header': False, 'first_col_is_header': True, 'data': [['Foo', 'Bar', 'Baz'], ['one', 'two', 'three'], ['four', 'five', 'six']]} expected = get_test_html_from_value(value) block = TableBlock() result = block.render(value) self.assertHTMLEqual(result, expected)
def test_table_block_render(self): """ Test a generic render. """ value = {'first_row_is_table_header': False, 'first_col_is_header': False, 'data': [['Test 1', 'Test 2', 'Test 3'], [None, None, None], [None, None, None]]} block = TableBlock() result = block.render(value) expected = get_test_html_from_value(value) self.assertHTMLEqual(result, expected) self.assertIn('Test 2', result)
def test_value_for_and_from_form(self): """ Make sure we get back good json and make sure it translates back to python. """ value = {'first_row_is_table_header': False, 'first_col_is_header': False, 'data': [['Foo', 1, None], [3.5, 'Bar', 'Baz']]} block = TableBlock() expected_json = '{"first_row_is_table_header": false, "first_col_is_header": false, "data": [["Foo", 1, null], [3.5, "Bar", "Baz"]]}' returned_json = block.value_for_form(value) self.assertJSONEqual(expected_json, returned_json) self.assertEqual(block.value_from_form(returned_json), value)
def test_do_not_render_html(self): """ Ensure that raw html doesn't render by default. """ value = {'first_row_is_table_header': False, 'first_col_is_header': False, 'data': [['<p><strong>Test</strong></p>', None, None], [None, None, None], [None, None, None]]} expected = get_test_html_from_value(value) block = TableBlock() result = block.render(value) self.assertHTMLEqual(result, expected)
def test_is_html_renderer(self): """ Test that settings flow through correctly to the is_html_renderer method. """ # TableBlock with default table_options block1 = TableBlock() self.assertEqual(block1.is_html_renderer(), False) # TableBlock with altered table_options new_options = self.default_table_options.copy() new_options['renderer'] = 'html' block2 = TableBlock(table_options=new_options) self.assertEqual(block2.is_html_renderer(), True)