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