PageRenderTime 22ms CodeModel.GetById 14ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/comment_tests/tests/model_tests.py

https://code.google.com/p/mango-py/
Python | 49 lines | 43 code | 6 blank | 0 comment | 3 complexity | a8ddf1eb9e4efa68f446d35efaf697a6 MD5 | raw file
 1from django.contrib.comments.models import Comment
 2
 3from regressiontests.comment_tests.models import Author, Article
 4from regressiontests.comment_tests.tests import CommentTestCase
 5
 6
 7class CommentModelTests(CommentTestCase):
 8    def testSave(self):
 9        for c in self.createSomeComments():
10            self.assertNotEqual(c.submit_date, None)
11
12    def testUserProperties(self):
13        c1, c2, c3, c4 = self.createSomeComments()
14        self.assertEqual(c1.name, "Joe Somebody")
15        self.assertEqual(c2.email, "jsomebody@example.com")
16        self.assertEqual(c3.name, "Frank Nobody")
17        self.assertEqual(c3.url, "http://example.com/~frank/")
18        self.assertEqual(c1.user, None)
19        self.assertEqual(c3.user, c4.user)
20
21class CommentManagerTests(CommentTestCase):
22
23    def testInModeration(self):
24        """Comments that aren't public are considered in moderation"""
25        c1, c2, c3, c4 = self.createSomeComments()
26        c1.is_public = False
27        c2.is_public = False
28        c1.save()
29        c2.save()
30        moderated_comments = list(Comment.objects.in_moderation().order_by("id"))
31        self.assertEqual(moderated_comments, [c1, c2])
32
33    def testRemovedCommentsNotInModeration(self):
34        """Removed comments are not considered in moderation"""
35        c1, c2, c3, c4 = self.createSomeComments()
36        c1.is_public = False
37        c2.is_public = False
38        c2.is_removed = True
39        c1.save()
40        c2.save()
41        moderated_comments = list(Comment.objects.in_moderation())
42        self.assertEqual(moderated_comments, [c1])
43
44    def testForModel(self):
45        c1, c2, c3, c4 = self.createSomeComments()
46        article_comments = list(Comment.objects.for_model(Article).order_by("id"))
47        author_comments = list(Comment.objects.for_model(Author.objects.get(pk=1)))
48        self.assertEqual(article_comments, [c1, c3])
49        self.assertEqual(author_comments, [c2])