~ubuntu-branches/ubuntu/quantal/python-django/quantal

« back to all changes in this revision

Viewing changes to tests/regressiontests/comment_tests/tests/comment_utils_moderators_tests.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2009-07-29 11:26:28 UTC
  • mfrom: (1.1.8 upstream) (4.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090729112628-pg09ino8sz0sj21t
Tags: 1.1-1
* New upstream release.
* Merge from experimental:
  - Ship FastCGI initscript and /etc/default file in python-django's examples
    directory (Closes: #538863)
  - Drop "05_10539-sphinx06-compatibility.diff"; it has been applied
    upstream.
  - Bump Standards-Version to 3.8.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from regressiontests.comment_tests.tests import CommentTestCase, CT, Site
 
2
from django.contrib.comments.forms import CommentForm
 
3
from django.contrib.comments.models import Comment
 
4
from django.contrib.comments.moderation import moderator, CommentModerator, AlreadyModerated
 
5
from regressiontests.comment_tests.models import Entry
 
6
from django.core import mail
 
7
 
 
8
class EntryModerator1(CommentModerator):
 
9
    email_notification = True
 
10
 
 
11
class EntryModerator2(CommentModerator):
 
12
    enable_field = 'enable_comments'
 
13
 
 
14
class EntryModerator3(CommentModerator):
 
15
    auto_close_field = 'pub_date'
 
16
    close_after = 7
 
17
 
 
18
class EntryModerator4(CommentModerator):
 
19
    auto_moderate_field = 'pub_date'
 
20
    moderate_after = 7
 
21
 
 
22
class CommentUtilsModeratorTests(CommentTestCase):
 
23
    fixtures = ["comment_utils.xml"]
 
24
 
 
25
    def createSomeComments(self):
 
26
        # Tests for the moderation signals must actually post data
 
27
        # through the comment views, because only the comment views
 
28
        # emit the custom signals moderation listens for.
 
29
        e = Entry.objects.get(pk=1)
 
30
        data = self.getValidData(e)
 
31
 
 
32
        self.client.post("/post/", data, REMOTE_ADDR="1.2.3.4")
 
33
 
 
34
        # We explicitly do a try/except to get the comment we've just
 
35
        # posted because moderation may have disallowed it, in which
 
36
        # case we can just return it as None.
 
37
        try:
 
38
            c1 = Comment.objects.all()[0]
 
39
        except IndexError:
 
40
            c1 = None
 
41
 
 
42
        self.client.post("/post/", data, REMOTE_ADDR="1.2.3.4")
 
43
 
 
44
        try:
 
45
            c2 = Comment.objects.all()[0]
 
46
        except IndexError:
 
47
            c2 = None
 
48
        return c1, c2
 
49
 
 
50
    def tearDown(self):
 
51
        moderator.unregister(Entry)
 
52
 
 
53
    def testRegisterExistingModel(self):
 
54
        moderator.register(Entry, EntryModerator1)
 
55
        self.assertRaises(AlreadyModerated, moderator.register, Entry, EntryModerator1)
 
56
 
 
57
    def testEmailNotification(self):
 
58
        moderator.register(Entry, EntryModerator1)
 
59
        self.createSomeComments()
 
60
        self.assertEquals(len(mail.outbox), 2)
 
61
 
 
62
    def testCommentsEnabled(self):
 
63
        moderator.register(Entry, EntryModerator2)
 
64
        self.createSomeComments()
 
65
        self.assertEquals(Comment.objects.all().count(), 1)
 
66
 
 
67
    def testAutoCloseField(self):
 
68
        moderator.register(Entry, EntryModerator3)
 
69
        self.createSomeComments()
 
70
        self.assertEquals(Comment.objects.all().count(), 0)
 
71
 
 
72
    def testAutoModerateField(self):
 
73
        moderator.register(Entry, EntryModerator4)
 
74
        c1, c2 = self.createSomeComments()
 
75
        self.assertEquals(c2.is_public, False)