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