source: products/qPloneComments/tags/2.2.0-rc1/tests/testQPloneCommentsNotification.py @ 1

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

Building directory structure

File size: 5.8 KB
Line 
1#
2# Test configuration form working
3#
4
5import os, sys, string
6if __name__ == '__main__':
7    execfile(os.path.join(sys.path[0], 'framework.py'))
8
9from Products.PloneTestCase import PloneTestCase
10from Products.CMFCore.utils import getToolByName
11from Products.CMFCore.CMFCorePermissions import ManagePortal, ReplyToItem
12from Products.MailHost.MailHost import MailBase
13from helperNotify import *
14
15PRODUCT = 'qPloneComments'
16PROPERTY_SHEET = "qPloneComments"
17
18
19PloneTestCase.installProduct(PRODUCT)
20PloneTestCase.setupPloneSite()
21
22
23class TestNotification(PloneTestCase.FunctionalTestCase):
24
25    def setApprovePublished(self, swithA=1,swithP=1):
26        self.prefs._updateProperty('enable_approve_notification', swithA)
27        self.prefs._updateProperty('enable_published_notification', swithP)
28
29
30    def afterSetUp(self):
31        self.loginAsPortalOwner()
32
33        self.qi = self.portal.portal_quickinstaller
34        self.qi.installProduct(PRODUCT)
35        # VERY IMPORTANT to guarantee product skin's content visibility
36        self._refreshSkinData()
37
38        '''Preparation for functional testing'''
39        self.discussion = getToolByName(self.portal, 'portal_discussion', None)
40        # Allow discussion for Document
41        portal_types = getToolByName(self.portal, 'portal_types', None)
42        doc_fti = portal_types.getTypeInfo('Document')
43        doc_fti._updateProperty('allow_discussion', 1)
44
45        portal_properties = getToolByName(self.portal, 'portal_properties', None)
46        self.prefs = portal_properties[PROPERTY_SHEET]
47
48        # Add Manager user - 'dm' and add him to Discussion Manager group
49        self.portal.portal_membership.addMember('dm', 'secret' , ['Manager'], [])
50        portal_groups = getToolByName(self.portal, 'portal_groups')
51        dm_group = portal_groups.getGroupById('DiscussionManager')
52        dm_group.addMember('dm')
53        self.logout()
54        self.login('dm')
55        # For prepare mail sending - enter an e-mail adress
56        self.prefs._updateProperty('email_discussion_manager', 'discussion.manager@test.com')
57        member = self.portal.portal_membership.getAuthenticatedMember()
58        member.setMemberProperties({'email':'creator@test.com'})
59       
60        # Add testing document to portal
61        my_doc = self.portal.invokeFactory('Document', id='my_doc')
62        self.my_doc = self.portal['my_doc']
63        self.my_doc.edit(text_format='plain', text='hello world')
64        # Create talkback for document and Prepare REQUEST
65        self.discussion.getDiscussionFor(self.my_doc)
66        self.request = self.app.REQUEST
67        self.request.form['Creator'] = self.portal.portal_membership.getAuthenticatedMember().getUserName()
68        self.request.form['subject'] = "Reply 1"
69        self.request.form['body_text'] = "text of reply"
70
71        prepareMailSendTest()
72
73   
74    def testPublishedOFF(self):
75        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
76        clearFile(output_file_path('mail.res'))
77        reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0]
78
79        # Set Published Notification OFF
80        self.setApprovePublished(swithA=0,swithP=0)
81        reply.discussion_publish_comment()
82        testNotMail(self)
83
84    def testPublishedON(self):
85        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
86        clearFile(output_file_path('mail.res'))
87        reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0]
88
89        # Set Published Notification ON
90        self.setApprovePublished(swithA=0,swithP=1)
91        reply.discussion_publish_comment()
92        testMailSend(self, state='published')
93
94
95    def testApproveOFF(self):
96        # Set Approve Notification OFF
97        self.setApprovePublished(swithA=0,swithP=0)
98        self.my_doc.discussion_reply('Reply 1', 'text of reply')
99        testNotMail(self)
100
101
102    def testApproveON(self):
103        # Set Approve Notification ON
104        self.setApprovePublished(swithA=1,swithP=0)
105        self.my_doc.discussion_reply('Reply 1', 'text of reply')
106        testMailSend(self, state='approve')
107
108
109    def testOFFModerationApprovePublished(self):
110        self.prefs._updateProperty('enable_moderation', 0)
111
112        # Test Enable Approve Notification & Enable Published Notification
113        self.setApprovePublished(swithA=1, swithP=1)
114        self.my_doc.discussion_reply('Reply 1', 'text of reply')
115        testMailSend(self, state='approve')
116        testMailSend(self, state='published')
117
118   
119    def testOFFModerationApprove(self):
120        self.prefs._updateProperty('enable_moderation', 0)
121       
122        # Test Enable Approve Notification & Disable Published Notification
123        self.setApprovePublished(swithA=1,swithP=0)
124        self.my_doc.discussion_reply('Reply 1', 'text of reply')
125        testMailSend(self, state='approve')
126        testNotMailSend(self, state='published')
127
128
129    def testOFFModerationPublished(self): 
130        self.prefs._updateProperty('enable_moderation', 0)
131       
132        # Test Enable Published Notification  & Disable Approve Notification
133        self.setApprovePublished(swithA=0,swithP=1)
134        self.my_doc.discussion_reply('Reply 1', 'text of reply')
135        testNotMailSend(self, state='approve')
136        testMailSend(self, state='published')
137
138
139    def testOFFModeration(self): 
140        self.prefs._updateProperty('enable_moderation', 0)
141       
142        # Test Disable Published Notification & Disable Approve Notification
143        self.setApprovePublished(swithA=0,swithP=0)
144        self.my_doc.discussion_reply('Reply 1', 'text of reply')
145        testNotMailSend(self, state='approve')
146        testNotMailSend(self, state='published')
147       
148
149
150TESTS = [TestNotification]
151
152def test_suite():
153    from unittest import TestSuite, makeSuite
154    suite = TestSuite()
155    suite.addTest(makeSuite(TestNotification))
156    return suite
157
158if __name__ == '__main__':
159    framework()
160
Note: See TracBrowser for help on using the repository browser.