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