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

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

Building directory structure

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