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 = """ <table> <tbody> <tr><td>Test 1</td><td>Test 2</td><td>Test 3</td></tr> <tr><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td></tr> </tbody> </table> """ self.assertHTMLEqual(result, expected) self.assertIn('Test 2', result)
def test_table_block_alignment_render(self): """ Test a generic render with some cells aligned. """ value = {'first_row_is_table_header': True, 'first_col_is_header': False, 'cell': [{'row': 0, 'col': 1, 'className': 'htLeft'}, {'row': 1, 'col': 1, 'className': 'htRight'}], 'data': [['Test 1', 'Test 2', 'Test 3'], [None, None, None], [None, None, None]]} block = TableBlock() result = block.render(value) expected = """ <table> <thead> <tr><th>Test 1</th><th class="htLeft">Test 2</th><th>Test 3</th></tr> </thead> <tbody> <tr><td></td><td class="htRight"></td><td></td></tr> <tr><td></td><td></td><td></td></tr> </tbody> </table> """ self.assertHTMLEqual(result, expected) self.assertIn('Test 2', result)
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 = """ <table> <tbody> <tr><td><p><strong>Test</strong></p></td><td></td><td></td></tr> <tr><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td></tr> </tbody> </table> """ block = TableBlock() result = block.render(value) self.assertHTMLEqual(result, expected)
def test_row_headers(self): """ Ensure that row headers are properly rendered. """ value = { "first_row_is_table_header": True, "first_col_is_header": False, "data": [["Foo", "Bar", "Baz"], [None, None, None], [None, None, None]], } expected = """ <table> <thead> <tr><th scope="col">Foo</th><th scope="col">Bar</th><th scope="col">Baz</th></tr> </thead> <tbody> <tr><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td></tr> </tbody> </table> """ block = TableBlock() result = block.render(value) self.assertHTMLEqual(result, 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 = """ <table> <thead> <tr><th scope="col">Foo</th><th scope="col">Bar</th><th scope="col">Baz</th></tr> </thead> <tbody> <tr><th scope="row">one</th><td>two</td><td>three</td></tr> <tr><th scope="row">four</th><td>five</td><td>six</td></tr> </tbody> </table> """ block = TableBlock() result = block.render(value) self.assertHTMLEqual(result, expected)
def test_row_headers(self): """ Ensure that row headers are properly rendered. """ value = { 'first_row_is_table_header': True, 'first_col_is_header': False, 'data': [['Foo', 'Bar', 'Baz'], [None, None, None], [None, None, None]] } expected = """ <table> <thead> <tr><th scope="col">Foo</th><th scope="col">Bar</th><th scope="col">Baz</th></tr> </thead> <tbody> <tr><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td></tr> </tbody> </table> """ 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 = """ <table> <tbody> <tr><th scope="row">Foo</th><td>Bar</td><td>Baz</td></tr> <tr><th scope="row">one</th><td>two</td><td>three</td></tr> <tr><th scope="row">four</th><td>five</td><td>six</td></tr> </tbody> </table> """ block = TableBlock() result = block.render(value) self.assertHTMLEqual(result, expected)
def test_table_block_alignment_render(self): """ Test a generic render with some cells aligned. """ value = { "first_row_is_table_header": True, "first_col_is_header": False, "cell": [ {"row": 0, "col": 1, "className": "htLeft"}, {"row": 1, "col": 1, "className": "htRight"}, ], "data": [ ["Test 1", "Test 2", "Test 3"], [None, None, None], [None, None, None], ], } block = TableBlock() result = block.render(value) expected = """ <table> <thead> <tr><th scope="col">Test 1</th><th scope="col" class="htLeft">Test 2</th><th scope="col">Test 3</th></tr> </thead> <tbody> <tr><td></td><td class="htRight"></td><td></td></tr> <tr><td></td><td></td><td></td></tr> </tbody> </table> """ self.assertHTMLEqual(result, expected) self.assertIn("Test 2", result)
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 = """ <table> <tbody> <tr><th scope="row">Foo</th><td>Bar</td><td>Baz</td></tr> <tr><th scope="row">one</th><td>two</td><td>three</td></tr> <tr><th scope="row">four</th><td>five</td><td>six</td></tr> </tbody> </table> """ block = TableBlock() result = block.render(value) self.assertHTMLEqual(result, expected)
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 = """ <table> <thead> <tr><th scope="col">Foo</th><th scope="col">Bar</th><th scope="col">Baz</th></tr> </thead> <tbody> <tr><th scope="row">one</th><td>two</td><td>three</td></tr> <tr><th scope="row">four</th><td>five</td><td>six</td></tr> </tbody> </table> """ block = TableBlock() result = block.render(value) self.assertHTMLEqual(result, expected)
def test_table_block_caption_render(self): """ Test a generic render with caption. """ value = { "table_caption": "caption", "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 = """ <table> <caption>caption</caption> <tbody> <tr><td>Test 1</td><td>Test 2</td><td>Test 3</td></tr> <tr><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td></tr> </tbody> </table> """ self.assertHTMLEqual(result, expected) self.assertIn("Test 2", result)
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_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_empty_table_block_is_not_rendered(self): """ Test an empty table is not rendered. """ value = None block = TableBlock() result = block.render(value) expected = "" self.assertHTMLEqual(result, expected) self.assertNotIn("None", result)
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_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_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_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_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_render_with_extra_context(self): """ Test that extra context variables passed in block.render are passed through to the template. """ block = TableBlock(template="tests/blocks/table_block_with_caption.html") 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]]} result = block.render(value, context={ 'caption': "A fascinating table." }) self.assertIn("Test 1", result) self.assertIn("<div>A fascinating table.</div>", result)
def test_render_with_extra_context(self): """ Test that extra context variables passed in block.render are passed through to the template. """ block = TableBlock(template="tests/blocks/table_block_with_caption.html") 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]]} result = block.render(value, context={ 'caption': "A fascinating table." }) self.assertIn("Test 1", result) self.assertIn("<div>A fascinating table.</div>", result)
def test_render_empty_table(self): """ An empty table should render okay. """ block = TableBlock() result = block.render( { "first_row_is_table_header": False, "first_col_is_header": False, "data": [[None, None, None], [None, None, None], [None, None, None]], } ) expected = """ <table> <tbody> <tr><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td></tr> </tbody> </table> """ self.assertHTMLEqual(result, expected)