def test_render_last_xtdcomments(self):
     t = ("{% load comments_xtd %}"
          "{% render_last_xtdcomments 5 for tests.article tests.diary %}")
     output = Template(t).render(Context())
     self.assertEqual(output.count('<a name='), 5)
     self.assertEqual(output.count('<a name="c6">'), 1)
     self.assertEqual(output.count('<a name="c5">'), 1)
     self.assertEqual(output.count('<a name="c4">'), 1)
     self.assertEqual(output.count('<a name="c3">'), 1)
     self.assertEqual(output.count('<a name="c2">'), 1)
     # We added 6 comments, and we render the last 5, so
     # the first one must not be rendered in the output.
     self.assertEqual(output.count('<a name="c1">'), 0)
 def test_render_last_xtdcomments(self):
     t = ("{% load comments_xtd %}"
          "{% render_last_xtdcomments 5 for tests.article tests.diary %}")
     output = Template(t).render(Context())
     self.assertEqual(output.count('<a name='), 5)
     self.assertEqual(output.count('<a name="c6">'), 1)
     self.assertEqual(output.count('<a name="c5">'), 1)
     self.assertEqual(output.count('<a name="c4">'), 1)
     self.assertEqual(output.count('<a name="c3">'), 1)
     self.assertEqual(output.count('<a name="c2">'), 1)
     # We added 6 comments, and we render the last 5, so
     # the first one must not be rendered in the output.
     self.assertEqual(output.count('<a name="c1">'), 0)
 def test_render_xtdcomment_tree(self):
     t = ("{% load comments_xtd %}"
          "{% render_xtdcomment_tree for object %}")
     output = Template(t).render(
         Context({
             'object': self.article,
             'user': AnonymousUser()
         }))
     self.assertEqual(output.count('<a name='), 9)
     # See test_models.py, ThreadStep5TestCase to get a quick
     # view of the comments posted and their thread structure.
     pos_c1 = output.index('<a name="c1"></a>')
     pos_c3 = output.index('<a name="c3"></a>')
     pos_c8 = output.index('<a name="c8"></a>')
     pos_c4 = output.index('<a name="c4"></a>')
     pos_c7 = output.index('<a name="c7"></a>')
     pos_c2 = output.index('<a name="c2"></a>')
     pos_c5 = output.index('<a name="c5"></a>')
     pos_c6 = output.index('<a name="c6"></a>')
     pos_c9 = output.index('<a name="c9"></a>')
     self.assertTrue(pos_c1 > 0)
     self.assertTrue(pos_c3 > 0)
     self.assertTrue(pos_c8 > 0)
     self.assertTrue(pos_c4 > 0)
     self.assertTrue(pos_c7 > 0)
     self.assertTrue(pos_c2 > 0)
     self.assertTrue(pos_c5 > 0)
     self.assertTrue(pos_c6 > 0)
     self.assertTrue(pos_c9 > 0)
     self.assertTrue(pos_c1 < pos_c3 < pos_c8 < pos_c4 < pos_c7 < pos_c2 <
                     pos_c5 < pos_c6 < pos_c9)
 def test_render_xtdcomment_tree(self):
     t = ("{% load comments_xtd %}"
          "{% render_xtdcomment_tree for object %}")
     output = Template(t).render(Context({'object': self.article,
                                          'user': AnonymousUser()}))
     self.assertEqual(output.count('<a name='), 9)
     # See test_models.py, ThreadStep5TestCase to get a quick
     # view of the comments posted and their thread structure.
     pos_c1 = output.index('<a name="c1"></a>')
     pos_c3 = output.index('<a name="c3"></a>')
     pos_c8 = output.index('<a name="c8"></a>')
     pos_c4 = output.index('<a name="c4"></a>')
     pos_c7 = output.index('<a name="c7"></a>')
     pos_c2 = output.index('<a name="c2"></a>')
     pos_c5 = output.index('<a name="c5"></a>')
     pos_c6 = output.index('<a name="c6"></a>')
     pos_c9 = output.index('<a name="c9"></a>')
     self.assertTrue(pos_c1 > 0)
     self.assertTrue(pos_c3 > 0)
     self.assertTrue(pos_c8 > 0)
     self.assertTrue(pos_c4 > 0)
     self.assertTrue(pos_c7 > 0)
     self.assertTrue(pos_c2 > 0)
     self.assertTrue(pos_c5 > 0)
     self.assertTrue(pos_c6 > 0)
     self.assertTrue(pos_c9 > 0)
     self.assertTrue(pos_c1 < pos_c3 < pos_c8 <
                     pos_c4 < pos_c7 < pos_c2 <
                     pos_c5 < pos_c6 < pos_c9)
 def test_get_last_xtdcomments(self):
     t = ("{% load comments_xtd %}"
          "{% get_last_xtdcomments 5 as last_comments"
          "   for tests.article tests.diary %}"
          "{% for comment in last_comments %}"
          "<comment>{{ comment.id }}</comment>"
          "{% endfor %}")
     output = Template(t).render(Context())
     self.assertEqual(output.count('<comment>'), 5)
     self.assertEqual(output.count('<comment>6</comment>'), 1)
     self.assertEqual(output.count('<comment>5</comment>'), 1)
     self.assertEqual(output.count('<comment>4</comment>'), 1)
     self.assertEqual(output.count('<comment>3</comment>'), 1)
     self.assertEqual(output.count('<comment>2</comment>'), 1)
     # We added 6 comments, and we render the last 5, so
     # the first one must not be rendered in the output.
     self.assertEqual(output.count('<comment>1</comment>'), 0)
 def test_get_last_xtdcomments(self):
     t = ("{% load comments_xtd %}"
          "{% get_last_xtdcomments 5 as last_comments"
          "   for tests.article tests.diary %}"
          "{% for comment in last_comments %}"
          "<comment>{{ comment.id }}</comment>"
          "{% endfor %}")
     output = Template(t).render(Context())
     self.assertEqual(output.count('<comment>'), 5)
     self.assertEqual(output.count('<comment>6</comment>'), 1)
     self.assertEqual(output.count('<comment>5</comment>'), 1)
     self.assertEqual(output.count('<comment>4</comment>'), 1)
     self.assertEqual(output.count('<comment>3</comment>'), 1)
     self.assertEqual(output.count('<comment>2</comment>'), 1)
     # We added 6 comments, and we render the last 5, so
     # the first one must not be rendered in the output.
     self.assertEqual(output.count('<comment>1</comment>'), 0)
Beispiel #7
0
    def test_value_is_escaped(self):
        img_tag_str = '<img src="test" />'

        rendered = Template(
            "{% load text_element %}"
            "{% text_element id='test' label='Test' value=img_tag_str %}"
        ).render(Context({"img_tag_str": img_tag_str}))

        assert escape(img_tag_str) in rendered
        assert rendered.count("src") == 1
Beispiel #8
0
    def test_render_table(self):
        out = Template(
            "{% load achilles %}"
            "{% ablock 'tables:People' %}").render(Context())

        # headers
        self.assertEqual(out.count('<th '), 2)

        # Cell row
        self.assertTrue("Kahlo" in out)
Beispiel #9
0
 def test_page_menu_flags(self):
     """
     Test that pages only appear in the menu templates they've been
     assigned to show in.
     """
     menus = []
     pages = []
     template = "{% load pages_tags %}"
     for i, label, path in settings.PAGE_MENU_TEMPLATES:
         menus.append(i)
         pages.append(RichTextPage.objects.create(in_menus=list(menus),
             title="Page for %s" % str(label),
             status=CONTENT_STATUS_PUBLISHED))
         template += "{%% page_menu '%s' %%}" % path
     rendered = Template(template).render(Context({}))
     for page in pages:
         self.assertEqual(rendered.count(page.title), len(page.in_menus))
Beispiel #10
0
 def test_page_menu_flags(self):
     """
     Test that pages only appear in the menu templates they've been
     assigned to show in.
     """
     menus = []
     pages = []
     template = "{% load pages_tags %}"
     for i, label, path in settings.PAGE_MENU_TEMPLATES:
         menus.append(i)
         pages.append(RichTextPage.objects.create(in_menus=list(menus),
             title="Page for %s" % str(label),
             status=CONTENT_STATUS_PUBLISHED))
         template += "{%% page_menu '%s' %%}" % path
     rendered = Template(template).render(Context({}))
     for page in pages:
         self.assertEqual(rendered.count(page.title), len(page.in_menus))
Beispiel #11
0
 def _assert_only_comment_2_and_3_and_their_children_are_published(self):
     t = ("{% load comments_xtd %}"
          "{% render_xtdcomment_tree for object %}")
     output = Template(t).render(
         Context({
             'object': self.article,
             'user': AnonymousUser()
         }))
     self.assertEqual(output.count('<a name='), 4)
     # Only the following comments must be displayed, the other ones must
     # have been unpublished when setting the comment 1 is_public to False.
     pos_c2 = output.index('<a name="c2"></a>')
     pos_c5 = output.index('<a name="c5"></a>')
     pos_c6 = output.index('<a name="c6"></a>')
     pos_c9 = output.index('<a name="c9"></a>')
     self.assertTrue(pos_c2 > 0)
     self.assertTrue(pos_c5 > 0)
     self.assertTrue(pos_c6 > 0)
     self.assertTrue(pos_c9 > 0)
     self.assertTrue(pos_c2 < pos_c5 < pos_c6 < pos_c9)
Beispiel #12
0
    def test_render_comment_tree(self):
        t = ("{% load comments_tree %}"
             "{% render_treecomment_tree for object %}")
        output = Template(t).render(
            Context({
                'object': self.article,
                'user': AnonymousUser()
            }))
        self.assertEqual(output.count('<a name='), 9)
        # See test_models.py, ThreadStep5TestCase to get a quick
        # view of the comments posted and their thread structure.
        id_list = [2, 4, 5, 8, 9, 3, 6, 7, 10]
        pos_list = [output.index(f'<a name="c{id}"></a>') for id in id_list]
        for pos in pos_list:
            self.assertTrue(pos > 0)

        for x in range(0, len(id_list) - 1):
            p1 = pos_list[x]
            p2 = pos_list[x + 1]
            self.assertTrue(p1 < p2)