示例#1
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)
示例#2
0
class BankingStreamFieldPage(Page):
    body = StreamField([
        ('paragraph', blocks.RichTextBlock()),
        ('bankrate_widget', BankrateWidgetBlock()),
        ('bankrate_cd_widget', BankrateCDRatesBlock()),
        ('bankrate_mortgage_widget', BankrateMortgageRatesBlock()),
        ('table_block', TableBlock(table_options=banking_table_options)),
    ])

    comparisons = StreamField([
        ('paragraph', blocks.RichTextBlock()),
        ('banking_comparison', BankingComparisonBlock()),
        ('bankrate_widget', BankrateWidgetBlock()),
        ('bankrate_cd_widget', BankrateCDRatesBlock()),
        ('bankrate_mortgage_widget', BankrateMortgageRatesBlock()),
        ('table_block', TableBlock(table_options=banking_table_options)),
    ],
                              null=True,
                              blank=True)

    parent_page_types = ['banking.BankingIndexPage']

    class Meta:
        verbose_name = 'Banking and Savings Streamfield page'

    content_panels = Page.content_panels + [
        StreamFieldPanel('body'),
        StreamFieldPanel('comparisons'),
    ]
示例#3
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)
示例#4
0
 def test_searchable_content(self):
     value = {'first_row_is_table_header': False, 'first_col_is_header': False,
              'data': [['Test 1', 'Test 2', 'Test 3'], [None, 'Bar', None],
                       [None, 'Foo', None]]}
     block = TableBlock()
     content = block.get_searchable_content(value)
     self.assertEqual(content, ['Test 1', 'Test 2', 'Test 3', 'Bar', 'Foo', ])
示例#5
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)
示例#6
0
 def test_searchable_content(self):
     value = {'first_row_is_table_header': False, 'first_col_is_header': False,
              'data': [['Test 1', 'Test 2', 'Test 3'], [None, 'Bar', None],
                       [None, 'Foo', None]]}
     block = TableBlock()
     content = block.get_searchable_content(value)
     self.assertEqual(content, ['Test 1', 'Test 2', 'Test 3', 'Bar', 'Foo', ])
示例#7
0
文件: tests.py 项目: jams2/wagtail
    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)
示例#8
0
文件: tests.py 项目: tnir/wagtail
    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)
示例#9
0
class TwoColumnPage(Page):
    body = StreamField([
        ('heading', blocks.CharBlock(classname="full title")),
        ('paragraph', blocks.RichTextBlock()),
        ('table', TableBlock()),
        ('image', ImageChooserBlock(icon="image")),
        ('embedded_video', EmbedBlock(icon="media")),
    ], blank=True)
    sidebar = StreamField([
        ('heading', blocks.CharBlock(classname="full title")),
        ('paragraph', blocks.RichTextBlock()),
        ('table', TableBlock()),
        ('image', ImageChooserBlock(icon="image")),
        ('embedded_video', EmbedBlock(icon="media")),
    ], blank=True)

    content_panels = Page.content_panels + [
        StreamFieldPanel('body'),
    ]
    sidebar_panel = [
        StreamFieldPanel('sidebar'),
    ]

    edit_handler = TabbedInterface([
        ObjectList(content_panels, heading='Main'),
        ObjectList(sidebar_panel, heading='Sidebar'),
        ObjectList(Page.promote_panels, heading='Promote'),
        ObjectList(Page.settings_panels, heading='Settings', classname="settings"),
    ])

    template = "wagtail-2-col.html"
示例#10
0
文件: tests.py 项目: jams2/wagtail
    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)
示例#11
0
文件: tests.py 项目: jams2/wagtail
 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)
示例#12
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)
示例#13
0
文件: tests.py 项目: jams2/wagtail
 def test_table_options_context_menu(self):
     """
     Test how contextMenu is set to default.
     """
     default_context_menu = list(
         DEFAULT_TABLE_OPTIONS["contextMenu"])  # create copy
     # confirm the default is correct
     table_options = TableBlock().table_options
     self.assertEqual(table_options["contextMenu"], default_context_menu)
     # confirm that when custom option is True, default is still used
     table_options_menu_true = TableBlock(table_options={
         "contextMenu": True
     }).table_options
     self.assertEqual(table_options_menu_true["contextMenu"],
                      default_context_menu)
     # confirm menu is removed if False is passed in
     table_options_menu_false = TableBlock(table_options={
         "contextMenu": False
     }).table_options
     self.assertIs(table_options_menu_false["contextMenu"], False)
     # confirm if list passed in, it is used
     table_options_menu_list = TableBlock(table_options={
         "contextMenu": ["undo", "redo"]
     }).table_options
     self.assertEqual(table_options_menu_list["contextMenu"],
                      ["undo", "redo"])
     # test if empty array passed in
     table_options_menu_list = TableBlock(table_options={
         "contextMenu": []
     }).table_options
     self.assertEqual(table_options_menu_list["contextMenu"], [])
示例#14
0
class ArticlePage(common.GenericPage):
    class Meta:
        verbose_name = '呼吸疾病中心页面模板/一般文章页'

    template = 'ncrcrd/article.html'

    content = StreamField([
        ('title', blocks.TitleBlock()),
        ('heading', blocks.HeadingBlock()),
        ('paragraph', blocks.ParagraphBlock()),
        ('image', blocks.ImageBlock()),
        ('person_card', blocks.PersonCardBlock()),
        ('organization_card', blocks.OrganizationCardBlock()),
        ('study_card', blocks.StudyCardBlock()),
        ('book_card', blocks.BookCardBlock()),
        ('table', TableBlock(label='表格')),
        ('table_corporation',
         TableBlock(label='协作单位表格',
                    template='ncrcrd/blocks/table_corporation.html')),
        ('table_guide',
         TableBlock(label='指南规范表格',
                    template='ncrcrd/blocks/table_guide.html')),
    ],
                          verbose_name='正文')

    show_sidebar = models.BooleanField(default=True, verbose_name='显示侧边栏')
    show_breadcrumb = models.BooleanField(default=True, verbose_name='显示面包屑导航')
示例#15
0
文件: tests.py 项目: jams2/wagtail
    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)
示例#16
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)
示例#17
0
文件: tests.py 项目: jams2/wagtail
    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)
示例#18
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)
示例#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 = """
            <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)
示例#20
0
文件: tests.py 项目: jams2/wagtail
 def test_searchable_content(self):
     """
     Test searchable content is created correctly.
     """
     block = TableBlock()
     search_content = block.get_searchable_content(value=self.value)
     self.assertIn("Galactica", search_content)
     self.assertIn("Brenik", search_content)
示例#21
0
 def test_searchable_content(self):
     """
     Test searchable content is created correctly.
     """
     block = TableBlock()
     search_content = block.get_searchable_content(value=self.value)
     self.assertIn('Galactica', search_content)
     self.assertIn('Brenik', search_content)
示例#22
0
class BlogPage(Page):
    body = StreamField([
        ('heading', blocks.CharBlock(classname="full title")),
        ('paragraph', blocks.RichTextBlock()),
        ('image', ImageChooserBlock()),
        ('small_table', TableBlock(table_options=small_table)),
        ('large_table', TableBlock(table_options=large_table)),
    ])
    thumbnail = models.ForeignKey('wagtailimages.Image',
                                  null=True,
                                  blank=True,
                                  on_delete=models.SET_NULL,
                                  related_name='+')
    tags = ClusterTaggableManager(through=BlogPageTag, blank=True)

    @property
    def intro(self):
        intro_text = ''
        blocks = self.body.stream_data
        for block in blocks:
            if block['type'] == "paragraph":
                intro_text = "&emsp;&emsp;&emsp;" + remove_html_tags(
                    block['value'][:300]) + "..."
                break
        return intro_text

    @property
    def npcs(self):
        npcs = [n.npc for n in self.npc_blog_relationship.all()]
        return npcs

    @property
    def quests(self):
        quests = [q.quest for q in self.quest_blog_relationship.all()]
        return quests

    content_panels = Page.content_panels + [
        StreamFieldPanel('body'),
        MultiFieldPanel([
            FieldPanel('thumbnail'),
        ],
                        heading="Thumbnail",
                        classname="collapsible collapsed"),
        MultiFieldPanel([
            InlinePanel('npc_blog_relationship'),
            InlinePanel('quest_blog_relationship'),
        ],
                        heading="Blog Extras -- NPC's and Quests",
                        classname="collapsible collapsed"),
        FieldPanel('tags', heading="Tags")
    ]

    def save(self, *args, **kwargs):
        if self.id is None:
            self.show_in_menus = True
            self.show_in_menus_default = True
        return super().save()
示例#23
0
class CreditCardReview(RoutablePageMixin, Page):
    '''
    The review of a card. Includes both the summary and the full review.
    Inherits from Page because it generates a page on the site.
    '''
    card = models.OneToOneField(CreditCard, related_name='review', on_delete=models.PROTECT)
    intro = StreamField([
        ('heading', blocks.CharBlock(classname="full title")),
        ('paragraph', blocks.RichTextBlock()),
        ('image', ImageChooserBlock()),
        ('blockquote', blocks.BlockQuoteBlock()),
        ('table_block', TableBlock()),
    ], blank=True)
    body = StreamField([
        ('heading', blocks.CharBlock(classname="full title")),
        ('paragraph', blocks.RichTextBlock()),
        ('image', ImageChooserBlock()),
        ('blockquote', blocks.BlockQuoteBlock()),
        ('table_block', TableBlock()),
    ])
    pros = RichTextField(default='<ul><li></li></ul>')
    cons = RichTextField(default='<ul><li></li></ul>')
    tags = ClusterTaggableManager(through=CreditCardReviewTag, blank=True)

    content_panels = Page.content_panels + [
        SnippetChooserPanel('card'),
        #FieldPanel('card', classname="full"),
        StreamFieldPanel('intro'),
        StreamFieldPanel('body'),
        FieldPanel('pros', classname="full"),
        FieldPanel('cons', classname="full"),
        FieldPanel('tags', classname="full"),
    ]

    @route(r'^card/$', name='conduit')
    def conduit(self, request):
        self.template = 'creditcards/credit_card_only.html'
        self.conduit = True
        return self.serve(request)

    @route(r'^$') #need default for revision view it seems
    def regular(self, request):
        return self.serve(request)

    @cached_property
    def conduit_url(self):
        subpage_url = self.reverse_subpage('conduit')
        if not self.url.endswith('/') and not subpage_url.startswith('/'):
            return self.url + '/' + subpage_url
        return self.url + subpage_url

    parent_page_types = ['creditcards.CreditCardIndex']

    def disclosure(self):
        return disclosure_generator(self.card.processing_network)
示例#24
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)
示例#25
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)
示例#26
0
文件: tests.py 项目: jams2/wagtail
    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)
示例#27
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)
示例#28
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)
示例#29
0
 def test_tableblock_render_form(self):
     """
     Test the rendered form field generated by TableBlock.
     """
     block = TableBlock()
     html = block.render_form(value=self.value)
     self.assertIn('<script>initTable', html)
     self.assertIn('<div class="field char_field widget-table_input">', html)
     # check that options render in the init function
     self.assertIn('"editor": "text"', html)
     self.assertIn('"autoColumnSize": false', html)
     self.assertIn('"stretchH": "all"', html)
示例#30
0
 def test_tableblock_render_form(self):
     """
     Test the rendered form field generated by TableBlock.
     """
     block = TableBlock()
     html = block.render_form(value=self.value)
     self.assertIn('<script>initTable', html)
     self.assertIn('<div class="field char_field widget-table_input">', html)
     # check that options render in the init function
     self.assertIn('"editor": "text"', html)
     self.assertIn('"autoColumnSize": false', html)
     self.assertIn('"stretchH": "all"', html)
示例#31
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)
示例#32
0
    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)
示例#33
0
    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)
示例#34
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)
示例#35
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)
示例#36
0
    def test_table_options_others(self):
        """
        Test simple options overrides get passed correctly.
        """
        block_1_opts = TableBlock(table_options={'startRows': 5, 'startCols': 2}).table_options
        self.assertEqual(block_1_opts['startRows'], 5)
        self.assertEqual(block_1_opts['startCols'], 2)

        block_2_opts = TableBlock(table_options={'stretchH': 'none'}).table_options
        self.assertEqual(block_2_opts['stretchH'], 'none')

        # check value that is not part of the defaults
        block_3_opts = TableBlock(table_options={'allowEmpty': False}).table_options
        self.assertEqual(block_3_opts['allowEmpty'], False)
示例#37
0
    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)
示例#38
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)
示例#39
0
 def test_default_table_options(self):
     """
     Test options without any custom table_options provided.
     """
     block = TableBlock()
     # check that default_table_options created correctly
     self.assertEqual(block.table_options, block.get_table_options())
     # check that default_table_options used on self
     self.assertEqual(self.default_table_options, block.table_options)
     # check a few individual keys from DEFAULT_TABLE_OPTIONS
     self.assertEqual(DEFAULT_TABLE_OPTIONS['startRows'], block.table_options['startRows'])
     self.assertEqual(DEFAULT_TABLE_OPTIONS['colHeaders'], block.table_options['colHeaders'])
     self.assertEqual(DEFAULT_TABLE_OPTIONS['contextMenu'], block.table_options['contextMenu'])
     self.assertEqual(DEFAULT_TABLE_OPTIONS['editor'], block.table_options['editor'])
     self.assertEqual(DEFAULT_TABLE_OPTIONS['stretchH'], block.table_options['stretchH'])
示例#40
0
 def test_default_table_options(self):
     """
     Test options without any custom table_options provided.
     """
     block = TableBlock()
     # check that default_table_options created correctly
     self.assertEqual(block.table_options, block.get_table_options())
     # check that default_table_options used on self
     self.assertEqual(self.default_table_options, block.table_options)
     # check a few individual keys from DEFAULT_TABLE_OPTIONS
     self.assertEqual(DEFAULT_TABLE_OPTIONS['startRows'], block.table_options['startRows'])
     self.assertEqual(DEFAULT_TABLE_OPTIONS['colHeaders'], block.table_options['colHeaders'])
     self.assertEqual(DEFAULT_TABLE_OPTIONS['contextMenu'], block.table_options['contextMenu'])
     self.assertEqual(DEFAULT_TABLE_OPTIONS['editor'], block.table_options['editor'])
     self.assertEqual(DEFAULT_TABLE_OPTIONS['stretchH'], block.table_options['stretchH'])
示例#41
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)
示例#42
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)