summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2009-03-23 21:07:02 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2009-03-23 21:07:02 +0000
commitf0560dfdb2adaa44fc739941a2a784c558ae6427 (patch)
tree96eff6021071b4ad77b1081ba21f12f5d8e8353c /tests
parent44f3080226888eb709cc6e027321647964ebe64e (diff)
Fixed #9282: added a generic comment moderation toolkit. See the documentation for details.
This began life as (part of) James Bennett's comment-utils app, and was adapted to be part of Django by Thejaswi Puthraya and Jannis Leidel. Thanks, all! git-svn-id: http://code.djangoproject.com/svn/django/trunk@10122 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/comment_tests/fixtures/comment_utils.xml15
-rw-r--r--tests/regressiontests/comment_tests/models.py8
-rw-r--r--tests/regressiontests/comment_tests/tests/__init__.py1
-rw-r--r--tests/regressiontests/comment_tests/tests/comment_utils_moderators_tests.py70
-rwxr-xr-xtests/runtests.py4
-rw-r--r--tests/templates/comments/comment_notification_email.txt3
6 files changed, 101 insertions, 0 deletions
diff --git a/tests/regressiontests/comment_tests/fixtures/comment_utils.xml b/tests/regressiontests/comment_tests/fixtures/comment_utils.xml
new file mode 100644
index 0000000000..a39bbf63e1
--- /dev/null
+++ b/tests/regressiontests/comment_tests/fixtures/comment_utils.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<django-objects version="1.0">
+ <object pk="1" model="comment_tests.entry">
+ <field type="CharField" name="title">ABC</field>
+ <field type="TextField" name="body">This is the body</field>
+ <field type="DateField" name="pub_date">2008-01-01</field>
+ <field type="BooleanField" name="enable_comments">True</field>
+ </object>
+ <object pk="2" model="comment_tests.entry">
+ <field type="CharField" name="title">XYZ</field>
+ <field type="TextField" name="body">Text here</field>
+ <field type="DateField" name="pub_date">2008-01-02</field>
+ <field type="BooleanField" name="enable_comments">False</field>
+ </object>
+</django-objects>
diff --git a/tests/regressiontests/comment_tests/models.py b/tests/regressiontests/comment_tests/models.py
index 28022e2848..62f416882c 100644
--- a/tests/regressiontests/comment_tests/models.py
+++ b/tests/regressiontests/comment_tests/models.py
@@ -20,3 +20,11 @@ class Article(models.Model):
def __str__(self):
return self.headline
+class Entry(models.Model):
+ title = models.CharField(max_length=250)
+ body = models.TextField()
+ pub_date = models.DateField()
+ enable_comments = models.BooleanField()
+
+ def __str__(self):
+ return self.title
diff --git a/tests/regressiontests/comment_tests/tests/__init__.py b/tests/regressiontests/comment_tests/tests/__init__.py
index 09026aa010..449fea471d 100644
--- a/tests/regressiontests/comment_tests/tests/__init__.py
+++ b/tests/regressiontests/comment_tests/tests/__init__.py
@@ -86,3 +86,4 @@ from regressiontests.comment_tests.tests.comment_form_tests import *
from regressiontests.comment_tests.tests.templatetag_tests import *
from regressiontests.comment_tests.tests.comment_view_tests import *
from regressiontests.comment_tests.tests.moderation_view_tests import *
+from regressiontests.comment_tests.tests.comment_utils_moderators_tests import *
diff --git a/tests/regressiontests/comment_tests/tests/comment_utils_moderators_tests.py b/tests/regressiontests/comment_tests/tests/comment_utils_moderators_tests.py
new file mode 100644
index 0000000000..4fe8b8ae12
--- /dev/null
+++ b/tests/regressiontests/comment_tests/tests/comment_utils_moderators_tests.py
@@ -0,0 +1,70 @@
+from regressiontests.comment_tests.tests import CommentTestCase, CT, Site
+from django.contrib.comments.models import Comment
+from django.contrib.comments.moderation import moderator, CommentModerator, AlreadyModerated
+from regressiontests.comment_tests.models import Entry
+from django.core import mail
+
+class EntryModerator1(CommentModerator):
+ email_notification = True
+
+class EntryModerator2(CommentModerator):
+ enable_field = 'enable_comments'
+
+class EntryModerator3(CommentModerator):
+ auto_close_field = 'pub_date'
+ close_after = 7
+
+class EntryModerator4(CommentModerator):
+ auto_moderate_field = 'pub_date'
+ moderate_after = 7
+
+class CommentUtilsModeratorTests(CommentTestCase):
+ fixtures = ["comment_utils.xml"]
+
+ def createSomeComments(self):
+ c1 = Comment.objects.create(
+ content_type = CT(Entry),
+ object_pk = "1",
+ user_name = "Joe Somebody",
+ user_email = "jsomebody@example.com",
+ user_url = "http://example.com/~joe/",
+ comment = "First!",
+ site = Site.objects.get_current(),
+ )
+ c2 = Comment.objects.create(
+ content_type = CT(Entry),
+ object_pk = "2",
+ user_name = "Joe the Plumber",
+ user_email = "joetheplumber@whitehouse.gov",
+ user_url = "http://example.com/~joe/",
+ comment = "Second!",
+ site = Site.objects.get_current(),
+ )
+ return c1, c2
+
+ def tearDown(self):
+ moderator.unregister(Entry)
+
+ def testRegisterExistingModel(self):
+ moderator.register(Entry, EntryModerator1)
+ self.assertRaises(AlreadyModerated, moderator.register, Entry, EntryModerator1)
+
+ def testEmailNotification(self):
+ moderator.register(Entry, EntryModerator1)
+ c1, c2 = self.createSomeComments()
+ self.assertEquals(len(mail.outbox), 2)
+
+ def testCommentsEnabled(self):
+ moderator.register(Entry, EntryModerator2)
+ c1, c2 = self.createSomeComments()
+ self.assertEquals(Comment.objects.all().count(), 1)
+
+ def testAutoCloseField(self):
+ moderator.register(Entry, EntryModerator3)
+ c1, c2 = self.createSomeComments()
+ self.assertEquals(Comment.objects.all().count(), 0)
+
+ def testAutoModerateField(self):
+ moderator.register(Entry, EntryModerator4)
+ c1, c2 = self.createSomeComments()
+ self.assertEquals(c2.is_public, False)
diff --git a/tests/runtests.py b/tests/runtests.py
index bd7f59bdf0..f556246c90 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -110,6 +110,10 @@ def django_tests(verbosity, interactive, test_labels):
'django.middleware.common.CommonMiddleware',
)
settings.SITE_ID = 1
+ # For testing comment-utils, we require the MANAGERS attribute
+ # to be set, so that a test email is sent out which we catch
+ # in our tests.
+ settings.MANAGERS = ("admin@djangoproject.com",)
# Load all the ALWAYS_INSTALLED_APPS.
# (This import statement is intentionally delayed until after we
diff --git a/tests/templates/comments/comment_notification_email.txt b/tests/templates/comments/comment_notification_email.txt
new file mode 100644
index 0000000000..63f149392e
--- /dev/null
+++ b/tests/templates/comments/comment_notification_email.txt
@@ -0,0 +1,3 @@
+A comment has been posted on {{ content_object }}.
+The comment reads as follows:
+{{ comment }}