source: products/qPloneComments/branches/plone205-21merge/tests/testQPloneCommentsConfiglet.py @ 1

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

Building directory structure

File size: 8.5 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
13
14PRODUCT = 'qPloneComments'
15PROPERTY_SHEET = "qPloneComments"
16
17USERS = {# Common Members
18         'admin':{'passw': 'secret_admin', 'roles': ['Manager']},
19         'owner':{'passw': 'secret_owner', 'roles': ['Owner']},
20         'member':{'passw': 'secret_member', 'roles': ['Member']},
21         'reviewer':{'passw': 'secret_reviewer', 'roles': ['Reviewer']},
22         # Members for discussion manager group
23         'dm_admin':{'passw': 'secret_dm_admin', 'roles': ['Manager']},
24         'dm_owner':{'passw': 'secret_dm_owner', 'roles': ['Owner']},
25         'dm_member':{'passw': 'secret_dm_member', 'roles': ['Member']},
26         'dm_reviewer':{'passw': 'secret_dm_reviewer', 'roles': ['Reviewer']},
27        }
28COMMON_USERS_IDS = [u for u in USERS.keys() if not u.startswith('dm_')]
29COMMON_USERS_IDS.append('anonym')
30DM_USERS_IDS = [u for u in USERS.keys() if u.startswith('dm_')]
31
32PloneTestCase.installProduct(PRODUCT)
33PloneTestCase.setupPloneSite()
34
35
36def addUsers(self):
37    self.loginAsPortalOwner()
38    # Add all users
39    self.membership = getToolByName(self.portal, 'portal_membership', None)
40    for user_id in USERS.keys():
41        self.membership.addMember(user_id, USERS[user_id]['passw'] , USERS[user_id]['roles'], [])
42   
43    # Add users to Discussion Manager group
44    portal_groups = getToolByName(self.portal, 'portal_groups')
45    dm_group = portal_groups.getGroupById(id='DiscussionManager')
46    dm_users = [dm_group.addMember(u) for u in DM_USERS_IDS]
47
48
49class TestConfiglet(PloneTestCase.FunctionalTestCase):
50
51    def afterSetUp(self):
52        self.loginAsPortalOwner()
53
54        self.qi = self.portal.portal_quickinstaller
55        self.qi.installProduct(PRODUCT)
56        # VERY IMPORTANT to guarantee product skin's content visibility
57        self._refreshSkinData()
58
59        '''Preparation for functional testing'''
60        # Allow discussion for Document
61        portal_types = getToolByName(self.portal, 'portal_types', None)
62        doc_fti = portal_types.getTypeInfo('Document')
63        doc_fti._updateProperty('allow_discussion', 1)
64
65        portal_properties = getToolByName(self.portal, 'portal_properties', None)
66        self.prefs = portal_properties[PROPERTY_SHEET]
67        self.request = self.app.REQUEST
68
69        # Add Manager user - 'dm' and add him to Discussion Manager group
70        self.portal.portal_membership.addMember('dm', 'secret' , ['Manager'], [])
71        portal_groups = getToolByName(self.portal, 'portal_groups')
72        dm_group = portal_groups.getGroupById(id='DiscussionManager')
73        dm_group.addMember('dm')
74        #self.logout()
75        self.login('dm')
76        # For prepare mail sending - enter an e-mail adress
77        self.prefs._updateProperty('email_discussion_manager', 'discussion.manager@test.com')
78        member = self.portal.portal_membership.getAuthenticatedMember()
79        member.setMemberProperties({'email':'creator@test.com'})
80        #self.fail(member.getMemberId()+' :: '+member.getUserName()+' :: '+str(member.getRoles())+' :: '+member.getProperty('email'))
81       
82        # Add testing document to portal
83        my_doc = self.portal.invokeFactory('Document', id='my_doc')
84        self.my_doc = self.portal['my_doc']
85        self.my_doc.edit(text_format='plain', text='hello world')
86
87
88    def testAnonymousCommenting(self):
89        getPortalReplyPerm = self.portal.rolesOfPermission
90        def getReplyRoles():
91            return [r['name'] for r in getPortalReplyPerm(ReplyToItem) if r['selected']=='SELECTED']
92        # Simulate switching ON Anonymous Commenting
93        self.request.form['enable_anonymous_commenting'] = 'True'
94        self.portal.prefs_comments_setup()
95        actual_reply_permission = getReplyRoles()
96        self.assert_('Anonymous' in actual_reply_permission, \
97                     "'Reply to Item' permission set for %s. 'Anonymous' role NOT added" %  actual_reply_permission)
98        # Simulate switching OFF Anonymous Commenting
99        if self.request.form.has_key('enable_anonymous_commenting'):
100           del self.request.form['enable_anonymous_commenting']
101        self.portal.prefs_comments_setup()
102        actual_reply_permission = getReplyRoles()
103        self.assert_(not 'Anonymous' in actual_reply_permission, \
104                     "'Reply to Item' permission set for %s. 'Anonymous' role NOT erased" %  actual_reply_permission)
105
106
107    def testSwitchONModeration(self):
108        addUsers(self)
109        self.discussion = self.portal.portal_discussion
110        self.request.form['enable_anonymous_commenting'] = 'True'
111        self.request.form['enable_moderation'] = 'True'
112        self.portal.prefs_comments_setup()
113        # Create talkback for document and Add comment to my_doc
114        self.discussion.getDiscussionFor(self.my_doc)
115        self.my_doc.discussion_reply('Reply 1','text of reply')
116        # Check moderating discussion
117        # MUST ALLOW for: members of 'DiscussionMnagers' group
118        # MUST REFUSE for: NOT members of 'DiscussionMnagers' group
119        getReplies = self.discussion.getDiscussionFor(self.my_doc).getReplies
120        for u in DM_USERS_IDS:
121            self.logout()
122            self.login(u)
123            self.assert_(getReplies(), "None discussion item added or discussion forbiden for %s user" % u)
124        for u in COMMON_USERS_IDS:
125            self.logout()
126            if not u=='anonym':
127                self.login(u)
128            self.assert_(not getReplies(), "Viewing discussion item allow for Anonymous user")
129
130       
131    def testSwitchOFFModeration(self):
132        addUsers(self)
133        self.discussion = self.portal.portal_discussion
134        self.request.form['enable_anonymous_commenting'] = 'True'
135        self.portal.prefs_comments_setup()
136        # Create talkback for document and Add comment to my_doc
137        self.discussion.getDiscussionFor(self.my_doc)
138        self.request.form['Creator'] = self.portal.portal_membership.getAuthenticatedMember().getUserName()
139        self.request.form['subject'] = "Reply 1"
140        self.request.form['body_text'] = "text of reply"
141        self.my_doc.discussion_reply('Reply 1','text of reply')
142        # Check moderating discussion
143        # MUST ALLOW for: user with any role or Anonym
144        all_users_ids = DM_USERS_IDS + COMMON_USERS_IDS
145        for u in all_users_ids:
146            self.logout()
147            if not u=='anonym':
148                self.login(u)
149            replies = self.discussion.getDiscussionFor(self.my_doc).getReplies()
150            self.assert_(replies, "No discussion item added or discussion forbidden for %s user" % u)
151
152
153    def testApproveNotification(self):
154        # Check ON Notification Anonymous Commenting
155        self.request.form['enable_approve_notification'] = 'True'
156        self.portal.prefs_comments_setup()
157        self.assert_(self.prefs.getProperty('enable_approve_notification')==1,"Approve Notification not terned ON")
158
159        # Check OFF Notification Anonymous Commenting
160        if self.request.form.has_key('enable_approve_notification'):
161           del self.request.form['enable_approve_notification']
162        self.portal.prefs_comments_setup()
163        self.assert_(self.prefs.getProperty('enable_approve_notification')==0,"Approve Notification not terned OFF")
164
165
166    def testPublishedNotification(self):
167        # Check ON Notification Anonymous Commenting
168        self.request.form['enable_published_notification'] = 'True'
169        self.portal.prefs_comments_setup()
170        self.assert_(self.prefs.getProperty('enable_published_notification')==1,"Published Notification not terned ON")
171
172        # Check OFF Notification Anonymous Commenting
173        if self.request.form.has_key('enable_published_notification'):
174           del self.request.form['enable_published_notification']
175        self.portal.prefs_comments_setup()
176        self.assert_(self.prefs.getProperty('enable_published_notification')==0,"Published Notification not terned OFF")
177
178
179
180TESTS = [TestConfiglet]
181
182def test_suite():
183    from unittest import TestSuite, makeSuite
184    suite = TestSuite()
185    suite.addTest(makeSuite(TestConfiglet))
186    return suite
187
188if __name__ == '__main__':
189    framework()
190
Note: See TracBrowser for help on using the repository browser.