[1] | 1 | # |
---|
| 2 | # Test configuration form working |
---|
| 3 | # |
---|
| 4 | |
---|
| 5 | import os, sys, string |
---|
| 6 | if __name__ == '__main__': |
---|
| 7 | execfile(os.path.join(sys.path[0], 'framework.py')) |
---|
| 8 | |
---|
| 9 | from Products.PloneTestCase import PloneTestCase |
---|
| 10 | from Products.CMFCore.utils import getToolByName |
---|
| 11 | from Products.CMFCore.CMFCorePermissions import ManagePortal, ReplyToItem |
---|
| 12 | import socket |
---|
| 13 | |
---|
| 14 | PRODUCT = 'qPloneComments' |
---|
| 15 | PROPERTY_SHEET = "qPloneComments" |
---|
| 16 | |
---|
| 17 | USERS = {# 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 | } |
---|
| 28 | COMMON_USERS_IDS = [u for u in USERS.keys() if not u.startswith('dm_')] |
---|
| 29 | COMMON_USERS_IDS.append('anonym') |
---|
| 30 | DM_USERS_IDS = [u for u in USERS.keys() if u.startswith('dm_')] |
---|
| 31 | |
---|
| 32 | PloneTestCase.installProduct(PRODUCT) |
---|
| 33 | PloneTestCase.setupPloneSite() |
---|
| 34 | |
---|
| 35 | def addUsers(self): |
---|
| 36 | self.loginAsPortalOwner() |
---|
| 37 | # Add all users |
---|
| 38 | self.membership = getToolByName(self.portal, 'portal_membership', None) |
---|
| 39 | for user_id in USERS.keys(): |
---|
| 40 | self.membership.addMember(user_id, USERS[user_id]['passw'] , USERS[user_id]['roles'], []) |
---|
| 41 | |
---|
| 42 | # Add users to Discussion Manager group |
---|
| 43 | portal_groups = getToolByName(self.portal, 'portal_groups') |
---|
| 44 | #portal_groups.addGroup('DiscussionManager', roles=['DiscussionManager']) |
---|
| 45 | dm_group = portal_groups.getGroupById(id='DiscussionManager') |
---|
| 46 | dm_users = [dm_group.addMember(u) for u in DM_USERS_IDS] |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | class 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 | # Add testing document to portal |
---|
| 66 | my_doc = self.portal.invokeFactory('Document', id='my_doc') |
---|
| 67 | self.my_doc = self.portal['my_doc'] |
---|
| 68 | self.my_doc.edit(text_format='plain', text='hello world') |
---|
| 69 | |
---|
| 70 | portal_properties = getToolByName(self.portal, 'portal_properties', None) |
---|
| 71 | self.prefs = portal_properties[PROPERTY_SHEET] |
---|
| 72 | self.request = self.app.REQUEST |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | def testAnonymousCommenting(self): |
---|
| 76 | getPortalReplyPerm = self.portal.rolesOfPermission |
---|
| 77 | def getReplyRoles(): |
---|
| 78 | return [r['name'] for r in getPortalReplyPerm(ReplyToItem) if r['selected']=='SELECTED'] |
---|
| 79 | # Simulate switching ON Anonymous Commenting |
---|
| 80 | self.request.form['Enable_Anonymous_Commenting'] = 'True' |
---|
| 81 | self.portal.prefs_comments_setup() |
---|
| 82 | actual_reply_permission = getReplyRoles() |
---|
| 83 | self.assert_('Anonymous' in actual_reply_permission, \ |
---|
| 84 | "'Reply to Item' permission set for %s. 'Anonymous' role NOT added" % actual_reply_permission) |
---|
| 85 | # Simulate switching OFF Anonymous Commenting |
---|
| 86 | if self.request.form.has_key('Enable_Anonymous_Commenting'): |
---|
| 87 | del self.request.form['Enable_Anonymous_Commenting'] |
---|
| 88 | self.portal.prefs_comments_setup() |
---|
| 89 | actual_reply_permission = getReplyRoles() |
---|
| 90 | self.assert_(not 'Anonymous' in actual_reply_permission, \ |
---|
| 91 | "'Reply to Item' permission set for %s. 'Anonymous' role NOT erased" % actual_reply_permission) |
---|
| 92 | |
---|
| 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 | getReplies = self.discussion.getDiscussionFor(self.my_doc).getReplies |
---|
| 107 | for u in DM_USERS_IDS: |
---|
| 108 | self.logout() |
---|
| 109 | self.login(u) |
---|
| 110 | self.assert_(getReplies(), "None discussion item added or discussion forbiden for %s user" % u) |
---|
| 111 | for u in COMMON_USERS_IDS: |
---|
| 112 | self.logout() |
---|
| 113 | if not u=='anonym': |
---|
| 114 | self.login(u) |
---|
| 115 | self.assert_(not getReplies(), "Viewing discussion item allow for Anonymous user") |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | def testSwitchOFFModeration(self): |
---|
| 119 | addUsers(self) |
---|
| 120 | self.discussion = self.portal.portal_discussion |
---|
| 121 | self.request.form['Enable_Anonymous_Commenting'] = 'True' |
---|
| 122 | self.portal.prefs_comments_setup() |
---|
| 123 | # Create talkback for document and Add comment to my_doc |
---|
| 124 | self.discussion.getDiscussionFor(self.my_doc) |
---|
| 125 | self.request.form['Creator'] = self.portal.portal_membership.getAuthenticatedMember().getUserName() |
---|
| 126 | self.request.form['subject'] = "Reply 1" |
---|
| 127 | self.request.form['body_text'] = "text of reply" |
---|
| 128 | self.my_doc.discussion_reply('Reply 1','text of reply') |
---|
| 129 | # Check moderating discussion |
---|
| 130 | # MUST ALLOW for: user with any role or Anonym |
---|
| 131 | all_users_ids = DM_USERS_IDS + COMMON_USERS_IDS |
---|
| 132 | for u in all_users_ids: |
---|
| 133 | self.logout() |
---|
| 134 | if not u=='anonym': |
---|
| 135 | self.login(u) |
---|
| 136 | replies = self.discussion.getDiscussionFor(self.my_doc).getReplies() |
---|
| 137 | self.assert_(replies, "No discussion item added or discussion forbidden for %s user" % u) |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | def testNotification(self): |
---|
| 141 | # For prepare mail sending - enter an e-mail adress |
---|
| 142 | self.prefs._updateProperty('Email_Discussion_Manager', 'wrong_email_addr') |
---|
| 143 | # Create talkback for document and Prepare REQUEST |
---|
| 144 | self.portal.portal_discussion.getDiscussionFor(self.my_doc) |
---|
| 145 | self.request.form['Creator'] = self.portal.portal_membership.getAuthenticatedMember().getUserName() |
---|
| 146 | self.request.form['subject'] = "Reply 1" |
---|
| 147 | self.request.form['body_text'] = "text of reply" |
---|
| 148 | |
---|
| 149 | # Check Notification ON |
---|
| 150 | self.assert_(self.prefs.getProperty('Enable_Notification')==1,"Notification not terned ON") |
---|
| 151 | self.assertRaises(socket.error, self.my_doc.discussion_reply, 'Reply 1', 'text of reply') |
---|
| 152 | # Check Notification OFF |
---|
| 153 | self.prefs._updateProperty('Enable_Notification', 0) |
---|
| 154 | self.assert_(self.prefs.getProperty('Enable_Notification')==0,"Notification not terned Off") |
---|
| 155 | try: |
---|
| 156 | self.my_doc.discussion_reply('Reply 1','text of reply') |
---|
| 157 | except socket.error: |
---|
| 158 | self.fail("Terning notification Off NOT work") |
---|
| 159 | |
---|
| 160 | |
---|
| 161 | TESTS = [TestConfiglet] |
---|
| 162 | |
---|
| 163 | def test_suite(): |
---|
| 164 | from unittest import TestSuite, makeSuite |
---|
| 165 | suite = TestSuite() |
---|
| 166 | suite.addTest(makeSuite(TestConfiglet)) |
---|
| 167 | return suite |
---|
| 168 | |
---|
| 169 | if __name__ == '__main__': |
---|
| 170 | framework() |
---|
| 171 | |
---|