Skip to content

Commit

Permalink
Add templatetag tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamu committed Jan 30, 2018
1 parent 395a988 commit 9b640b4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pinax/comments/models.py
Expand Up @@ -39,4 +39,4 @@ def data(self):
}

def __str__(self):
return "pk=%d" % self.pk
return "pk=%d" % self.pk # pragma: no cover
42 changes: 42 additions & 0 deletions pinax/comments/tests/tests.py
Expand Up @@ -275,3 +275,45 @@ def test_ttag_comment_target(self):
Context({"o": d}),
"/comment/%d/%d/" % (ContentType.objects.get_for_model(d).pk, d.pk)
)

def test_ttag_can_edit_comment(self):
d = Demo.objects.create(name="Wizard")
with self.login(self.gimli):
self.post_comment(d, data={
"name": "Gandalf",
"comment": "You can't win",
})
comment = Comment.objects.get()

self.assert_renders(
"{% load pinax_comments_tags %}{% if comment|can_edit_comment:user %}True{% else %}False{% endif %}",
Context({"comment": comment, "user": self.gimli}),
"True"
)

self.assert_renders(
"{% load pinax_comments_tags %}{% if comment|can_edit_comment:user %}True{% else %}False{% endif %}",
Context({"comment": comment, "user": self.aragorn}),
"False"
)

def test_ttag_can_delete_comment(self):
d = Demo.objects.create(name="Wizard")
with self.login(self.gimli):
self.post_comment(d, data={
"name": "Gandalf",
"comment": "You can't win",
})
comment = Comment.objects.get()

self.assert_renders(
"{% load pinax_comments_tags %}{% if comment|can_delete_comment:user %}True{% else %}False{% endif %}",
Context({"comment": comment, "user": self.gimli}),
"True"
)

self.assert_renders(
"{% load pinax_comments_tags %}{% if comment|can_delete_comment:user %}True{% else %}False{% endif %}",
Context({"comment": comment, "user": self.aragorn}),
"False"
)

0 comments on commit 9b640b4

Please sign in to comment.