source: products/quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/testQPloneCommentsNotification.py @ 1465

Last change on this file since 1465 was 1465, checked in by crchemist, 12 years ago

fix test_bug_notification_on_single_reply_delete

File size: 9.0 KB
Line 
1#
2# Test configuration form working
3#
4import re
5from helperNotify import *
6from email.Header import Header
7
8from Products.CMFCore.permissions import ManagePortal, ReplyToItem
9import base64
10from email import message_from_string
11from quintagroup.plonecomments.utils import getMsg
12from base import getToolByName, FunctionalTestCase
13from config import *
14
15
16class TestNotification(FunctionalTestCase):
17
18    def setApprovePublished(self, swithA=1,swithP=1):
19        self.prefs._updateProperty('enable_approve_notification', swithA)
20        self.prefs._updateProperty('enable_published_notification', swithP)
21
22    def afterSetUp(self):
23        self.loginAsPortalOwner()
24
25        # VERY IMPORTANT to guarantee product skin's content visibility
26        self._refreshSkinData()
27
28        '''Preparation for functional testing'''
29        self.discussion = getToolByName(self.portal, 'portal_discussion', None)
30        # Allow discussion for Document
31        portal_types = getToolByName(self.portal, 'portal_types', None)
32        doc_fti = portal_types.getTypeInfo('Document')
33        doc_fti._updateProperty('allow_discussion', 1)
34
35        # Make sure Documents are visible by default
36        # XXX only do this for plone 3
37        self.portal.portal_workflow.setChainForPortalTypes(('Document',), 'plone_workflow')
38
39        portal_properties = getToolByName(self.portal, 'portal_properties', None)
40        self.prefs = portal_properties[PROPERTY_SHEET]
41
42        # Add Manager user - 'dm' and add him to Discussion Manager group
43        self.portal.portal_membership.addMember('dm', 'secret' , ['Manager'], [])
44        portal_groups = getToolByName(self.portal, 'portal_groups')
45        dm_group = portal_groups.getGroupById('DiscussionManager')
46        dm_group.addMember('dm')
47        self.logout()
48        self.login('dm')
49        # For prepare mail sending - enter an e-mail adress
50        self.portal.email_from_address = 'mail@plone.test'
51        self.prefs._updateProperty('email_discussion_manager', 'discussion.manager@test.com')
52        member = self.portal.portal_membership.getAuthenticatedMember()
53        member.setMemberProperties({'email':'creator@test.com'})
54
55        # Add testing document to portal
56        my_doc = self.portal.invokeFactory('Document', id='my_doc', title='Doc')
57        self.my_doc = self.portal['my_doc']
58        self.my_doc.edit(text_format='plain', text='hello world')
59        # Create talkback for document and Prepare REQUEST
60        self.discussion.getDiscussionFor(self.my_doc)
61        self.request = self.app.REQUEST
62        self.request.form['Creator'] = self.portal.portal_membership.getAuthenticatedMember().getUserName()
63        self.request.form['subject'] = "Reply 1"
64        self.request.form['body_text'] = "text of reply"
65
66        prepareMailSendTest()
67
68    def test_bug_parent_reply(self):
69        setProperties(self.prefs, 'enable_reply_user_notification')
70        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
71        parent_reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0]
72        parent_reply.discussion_reply('reply', 'text')
73
74    def test_bug_mistakable_names(self):
75        setProperties(self.prefs, 'enable_reply_user_notification')
76        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
77        parent_reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0]
78
79        args={'mto': 'user_email@gmail.com',
80              'mfrom': 'admin_email@gmail.com',
81              'obj': parent_reply,
82              'organization_name': 'org_name',
83              'name': parent_reply.getOwnerTuple()[1]}
84
85        msg = getMsg(self.portal, 'reply_notify_template', args)
86        patt = re.compile('\\n([^,]*?),\\n\\n')
87        m = patt.search(msg)
88        if m:
89            name = m.group(1)
90            self.assertEqual(parent_reply.getOwnerTuple()[1], name)
91        else:
92            raise "No name"
93
94    def test_notificafion_disabled(self):
95        cleanOutputDir()
96        setProperties(self.prefs)
97        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
98        self.failIf(testMailExistance(), 'Mail was sended when all notification was disabled.')
99
100    def test_published_comment_notification(self):
101        cleanOutputDir()
102        setProperties(self.prefs, 'enable_published_notification')
103        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
104        self.failUnless(testMailExistance(), 'Mail was not sended when enable_published_notification.')
105
106    def test_approve_comment_notification(self):
107        cleanOutputDir()
108        setProperties(self.prefs, 'enable_approve_notification')
109        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
110        self.failUnless(testMailExistance(), 'Mail was not sended when enable_approve_notification.')
111
112    def test_reply_comment_user_notification(self):
113        cleanOutputDir()
114        setProperties(self.prefs, 'enable_reply_user_notification')
115        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
116        self.failIf(testMailExistance(), 'Mail was sended for simple reply when enable_reply_user_notification.')
117
118        reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0]
119        reply.discussion_reply('A Reply for comment' ,'text of reply for comment')
120        reply_for_comment = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0]
121        self.failUnless(testMailExistance(), 'Mail was not sended when enable_reply_user_notification.')
122
123    def test_rejected_comment_notification(self):
124        cleanOutputDir()
125        setProperties(self.prefs, 'enable_rejected_user_notification', 'enable_moderation')
126        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
127        self.failIf(testMailExistance(), 'Mail was sended when enable_rejected_user_notification was enabled.')
128
129        reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0]
130        self.portal.REQUEST.set('ids', [reply.getId()])
131        self.portal.prefs_recent_comments_delete()
132        self.failUnless(testMailExistance(), 'Mail was not sended when enable_rejected_user_notification.')
133
134    def test_approve_comment_user__notification(self):
135        cleanOutputDir()
136        setProperties(self.prefs, 'enable_approve_user_notification')
137        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
138        self.failUnless(testMailExistance(), 'Mail was not sended when enable_approve_user_notification.')
139
140    def test_bug_notification_on_single_reply_publish(self):
141        """ Bug: no notification sent on publishing single comment.
142            Must be 3 mails: for replier about replying on his commen;
143                             for replier about publishig his comment;
144                             for document creator about adding new comment.
145        """
146        properties = ['enable_approve_user_notification', 'enable_reply_user_notification',
147                      'enable_published_notification']
148        setProperties(self.prefs, *properties)
149        #setProperties(self.prefs, 'enable_published_notification', )
150        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
151        reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0]
152        reply.discussion_reply('A Reply for reply for my_doc' ,'text of reply on reply for my_doc')
153        reply2 = self.discussion.getDiscussionFor(reply).getReplies()[0]
154
155        cleanOutputDir()
156        reply2.discussion_publish_comment()
157        mails = getMails()
158        self.failUnless([1 for m in mails if re.search('^Subject:.*(replied).*$', m, re.I|re.M)],
159            'No notification for reply.' % properties)
160        self.failUnless([1 for m in mails if re.search('^Subject:.*(added).*$', m, re.I|re.M)],
161            'No notification for adding comment.' % properties)
162        self.failUnless([1 for m in mails if re.search('^Subject:.*(published).*$', m, re.I|re.M)],
163            'No notification for publishing comment.' % properties)
164
165    def test_bug_notification_on_single_reply_delete(self):
166        """ Bug: no notification sent on deleting single comment.
167            Mail about rejecing comment should be sent to comentator.
168        """
169        properties = ['enable_rejected_user_notification',]
170        setProperties(self.prefs, *properties)
171        #setProperties(self.prefs, 'enable_published_notification', )
172        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
173        reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0]
174
175        cleanOutputDir()
176        reply.deleteDiscussion()
177        mails = getMails()
178        subject = str(Header('Your comment on Doc was not approved', 'utf-8'))
179        subjs = [message_from_string(m)['Subject'] for m in mails]
180        self.failUnless([1 for m in subjs if m == subject],
181            'No notification for rejecting comment.' % properties)
182
183
184def test_suite():
185    from unittest import TestSuite, makeSuite
186    suite = TestSuite()
187    suite.addTest(makeSuite(TestNotification))
188    return suite
Note: See TracBrowser for help on using the repository browser.