1 | # |
---|
2 | # Test configuration form working |
---|
3 | # |
---|
4 | |
---|
5 | from Products.CMFCore.permissions import ReplyToItem |
---|
6 | from AccessControl.SecurityManagement import noSecurityManager |
---|
7 | from base import getToolByName, FunctionalTestCase |
---|
8 | from config import USERS, PROPERTY_SHEET, DM_USERS_IDS, COMMON_USERS_IDS |
---|
9 | |
---|
10 | |
---|
11 | def addUsers(self): |
---|
12 | self.loginAsPortalOwner() |
---|
13 | # Add all users |
---|
14 | self.membership = getToolByName(self.portal, 'portal_membership', None) |
---|
15 | for user_id in USERS.keys(): |
---|
16 | self.membership.addMember(user_id, USERS[user_id]['passw'], |
---|
17 | USERS[user_id]['roles'], []) |
---|
18 | |
---|
19 | # Add users to Discussion Manager group |
---|
20 | portal_groups = getToolByName(self.portal, 'portal_groups') |
---|
21 | dm_group = portal_groups.getGroupById('DiscussionManager') |
---|
22 | dm_users = [dm_group.addMember(u) for u in DM_USERS_IDS] |
---|
23 | |
---|
24 | |
---|
25 | class TestConfiglet(FunctionalTestCase): |
---|
26 | |
---|
27 | def getDiscussionReplies(self, obj): |
---|
28 | return self.discussion.getDiscussionFor(obj).getReplies() |
---|
29 | |
---|
30 | def afterSetUp(self): |
---|
31 | self.loginAsPortalOwner() |
---|
32 | |
---|
33 | # VERY IMPORTANT to guarantee product skin's content visibility |
---|
34 | self._refreshSkinData() |
---|
35 | |
---|
36 | '''Preparation for functional testing''' |
---|
37 | # Allow discussion for Document |
---|
38 | portal_types = getToolByName(self.portal, 'portal_types', None) |
---|
39 | doc_fti = portal_types.getTypeInfo('Document') |
---|
40 | doc_fti._updateProperty('allow_discussion', 1) |
---|
41 | |
---|
42 | # Make sure Documents are visible by default |
---|
43 | # XXX only do this for plone 3 |
---|
44 | self.portal.portal_workflow.setChainForPortalTypes(('Document',), |
---|
45 | 'plone_workflow') |
---|
46 | |
---|
47 | portal_properties = getToolByName(self.portal, 'portal_properties', |
---|
48 | None) |
---|
49 | self.prefs = portal_properties[PROPERTY_SHEET] |
---|
50 | self.request = self.app.REQUEST |
---|
51 | |
---|
52 | # Add Manager user - 'dm' and add him to Discussion Manager group |
---|
53 | self.portal.portal_membership.addMember('dm', 'secret', |
---|
54 | ['Manager'], []) |
---|
55 | portal_groups = getToolByName(self.portal, 'portal_groups') |
---|
56 | dm_group = portal_groups.getGroupById('DiscussionManager') |
---|
57 | dm_group.addMember('dm') |
---|
58 | #self.logout() |
---|
59 | self.login('dm') |
---|
60 | # For prepare mail sending - enter an e-mail adress |
---|
61 | self.prefs._updateProperty('email_discussion_manager', |
---|
62 | 'discussion.manager@test.com') |
---|
63 | member = self.portal.portal_membership.getAuthenticatedMember() |
---|
64 | member.setMemberProperties({'email': 'creator@test.com'}) |
---|
65 | #self.fail(member.getMemberId()+' :: '+member.getUserName()+' \ |
---|
66 | # :: '+str(member.getRoles())+' :: '+member.getProperty('email')) |
---|
67 | |
---|
68 | # Add testing document to portal |
---|
69 | my_doc = self.portal.invokeFactory('Document', id='my_doc') |
---|
70 | self.my_doc = self.portal['my_doc'] |
---|
71 | self.my_doc.edit(text_format='plain', text='hello world') |
---|
72 | |
---|
73 | def testAnonymousCommenting(self): |
---|
74 | def getReplyRoles(): |
---|
75 | return [r['name'] |
---|
76 | for r in self.portal.rolesOfPermission(ReplyToItem) |
---|
77 | if r['selected'] == 'SELECTED'] |
---|
78 | # Simulate switching ON Anonymous Commenting |
---|
79 | self.request.form['enable_anonymous_commenting'] = 'True' |
---|
80 | self.portal.prefs_comments_setup() |
---|
81 | actual_reply_permission = getReplyRoles() |
---|
82 | self.failUnless('Anonymous' in actual_reply_permission, \ |
---|
83 | "'Reply to Item' permission set for %s. 'Anonymous' " |
---|
84 | "role NOT added" % actual_reply_permission) |
---|
85 | # Simulate switching OFF Anonymous Commenting |
---|
86 | if 'enable_anonymous_commenting' in self.request.form: |
---|
87 | del self.request.form['enable_anonymous_commenting'] |
---|
88 | self.portal.prefs_comments_setup() |
---|
89 | actual_reply_permission = getReplyRoles() |
---|
90 | self.failIf('Anonymous' in actual_reply_permission, \ |
---|
91 | "'Reply to Item' permission set for %s. 'Anonymous' role " |
---|
92 | "NOT erased" % actual_reply_permission) |
---|
93 | |
---|
94 | def testSwitchONModeration(self): |
---|
95 | addUsers(self) |
---|
96 | self.discussion = self.portal.portal_discussion |
---|
97 | self.request.form['enable_anonymous_commenting'] = 'True' |
---|
98 | self.request.form['enable_moderation'] = 'True' |
---|
99 | self.portal.prefs_comments_setup() |
---|
100 | # Create talkback for document and Add comment to my_doc |
---|
101 | self.discussion.getDiscussionFor(self.my_doc) |
---|
102 | self.my_doc.discussion_reply('Reply 1', 'text of reply') |
---|
103 | # Check moderating discussion |
---|
104 | # MUST ALLOW for: members of 'DiscussionMnagers' group |
---|
105 | # MUST REFUSE for: NOT members of 'DiscussionMnagers' group |
---|
106 | for u in DM_USERS_IDS: |
---|
107 | self.logout() |
---|
108 | self.login(u) |
---|
109 | self.failUnless(self.getDiscussionReplies(self.my_doc), |
---|
110 | "None discussion item added or discussion" |
---|
111 | " forbiden for %s user" % u) |
---|
112 | for u in COMMON_USERS_IDS: |
---|
113 | self.logout() |
---|
114 | if not u == 'anonym': |
---|
115 | self.login(u) |
---|
116 | noSecurityManager() |
---|
117 | self.failIf(self.getDiscussionReplies(self.my_doc), |
---|
118 | "Viewing discussion item allow for Anonymous user") |
---|
119 | |
---|
120 | def testSwitchOFFModeration(self): |
---|
121 | addUsers(self) |
---|
122 | self.discussion = self.portal.portal_discussion |
---|
123 | self.request.form['enable_anonymous_commenting'] = 'True' |
---|
124 | self.portal.prefs_comments_setup() |
---|
125 | # Create talkback for document and Add comment to my_doc |
---|
126 | self.discussion.getDiscussionFor(self.my_doc) |
---|
127 | authmember = self.portal.portal_membership.getAuthenticatedMember() |
---|
128 | self.request.form['Creator'] = authmember.getUserName() |
---|
129 | self.request.form['subject'] = "Reply 1" |
---|
130 | self.request.form['body_text'] = "text of reply" |
---|
131 | self.my_doc.discussion_reply('Reply 1', 'text of reply') |
---|
132 | # Check moderating discussion |
---|
133 | # MUST ALLOW for: user with any role or Anonym |
---|
134 | all_users_ids = DM_USERS_IDS + COMMON_USERS_IDS |
---|
135 | for u in all_users_ids: |
---|
136 | self.logout() |
---|
137 | if not u == 'anonym': |
---|
138 | self.login(u) |
---|
139 | replies = self.getDiscussionReplies(self.my_doc) |
---|
140 | self.failUnless(replies, |
---|
141 | "No discussion item added or discussion" |
---|
142 | " forbidden for %s user" % u) |
---|
143 | |
---|
144 | def testApproveNotification(self): |
---|
145 | # Check ON Notification Anonymous Commenting |
---|
146 | self.request.form['enable_approve_notification'] = 'True' |
---|
147 | self.portal.prefs_comments_setup() |
---|
148 | getProp = self.prefs.getProperty |
---|
149 | self.failUnless(getProp('enable_approve_notification') == 1, |
---|
150 | "Approve Notification not terned ON") |
---|
151 | |
---|
152 | # Check OFF Notification Anonymous Commenting |
---|
153 | if 'enable_approve_notification' in self.request.form: |
---|
154 | del self.request.form['enable_approve_notification'] |
---|
155 | self.portal.prefs_comments_setup() |
---|
156 | self.failUnless(getProp('enable_approve_notification') == 0, |
---|
157 | "Approve Notification not terned OFF") |
---|
158 | |
---|
159 | def testPublishedNotification(self): |
---|
160 | # Check ON Notification Anonymous Commenting |
---|
161 | self.request.form['enable_published_notification'] = 'True' |
---|
162 | self.portal.prefs_comments_setup() |
---|
163 | getProp = self.prefs.getProperty |
---|
164 | self.failUnless(getProp('enable_published_notification') == 1, |
---|
165 | "Published Notification not terned ON") |
---|
166 | |
---|
167 | # Check OFF Notification Anonymous Commenting |
---|
168 | if 'enable_published_notification' in self.request.form: |
---|
169 | del self.request.form['enable_published_notification'] |
---|
170 | self.portal.prefs_comments_setup() |
---|
171 | self.failUnless(getProp('enable_published_notification') == 0, |
---|
172 | "Published Notification not terned OFF") |
---|
173 | |
---|
174 | |
---|
175 | def test_suite(): |
---|
176 | from unittest import TestSuite, makeSuite |
---|
177 | suite = TestSuite() |
---|
178 | suite.addTest(makeSuite(TestConfiglet)) |
---|
179 | return suite |
---|