| 1 | # |
|---|
| 2 | # Test configuration form working |
|---|
| 3 | # |
|---|
| 4 | |
|---|
| 5 | from Products.PloneTestCase import PloneTestCase |
|---|
| 6 | from Products.CMFCore.utils import getToolByName |
|---|
| 7 | from Products.CMFCore.permissions import ManagePortal, ReplyToItem |
|---|
| 8 | |
|---|
| 9 | import re |
|---|
| 10 | from helperNotify import * |
|---|
| 11 | from email.Header import Header |
|---|
| 12 | from Products.qPloneComments.utils import getMsg |
|---|
| 13 | |
|---|
| 14 | PRODUCT = 'qPloneComments' |
|---|
| 15 | PROPERTY_SHEET = "qPloneComments" |
|---|
| 16 | |
|---|
| 17 | PloneTestCase.installProduct(PRODUCT) |
|---|
| 18 | PloneTestCase.setupPloneSite() |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | class TestNotification(PloneTestCase.FunctionalTestCase): |
|---|
| 22 | |
|---|
| 23 | def setApprovePublished(self, swithA=1,swithP=1): |
|---|
| 24 | self.prefs._updateProperty('enable_approve_notification', swithA) |
|---|
| 25 | self.prefs._updateProperty('enable_published_notification', swithP) |
|---|
| 26 | |
|---|
| 27 | def afterSetUp(self): |
|---|
| 28 | self.loginAsPortalOwner() |
|---|
| 29 | |
|---|
| 30 | self.qi = self.portal.portal_quickinstaller |
|---|
| 31 | self.qi.installProduct(PRODUCT) |
|---|
| 32 | # VERY IMPORTANT to guarantee product skin's content visibility |
|---|
| 33 | self._refreshSkinData() |
|---|
| 34 | |
|---|
| 35 | '''Preparation for functional testing''' |
|---|
| 36 | self.discussion = getToolByName(self.portal, 'portal_discussion', None) |
|---|
| 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',), 'plone_workflow') |
|---|
| 45 | |
|---|
| 46 | portal_properties = getToolByName(self.portal, 'portal_properties', None) |
|---|
| 47 | self.prefs = portal_properties[PROPERTY_SHEET] |
|---|
| 48 | |
|---|
| 49 | # Add Manager user - 'dm' and add him to Discussion Manager group |
|---|
| 50 | self.portal.portal_membership.addMember('dm', 'secret' , ['Manager'], []) |
|---|
| 51 | portal_groups = getToolByName(self.portal, 'portal_groups') |
|---|
| 52 | dm_group = portal_groups.getGroupById('DiscussionManager') |
|---|
| 53 | dm_group.addMember('dm') |
|---|
| 54 | self.logout() |
|---|
| 55 | self.login('dm') |
|---|
| 56 | # For prepare mail sending - enter an e-mail adress |
|---|
| 57 | self.portal.email_from_address = 'mail@plone.test' |
|---|
| 58 | self.prefs._updateProperty('email_discussion_manager', 'discussion.manager@test.com') |
|---|
| 59 | member = self.portal.portal_membership.getAuthenticatedMember() |
|---|
| 60 | member.setMemberProperties({'email':'creator@test.com'}) |
|---|
| 61 | |
|---|
| 62 | # Add testing document to portal |
|---|
| 63 | my_doc = self.portal.invokeFactory('Document', id='my_doc', title='Doc') |
|---|
| 64 | self.my_doc = self.portal['my_doc'] |
|---|
| 65 | self.my_doc.edit(text_format='plain', text='hello world') |
|---|
| 66 | # Create talkback for document and Prepare REQUEST |
|---|
| 67 | self.discussion.getDiscussionFor(self.my_doc) |
|---|
| 68 | self.request = self.app.REQUEST |
|---|
| 69 | self.request.form['Creator'] = self.portal.portal_membership.getAuthenticatedMember().getUserName() |
|---|
| 70 | self.request.form['subject'] = "Reply 1" |
|---|
| 71 | self.request.form['body_text'] = "text of reply" |
|---|
| 72 | |
|---|
| 73 | prepareMailSendTest() |
|---|
| 74 | |
|---|
| 75 | def test_bug_parent_reply(self): |
|---|
| 76 | setProperties(self.prefs, 'enable_reply_user_notification') |
|---|
| 77 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
|---|
| 78 | parent_reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] |
|---|
| 79 | parent_reply.discussion_reply('reply', 'text') |
|---|
| 80 | |
|---|
| 81 | def test_bug_mistakable_names(self): |
|---|
| 82 | setProperties(self.prefs, 'enable_reply_user_notification') |
|---|
| 83 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
|---|
| 84 | parent_reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] |
|---|
| 85 | |
|---|
| 86 | args={'mto': 'user_email@gmail.com', |
|---|
| 87 | 'mfrom': 'admin_email@gmail.com', |
|---|
| 88 | 'obj': parent_reply, |
|---|
| 89 | 'organization_name': 'org_name', |
|---|
| 90 | 'name': parent_reply.getOwnerTuple()[1]} |
|---|
| 91 | |
|---|
| 92 | msg = getMsg(self.portal, 'reply_notify_template', args) |
|---|
| 93 | patt = re.compile('\\n([^,]*?),\\n\\n') |
|---|
| 94 | m = patt.search(msg) |
|---|
| 95 | if m: |
|---|
| 96 | name = m.group(1) |
|---|
| 97 | self.assertEqual(parent_reply.getOwnerTuple()[1], name) |
|---|
| 98 | else: |
|---|
| 99 | raise "No name" |
|---|
| 100 | |
|---|
| 101 | def test_notificafion_disabled(self): |
|---|
| 102 | cleanOutputDir() |
|---|
| 103 | setProperties(self.prefs) |
|---|
| 104 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
|---|
| 105 | self.assert_(not testMailExistance(), 'Mail was sended when all notification was disabled') |
|---|
| 106 | |
|---|
| 107 | def test_published_comment_notification(self): |
|---|
| 108 | cleanOutputDir() |
|---|
| 109 | setProperties(self.prefs, 'enable_published_notification') |
|---|
| 110 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
|---|
| 111 | self.assert_(testMailExistance(), 'Mail was not sended when enable_published_notification') |
|---|
| 112 | |
|---|
| 113 | def test_approve_comment_notification(self): |
|---|
| 114 | cleanOutputDir() |
|---|
| 115 | setProperties(self.prefs, 'enable_approve_notification') |
|---|
| 116 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
|---|
| 117 | self.assert_(testMailExistance(), 'Mail was not sended when enable_approve_notification') |
|---|
| 118 | |
|---|
| 119 | def test_reply_comment_user_notification(self): |
|---|
| 120 | cleanOutputDir() |
|---|
| 121 | setProperties(self.prefs, 'enable_reply_user_notification') |
|---|
| 122 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
|---|
| 123 | self.assert_(not testMailExistance(), 'Mail was sended for simple reply when enable_reply_user_notification') |
|---|
| 124 | |
|---|
| 125 | reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] |
|---|
| 126 | reply.discussion_reply('A Reply for comment' ,'text of reply for comment') |
|---|
| 127 | reply_for_comment = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] |
|---|
| 128 | self.assert_(testMailExistance(), 'Mail was not sended when enable_reply_user_notification') |
|---|
| 129 | |
|---|
| 130 | def test_rejected_comment_notification(self): |
|---|
| 131 | cleanOutputDir() |
|---|
| 132 | setProperties(self.prefs, 'enable_rejected_user_notification', 'enable_moderation') |
|---|
| 133 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
|---|
| 134 | self.assert_(not testMailExistance(), 'Mail was sended when enable_rejected_user_notification was enabled') |
|---|
| 135 | |
|---|
| 136 | reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] |
|---|
| 137 | self.portal.REQUEST.set('ids', [reply.getId()]) |
|---|
| 138 | self.portal.prefs_recent_comments_delete() |
|---|
| 139 | self.assert_(testMailExistance(), 'Mail was not sended when enable_rejected_user_notification') |
|---|
| 140 | |
|---|
| 141 | def test_approve_comment_user__notification(self): |
|---|
| 142 | cleanOutputDir() |
|---|
| 143 | setProperties(self.prefs, 'enable_approve_user_notification') |
|---|
| 144 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
|---|
| 145 | self.assert_(testMailExistance(), 'Mail was not sended when enable_approve_user_notification') |
|---|
| 146 | |
|---|
| 147 | def test_bug_notification_on_single_reply_publish(self): |
|---|
| 148 | """ Bug: no notification sent on publishing single comment. |
|---|
| 149 | Must be 3 mails: for replier about replying on his commen; |
|---|
| 150 | for replier about publishig his comment; |
|---|
| 151 | for document creator about adding new comment. |
|---|
| 152 | """ |
|---|
| 153 | properties = ['enable_approve_user_notification', 'enable_reply_user_notification', |
|---|
| 154 | 'enable_published_notification'] |
|---|
| 155 | setProperties(self.prefs, *properties) |
|---|
| 156 | #setProperties(self.prefs, 'enable_published_notification', ) |
|---|
| 157 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
|---|
| 158 | reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] |
|---|
| 159 | reply.discussion_reply('A Reply for reply for my_doc' ,'text of reply on reply for my_doc') |
|---|
| 160 | reply2 = self.discussion.getDiscussionFor(reply).getReplies()[0] |
|---|
| 161 | |
|---|
| 162 | cleanOutputDir() |
|---|
| 163 | reply2.discussion_publish_comment() |
|---|
| 164 | mails = getMails() |
|---|
| 165 | self.assert_([1 for m in mails if re.search('^Subject:.*(replied).*$', m, re.I|re.M)] \ |
|---|
| 166 | ,'No notification for reply' % properties) |
|---|
| 167 | self.assert_([1 for m in mails if re.search('^Subject:.*(added).*$', m, re.I|re.M)] \ |
|---|
| 168 | , 'No notification for adding comment' % properties) |
|---|
| 169 | self.assert_([1 for m in mails if re.search('^Subject:.*(published).*$', m, re.I|re.M)] \ |
|---|
| 170 | , 'No notification for publishing comment' % properties) |
|---|
| 171 | |
|---|
| 172 | def test_bug_notification_on_single_reply_delete(self): |
|---|
| 173 | """ Bug: no notification sent on deleting single comment. |
|---|
| 174 | Mail about rejecing comment should be sent to comentator. |
|---|
| 175 | """ |
|---|
| 176 | properties = ['enable_rejected_user_notification',] |
|---|
| 177 | setProperties(self.prefs, *properties) |
|---|
| 178 | #setProperties(self.prefs, 'enable_published_notification', ) |
|---|
| 179 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
|---|
| 180 | reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] |
|---|
| 181 | |
|---|
| 182 | cleanOutputDir() |
|---|
| 183 | reply.deleteDiscussion() |
|---|
| 184 | mails = getMails() |
|---|
| 185 | regexp = re.compile("Subject:\s*(.*?)$",re.M) |
|---|
| 186 | subject = str(Header('Your comment on "Doc" was not approved', 'utf-8')) |
|---|
| 187 | self.assert_([1 for m in mails if regexp.search(m).group(1) == subject] \ |
|---|
| 188 | ,'No notification for rejecting comment' % properties) |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | def test_suite(): |
|---|
| 192 | from unittest import TestSuite, makeSuite |
|---|
| 193 | suite = TestSuite() |
|---|
| 194 | suite.addTest(makeSuite(TestNotification)) |
|---|
| 195 | return suite |
|---|