source: products/qPloneComments/tags/2.3/tests/testQPloneCommentsNotification.py @ 1591

Last change on this file since 1591 was 1, checked in by myroslav, 18 years ago

Building directory structure

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