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