Exemple #1
0
    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)
Exemple #2
0
    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)
Exemple #3
0
    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>&lt;p&gt;&lt;strong&gt;Test&lt;/strong&gt;&lt;/p&gt;</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)
Exemple #4
0
    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)
Exemple #5
0
    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)
Exemple #6
0
    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)
Exemple #7
0
    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)
Exemple #8
0
    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)
Exemple #9
0
    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)
Exemple #10
0
 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)
Exemple #11
0
    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)
Exemple #12
0
 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)
Exemple #13
0
 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)
Exemple #14
0
    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)
Exemple #15
0
    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)
Exemple #16
0
    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)
Exemple #17
0
    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)
Exemple #18
0
    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)
Exemple #19
0
    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)
Exemple #20
0
    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)
Exemple #21
0
    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)
Exemple #22
0
    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)
Exemple #23
0
    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)
Exemple #24
0
    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)
Exemple #25
0
 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)