~ubuntu-branches/ubuntu/quantal/python-django/quantal

« back to all changes in this revision

Viewing changes to tests/regressiontests/comment_tests/tests/templatetag_tests.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant
  • Date: 2008-11-15 19:15:33 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20081115191533-xbt1ut2xf4fvwtvc
Tags: 1.0.1-0ubuntu1
* New upstream release:
  - Bug fixes.

* The tests/ sub-directory appaers to have been dropped upstream, so pull
  our patch to workaround the tests and modify the rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from django.contrib.comments.forms import CommentForm
2
 
from django.contrib.comments.models import Comment
3
 
from django.template import Template, Context
4
 
from regressiontests.comment_tests.models import Article, Author
5
 
from regressiontests.comment_tests.tests import CommentTestCase
6
 
 
7
 
class CommentTemplateTagTests(CommentTestCase):
8
 
 
9
 
    def render(self, t, **c):
10
 
        ctx = Context(c)
11
 
        out = Template(t).render(ctx)
12
 
        return ctx, out
13
 
 
14
 
    def testCommentFormTarget(self):
15
 
        ctx, out = self.render("{% load comments %}{% comment_form_target %}")
16
 
        self.assertEqual(out, "/post/")
17
 
 
18
 
    def testGetCommentForm(self, tag=None):
19
 
        t = "{% load comments %}" + (tag or "{% get_comment_form for comment_tests.article a.id as form %}")
20
 
        ctx, out = self.render(t, a=Article.objects.get(pk=1))
21
 
        self.assertEqual(out, "")
22
 
        self.assert_(isinstance(ctx["form"], CommentForm))
23
 
 
24
 
    def testGetCommentFormFromLiteral(self):
25
 
        self.testGetCommentForm("{% get_comment_form for comment_tests.article 1 as form %}")
26
 
 
27
 
    def testGetCommentFormFromObject(self):
28
 
        self.testGetCommentForm("{% get_comment_form for a as form %}")
29
 
 
30
 
    def testRenderCommentForm(self, tag=None):
31
 
        t = "{% load comments %}" + (tag or "{% render_comment_form for comment_tests.article a.id %}")
32
 
        ctx, out = self.render(t, a=Article.objects.get(pk=1))
33
 
        self.assert_(out.strip().startswith("<form action="))
34
 
        self.assert_(out.strip().endswith("</form>"))
35
 
 
36
 
    def testRenderCommentFormFromLiteral(self):
37
 
        self.testRenderCommentForm("{% render_comment_form for comment_tests.article 1 %}")
38
 
 
39
 
    def testRenderCommentFormFromObject(self):
40
 
        self.testRenderCommentForm("{% render_comment_form for a %}")
41
 
 
42
 
    def testGetCommentCount(self, tag=None):
43
 
        self.createSomeComments()
44
 
        t = "{% load comments %}" + (tag or "{% get_comment_count for comment_tests.article a.id as cc %}") + "{{ cc }}"
45
 
        ctx, out = self.render(t, a=Article.objects.get(pk=1))
46
 
        self.assertEqual(out, "2")
47
 
 
48
 
    def testGetCommentCountFromLiteral(self):
49
 
        self.testGetCommentCount("{% get_comment_count for comment_tests.article 1 as cc %}")
50
 
 
51
 
    def testGetCommentCountFromObject(self):
52
 
        self.testGetCommentCount("{% get_comment_count for a as cc %}")
53
 
 
54
 
    def testGetCommentList(self, tag=None):
55
 
        c1, c2, c3, c4 = self.createSomeComments()
56
 
        t = "{% load comments %}" + (tag or "{% get_comment_list for comment_tests.author a.id as cl %}")
57
 
        ctx, out = self.render(t, a=Author.objects.get(pk=1))
58
 
        self.assertEqual(out, "")
59
 
        self.assertEqual(list(ctx["cl"]), [c2])
60
 
 
61
 
    def testGetCommentListFromLiteral(self):
62
 
        self.testGetCommentList("{% get_comment_list for comment_tests.author 1 as cl %}")
63
 
 
64
 
    def testGetCommentListFromObject(self):
65
 
        self.testGetCommentList("{% get_comment_list for a as cl %}")