/tests/regressiontests/comment_tests/tests/__init__.py

https://code.google.com/p/mango-py/ · Python · 90 lines · 77 code · 8 blank · 5 comment · 0 complexity · abe44235a8cdebc77197207206be0b92 MD5 · raw file

  1. from django.contrib.auth.models import User
  2. from django.contrib.comments.forms import CommentForm
  3. from django.contrib.comments.models import Comment
  4. from django.contrib.contenttypes.models import ContentType
  5. from django.contrib.sites.models import Site
  6. from django.test import TestCase
  7. from regressiontests.comment_tests.models import Article, Author
  8. # Shortcut
  9. CT = ContentType.objects.get_for_model
  10. # Helper base class for comment tests that need data.
  11. class CommentTestCase(TestCase):
  12. fixtures = ["comment_tests"]
  13. urls = 'django.contrib.comments.urls'
  14. def createSomeComments(self):
  15. # Two anonymous comments on two different objects
  16. c1 = Comment.objects.create(
  17. content_type = CT(Article),
  18. object_pk = "1",
  19. user_name = "Joe Somebody",
  20. user_email = "jsomebody@example.com",
  21. user_url = "http://example.com/~joe/",
  22. comment = "First!",
  23. site = Site.objects.get_current(),
  24. )
  25. c2 = Comment.objects.create(
  26. content_type = CT(Author),
  27. object_pk = "1",
  28. user_name = "Joe Somebody",
  29. user_email = "jsomebody@example.com",
  30. user_url = "http://example.com/~joe/",
  31. comment = "First here, too!",
  32. site = Site.objects.get_current(),
  33. )
  34. # Two authenticated comments: one on the same Article, and
  35. # one on a different Author
  36. user = User.objects.create(
  37. username = "frank_nobody",
  38. first_name = "Frank",
  39. last_name = "Nobody",
  40. email = "fnobody@example.com",
  41. password = "",
  42. is_staff = False,
  43. is_active = True,
  44. is_superuser = False,
  45. )
  46. c3 = Comment.objects.create(
  47. content_type = CT(Article),
  48. object_pk = "1",
  49. user = user,
  50. user_url = "http://example.com/~frank/",
  51. comment = "Damn, I wanted to be first.",
  52. site = Site.objects.get_current(),
  53. )
  54. c4 = Comment.objects.create(
  55. content_type = CT(Author),
  56. object_pk = "2",
  57. user = user,
  58. user_url = "http://example.com/~frank/",
  59. comment = "You get here first, too?",
  60. site = Site.objects.get_current(),
  61. )
  62. return c1, c2, c3, c4
  63. def getData(self):
  64. return {
  65. 'name' : 'Jim Bob',
  66. 'email' : 'jim.bob@example.com',
  67. 'url' : '',
  68. 'comment' : 'This is my comment',
  69. }
  70. def getValidData(self, obj):
  71. f = CommentForm(obj)
  72. d = self.getData()
  73. d.update(f.initial)
  74. return d
  75. from regressiontests.comment_tests.tests.app_api_tests import *
  76. from regressiontests.comment_tests.tests.feed_tests import *
  77. from regressiontests.comment_tests.tests.model_tests import *
  78. from regressiontests.comment_tests.tests.comment_form_tests import *
  79. from regressiontests.comment_tests.tests.templatetag_tests import *
  80. from regressiontests.comment_tests.tests.comment_view_tests import *
  81. from regressiontests.comment_tests.tests.moderation_view_tests import *
  82. from regressiontests.comment_tests.tests.comment_utils_moderators_tests import *