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