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