source: products/qPloneComments/tags/2.2.1/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: 5.6 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
18PloneTestCase.installProduct(PRODUCT)
19PloneTestCase.setupPloneSite()
20
21
22class TestNotification(PloneTestCase.FunctionalTestCase):
23
24    def setApprovePublished(self, swithA=1,swithP=1):
25        self.prefs._updateProperty('enable_approve_notification', swithA)
26        self.prefs._updateProperty('enable_published_notification', swithP)
27
28    def afterSetUp(self):
29        self.loginAsPortalOwner()
30
31        self.qi = self.portal.portal_quickinstaller
32        self.qi.installProduct(PRODUCT)
33        # VERY IMPORTANT to guarantee product skin's content visibility
34        self._refreshSkinData()
35
36        '''Preparation for functional testing'''
37        self.discussion = getToolByName(self.portal, 'portal_discussion', None)
38        # Allow discussion for Document
39        portal_types = getToolByName(self.portal, 'portal_types', None)
40        doc_fti = portal_types.getTypeInfo('Document')
41        doc_fti._updateProperty('allow_discussion', 1)
42
43        portal_properties = getToolByName(self.portal, 'portal_properties', None)
44        self.prefs = portal_properties[PROPERTY_SHEET]
45
46        # Add Manager user - 'dm' and add him to Discussion Manager group
47        self.portal.portal_membership.addMember('dm', 'secret' , ['Manager'], [])
48        portal_groups = getToolByName(self.portal, 'portal_groups')
49        dm_group = portal_groups.getGroupById('DiscussionManager')
50        dm_group.addMember('dm')
51        self.logout()
52        self.login('dm')
53        # For prepare mail sending - enter an e-mail adress
54        self.prefs._updateProperty('email_discussion_manager', 'discussion.manager@test.com')
55        member = self.portal.portal_membership.getAuthenticatedMember()
56        member.setMemberProperties({'email':'creator@test.com'})
57
58        # Add testing document to portal
59        my_doc = self.portal.invokeFactory('Document', id='my_doc')
60        self.my_doc = self.portal['my_doc']
61        self.my_doc.edit(text_format='plain', text='hello world')
62        # Create talkback for document and Prepare REQUEST
63        self.discussion.getDiscussionFor(self.my_doc)
64        self.request = self.app.REQUEST
65        self.request.form['Creator'] = self.portal.portal_membership.getAuthenticatedMember().getUserName()
66        self.request.form['subject'] = "Reply 1"
67        self.request.form['body_text'] = "text of reply"
68
69        prepareMailSendTest()
70
71    def test_notificafion_disabled(self):
72        cleanOutputDir()
73        setProperties(self.prefs)
74        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
75        self.assert_(not testMailExistance(), 'Mail was sended when all notification was disabled')
76
77    def test_published_comment_notification(self):
78        cleanOutputDir()
79        setProperties(self.prefs, 'enable_published_notification')
80        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
81        self.assert_(testMailExistance(), 'Mail was not sended when enable_published_notification')
82
83    def test_approve_comment_notification(self):
84        cleanOutputDir()
85        setProperties(self.prefs, 'enable_approve_notification')
86        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
87        self.assert_(testMailExistance(), 'Mail was not sended when enable_approve_notification')
88
89    def test_reply_comment_user_notification(self):
90        cleanOutputDir()
91        setProperties(self.prefs, 'enable_reply_user_notification')
92        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
93        self.assert_(not testMailExistance(), 'Mail was sended for simple reply when enable_reply_user_notification')
94
95        reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0]
96        reply.discussion_reply('A Reply for comment' ,'text of reply for comment')
97        reply_for_comment = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0]
98        self.assert_(testMailExistance(), 'Mail was not sended when enable_reply_user_notification')
99
100    def test_rejected_comment_notification(self):
101        cleanOutputDir()
102        setProperties(self.prefs, 'enable_rejected_user_notification', 'enable_moderation')
103        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
104        self.assert_(not testMailExistance(), 'Mail was sended when enable_rejected_user_notification was enabled')
105
106        reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0]
107        self.portal.REQUEST.set('ids', [reply.getId()])
108        self.portal.prefs_recent_comments_delete()
109        self.assert_(testMailExistance(), 'Mail was not sended when enable_rejected_user_notification')
110
111    def test_approve_comment_user__notification(self):
112        cleanOutputDir()
113        setProperties(self.prefs, 'enable_approve_user_notification')
114        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
115        self.assert_(testMailExistance(), 'Mail was not sended when enable_approve_user_notification')
116
117
118TESTS = [TestNotification]
119
120def test_suite():
121    from unittest import TestSuite, makeSuite
122    suite = TestSuite()
123    suite.addTest(makeSuite(TestNotification))
124    return suite
125
126if __name__ == '__main__':
127    framework()
128
Note: See TracBrowser for help on using the repository browser.