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