[832] | 1 | # |
---|
| 2 | # Test configuration form working |
---|
| 3 | # |
---|
[3107] | 4 | |
---|
| 5 | from Products.CMFCore.utils import getToolByName |
---|
[880] | 6 | import re |
---|
[3107] | 7 | from helperNotify import setProperties, testMailExistance |
---|
[832] | 8 | from quintagroup.plonecomments.utils import getMsg |
---|
[3110] | 9 | from quintagroup.plonecomments.tests.base import FunctionalTestCase |
---|
| 10 | from quintagroup.plonecomments.tests.config import PROPERTY_SHEET |
---|
[1633] | 11 | from Products.CMFPlone.tests.utils import MockMailHost |
---|
[880] | 12 | |
---|
[2137] | 13 | REXP_TO = re.compile("To:\s*(.*?)$", re.M) |
---|
| 14 | REXP_SUBJ = re.compile("Subject:\s*(.*?)$", re.M) |
---|
[1633] | 15 | |
---|
| 16 | |
---|
[832] | 17 | class TestNotification(FunctionalTestCase): |
---|
| 18 | |
---|
[2137] | 19 | def getDiscussionReplies(self, obj): |
---|
| 20 | return self.discussion.getDiscussionFor(obj).getReplies() |
---|
| 21 | |
---|
| 22 | def setApprovePublished(self, swithA=1, swithP=1): |
---|
[832] | 23 | self.prefs._updateProperty('enable_approve_notification', swithA) |
---|
| 24 | self.prefs._updateProperty('enable_published_notification', swithP) |
---|
| 25 | |
---|
[1633] | 26 | def beforeTearDown(self): |
---|
| 27 | self.portal.MailHost = self.portal._original_MailHost |
---|
| 28 | |
---|
[832] | 29 | def afterSetUp(self): |
---|
[1633] | 30 | self.portal._original_MailHost = self.portal.MailHost |
---|
[3107] | 31 | self.portal.MailHost = MockMailHost('MailHost') |
---|
[1633] | 32 | |
---|
[832] | 33 | self.loginAsPortalOwner() |
---|
| 34 | |
---|
| 35 | # VERY IMPORTANT to guarantee product skin's content visibility |
---|
| 36 | self._refreshSkinData() |
---|
| 37 | |
---|
| 38 | '''Preparation for functional testing''' |
---|
| 39 | self.discussion = getToolByName(self.portal, 'portal_discussion', None) |
---|
| 40 | # Allow discussion for Document |
---|
| 41 | portal_types = getToolByName(self.portal, 'portal_types', None) |
---|
| 42 | doc_fti = portal_types.getTypeInfo('Document') |
---|
| 43 | doc_fti._updateProperty('allow_discussion', 1) |
---|
| 44 | |
---|
| 45 | # Make sure Documents are visible by default |
---|
| 46 | # XXX only do this for plone 3 |
---|
[2137] | 47 | self.portal.portal_workflow.setChainForPortalTypes(('Document',), |
---|
| 48 | 'plone_workflow') |
---|
[832] | 49 | |
---|
[2137] | 50 | portal_properties = getToolByName(self.portal, 'portal_properties', |
---|
| 51 | None) |
---|
[832] | 52 | self.prefs = portal_properties[PROPERTY_SHEET] |
---|
| 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 |
---|
| 63 | self.portal.email_from_address = 'mail@plone.test' |
---|
[2137] | 64 | self.prefs._updateProperty('email_discussion_manager', |
---|
| 65 | 'discussion.manager@test.com') |
---|
[832] | 66 | member = self.portal.portal_membership.getAuthenticatedMember() |
---|
[2137] | 67 | member.setMemberProperties({'email': 'creator@test.com'}) |
---|
[832] | 68 | |
---|
| 69 | # Add testing document to portal |
---|
[3107] | 70 | self.portal.invokeFactory('Document', id='my_doc', title='Doc') |
---|
[832] | 71 | self.my_doc = self.portal['my_doc'] |
---|
| 72 | self.my_doc.edit(text_format='plain', text='hello world') |
---|
| 73 | # Create talkback for document and Prepare REQUEST |
---|
| 74 | self.discussion.getDiscussionFor(self.my_doc) |
---|
| 75 | self.request = self.app.REQUEST |
---|
[2137] | 76 | authmember = self.portal.portal_membership.getAuthenticatedMember() |
---|
| 77 | self.request.form['Creator'] = authmember.getUserName() |
---|
[832] | 78 | self.request.form['subject'] = "Reply 1" |
---|
| 79 | self.request.form['body_text'] = "text of reply" |
---|
| 80 | |
---|
[1633] | 81 | #prepareMailSendTest() |
---|
[832] | 82 | |
---|
| 83 | def test_bug_parent_reply(self): |
---|
| 84 | setProperties(self.prefs, 'enable_reply_user_notification') |
---|
[2137] | 85 | self.my_doc.discussion_reply('A Reply for my_doc', |
---|
| 86 | 'text of reply for my_doc') |
---|
| 87 | parent_reply = self.getDiscussionReplies(self.my_doc)[0] |
---|
[832] | 88 | parent_reply.discussion_reply('reply', 'text') |
---|
| 89 | |
---|
| 90 | def test_bug_mistakable_names(self): |
---|
| 91 | setProperties(self.prefs, 'enable_reply_user_notification') |
---|
[2137] | 92 | self.my_doc.discussion_reply('A Reply for my_doc', |
---|
| 93 | 'text of reply for my_doc') |
---|
| 94 | parent_reply = self.getDiscussionReplies(self.my_doc)[0] |
---|
[832] | 95 | |
---|
[2137] | 96 | args = {'mto': 'user_email@gmail.com', |
---|
| 97 | 'mfrom': 'admin_email@gmail.com', |
---|
| 98 | 'obj': parent_reply, |
---|
| 99 | 'organization_name': 'org_name', |
---|
| 100 | 'name': parent_reply.getOwnerTuple()[1]} |
---|
[832] | 101 | |
---|
| 102 | msg = getMsg(self.portal, 'reply_notify_template', args) |
---|
| 103 | patt = re.compile('\\n([^,]*?),\\n\\n') |
---|
| 104 | m = patt.search(msg) |
---|
| 105 | if m: |
---|
| 106 | name = m.group(1) |
---|
| 107 | self.assertEqual(parent_reply.getOwnerTuple()[1], name) |
---|
| 108 | else: |
---|
| 109 | raise "No name" |
---|
| 110 | |
---|
| 111 | def test_notificafion_disabled(self): |
---|
[1633] | 112 | self.portal.MailHost.reset() |
---|
[832] | 113 | setProperties(self.prefs) |
---|
[2137] | 114 | self.my_doc.discussion_reply('A Reply for my_doc', |
---|
| 115 | 'text of reply for my_doc') |
---|
| 116 | self.failIf(testMailExistance(self), |
---|
| 117 | 'Mail was sended when all notification was disabled.') |
---|
[832] | 118 | |
---|
| 119 | def test_published_comment_notification(self): |
---|
[1633] | 120 | self.portal.MailHost.reset() |
---|
[832] | 121 | setProperties(self.prefs, 'enable_published_notification') |
---|
[2137] | 122 | self.my_doc.discussion_reply('A Reply for my_doc', |
---|
| 123 | 'text of reply for my_doc') |
---|
| 124 | self.failUnless(testMailExistance(self), |
---|
| 125 | 'Mail was not sended when enable_published_notification.') |
---|
[832] | 126 | |
---|
| 127 | def test_approve_comment_notification(self): |
---|
[1633] | 128 | self.portal.MailHost.reset() |
---|
[832] | 129 | setProperties(self.prefs, 'enable_approve_notification') |
---|
[2137] | 130 | self.my_doc.discussion_reply('A Reply for my_doc', |
---|
| 131 | 'text of reply for my_doc') |
---|
| 132 | self.failUnless(testMailExistance(self), |
---|
| 133 | 'Mail was not sended when enable_approve_notification.') |
---|
[832] | 134 | |
---|
| 135 | def test_reply_comment_user_notification(self): |
---|
[1633] | 136 | self.portal.MailHost.reset() |
---|
[832] | 137 | setProperties(self.prefs, 'enable_reply_user_notification') |
---|
[2137] | 138 | self.my_doc.discussion_reply('A Reply for my_doc', |
---|
| 139 | 'text of reply for my_doc') |
---|
| 140 | self.failIf(testMailExistance(self), |
---|
| 141 | 'Mail was sended for simple reply ' |
---|
| 142 | 'when enable_reply_user_notification.') |
---|
[832] | 143 | |
---|
[2137] | 144 | reply = self.getDiscussionReplies(self.my_doc)[0] |
---|
| 145 | reply.discussion_reply('A Reply for comment', |
---|
| 146 | 'text of reply for comment') |
---|
| 147 | self.failUnless(testMailExistance(self), |
---|
| 148 | 'Mail was not sended when enable_reply_user_notification.') |
---|
[832] | 149 | |
---|
| 150 | def test_rejected_comment_notification(self): |
---|
[1633] | 151 | self.portal.MailHost.reset() |
---|
[2137] | 152 | setProperties(self.prefs, 'enable_rejected_user_notification', |
---|
| 153 | 'enable_moderation') |
---|
| 154 | self.my_doc.discussion_reply('A Reply for my_doc', |
---|
| 155 | 'text of reply for my_doc') |
---|
| 156 | self.failIf(testMailExistance(self), |
---|
| 157 | 'Mail was sended when enable_rejected_user_notification' |
---|
| 158 | ' was enabled.') |
---|
[832] | 159 | |
---|
[2137] | 160 | reply = self.getDiscussionReplies(self.my_doc)[0] |
---|
[832] | 161 | self.portal.REQUEST.set('ids', [reply.getId()]) |
---|
| 162 | self.portal.prefs_recent_comments_delete() |
---|
[2137] | 163 | self.failUnless(testMailExistance(self), |
---|
| 164 | 'Mail was not sended when enable_rejected_user_notification.') |
---|
[832] | 165 | |
---|
| 166 | def test_approve_comment_user__notification(self): |
---|
[1633] | 167 | self.portal.MailHost.reset() |
---|
[832] | 168 | setProperties(self.prefs, 'enable_approve_user_notification') |
---|
[2137] | 169 | self.my_doc.discussion_reply('A Reply for my_doc', |
---|
| 170 | 'text of reply for my_doc') |
---|
| 171 | self.failUnless(testMailExistance(self), |
---|
| 172 | 'Mail was not sended when enable_approve_user_notification.') |
---|
[832] | 173 | |
---|
| 174 | def test_bug_notification_on_single_reply_publish(self): |
---|
| 175 | """ Bug: no notification sent on publishing single comment. |
---|
| 176 | Must be 3 mails: for replier about replying on his commen; |
---|
| 177 | for replier about publishig his comment; |
---|
| 178 | for document creator about adding new comment. |
---|
| 179 | """ |
---|
[2137] | 180 | properties = ['enable_approve_user_notification', |
---|
| 181 | 'enable_reply_user_notification', |
---|
[832] | 182 | 'enable_published_notification'] |
---|
| 183 | setProperties(self.prefs, *properties) |
---|
| 184 | #setProperties(self.prefs, 'enable_published_notification', ) |
---|
[2137] | 185 | self.my_doc.discussion_reply('A Reply for my_doc', |
---|
| 186 | 'text of reply for my_doc') |
---|
| 187 | reply = self.getDiscussionReplies(self.my_doc)[0] |
---|
| 188 | reply.discussion_reply('A Reply for reply for my_doc', |
---|
| 189 | 'text of reply on reply for my_doc') |
---|
| 190 | reply2 = self.getDiscussionReplies(reply)[0] |
---|
[832] | 191 | |
---|
[1633] | 192 | self.portal.MailHost.reset() |
---|
[832] | 193 | reply2.discussion_publish_comment() |
---|
[1633] | 194 | mails = [str(m) for m in self.portal.MailHost.messages] |
---|
[2137] | 195 | self.failUnless([1 for m in mails |
---|
| 196 | if REXP_SUBJ.search(m) and \ |
---|
| 197 | 'replied' in REXP_SUBJ.search(m).group(1)], |
---|
[880] | 198 | 'No notification for reply.' % properties) |
---|
[2137] | 199 | self.failUnless([1 for m in mails |
---|
| 200 | if REXP_SUBJ.search(m) and \ |
---|
| 201 | 'added' in REXP_SUBJ.search(m).group(1)], |
---|
[880] | 202 | 'No notification for adding comment.' % properties) |
---|
[2137] | 203 | self.failUnless([1 for m in mails |
---|
| 204 | if REXP_SUBJ.search(m) and \ |
---|
| 205 | 'published' in REXP_SUBJ.search(m).group(1)], |
---|
[880] | 206 | 'No notification for publishing comment.' % properties) |
---|
[832] | 207 | |
---|
| 208 | def test_bug_notification_on_single_reply_delete(self): |
---|
| 209 | """ Bug: no notification sent on deleting single comment. |
---|
| 210 | Mail about rejecing comment should be sent to comentator. |
---|
| 211 | """ |
---|
[2137] | 212 | properties = ['enable_rejected_user_notification', ] |
---|
[832] | 213 | setProperties(self.prefs, *properties) |
---|
| 214 | #setProperties(self.prefs, 'enable_published_notification', ) |
---|
[2137] | 215 | self.my_doc.discussion_reply('A Reply for my_doc', |
---|
| 216 | 'text of reply for my_doc') |
---|
| 217 | reply = self.getDiscussionReplies(self.my_doc)[0] |
---|
[832] | 218 | |
---|
[1633] | 219 | self.portal.MailHost.reset() |
---|
[832] | 220 | reply.deleteDiscussion() |
---|
[1633] | 221 | mails = [str(m) for m in self.portal.MailHost.messages] |
---|
[1719] | 222 | subject = 'Your comment on Doc was not approved' |
---|
[2137] | 223 | self.failUnless([1 for m in mails |
---|
| 224 | if REXP_SUBJ.search(m) and \ |
---|
| 225 | REXP_SUBJ.search(m).group(1) == subject], |
---|
[880] | 226 | 'No notification for rejecting comment.' % properties) |
---|
[832] | 227 | |
---|
| 228 | |
---|
| 229 | def test_suite(): |
---|
| 230 | from unittest import TestSuite, makeSuite |
---|
| 231 | suite = TestSuite() |
---|
| 232 | suite.addTest(makeSuite(TestNotification)) |
---|
| 233 | return suite |
---|