Changeset 2137 in products for quintagroup.plonecomments/branches/jquery/quintagroup/plonecomments/tests/testQPloneCommentsNotification.py
- Timestamp:
- Apr 16, 2010 12:13:55 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.plonecomments/branches/jquery/quintagroup/plonecomments/tests/testQPloneCommentsNotification.py
r1719 r2137 15 15 from Products.CMFPlone.tests.utils import MockMailHost 16 16 17 REXP_TO = re.compile("To:\s*(.*?)$", re.M)18 REXP_SUBJ = re.compile("Subject:\s*(.*?)$", re.M)17 REXP_TO = re.compile("To:\s*(.*?)$", re.M) 18 REXP_SUBJ = re.compile("Subject:\s*(.*?)$", re.M) 19 19 20 20 21 21 class TestNotification(FunctionalTestCase): 22 22 23 def setApprovePublished(self, swithA=1,swithP=1): 23 def getDiscussionReplies(self, obj): 24 return self.discussion.getDiscussionFor(obj).getReplies() 25 26 def setApprovePublished(self, swithA=1, swithP=1): 24 27 self.prefs._updateProperty('enable_approve_notification', swithA) 25 28 self.prefs._updateProperty('enable_published_notification', swithP) … … 46 49 # Make sure Documents are visible by default 47 50 # 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.portal.portal_workflow.setChainForPortalTypes(('Document',), 52 'plone_workflow') 53 54 portal_properties = getToolByName(self.portal, 'portal_properties', 55 None) 51 56 self.prefs = portal_properties[PROPERTY_SHEET] 52 57 53 58 # Add Manager user - 'dm' and add him to Discussion Manager group 54 self.portal.portal_membership.addMember('dm', 'secret' , ['Manager'], []) 59 self.portal.portal_membership.addMember('dm', 'secret', 60 ['Manager'], []) 55 61 portal_groups = getToolByName(self.portal, 'portal_groups') 56 62 dm_group = portal_groups.getGroupById('DiscussionManager') … … 60 66 # For prepare mail sending - enter an e-mail adress 61 67 self.portal.email_from_address = 'mail@plone.test' 62 self.prefs._updateProperty('email_discussion_manager', 'discussion.manager@test.com') 68 self.prefs._updateProperty('email_discussion_manager', 69 'discussion.manager@test.com') 63 70 member = self.portal.portal_membership.getAuthenticatedMember() 64 member.setMemberProperties({'email': 'creator@test.com'})71 member.setMemberProperties({'email': 'creator@test.com'}) 65 72 66 73 # Add testing document to portal 67 my_doc = self.portal.invokeFactory('Document', id='my_doc', title='Doc') 74 my_doc = self.portal.invokeFactory('Document', id='my_doc', 75 title='Doc') 68 76 self.my_doc = self.portal['my_doc'] 69 77 self.my_doc.edit(text_format='plain', text='hello world') … … 71 79 self.discussion.getDiscussionFor(self.my_doc) 72 80 self.request = self.app.REQUEST 73 self.request.form['Creator'] = self.portal.portal_membership.getAuthenticatedMember().getUserName() 81 authmember = self.portal.portal_membership.getAuthenticatedMember() 82 self.request.form['Creator'] = authmember.getUserName() 74 83 self.request.form['subject'] = "Reply 1" 75 84 self.request.form['body_text'] = "text of reply" … … 79 88 def test_bug_parent_reply(self): 80 89 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] 90 self.my_doc.discussion_reply('A Reply for my_doc', 91 'text of reply for my_doc') 92 parent_reply = self.getDiscussionReplies(self.my_doc)[0] 83 93 parent_reply.discussion_reply('reply', 'text') 84 94 85 95 def test_bug_mistakable_names(self): 86 96 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]} 97 self.my_doc.discussion_reply('A Reply for my_doc', 98 'text of reply for my_doc') 99 parent_reply = self.getDiscussionReplies(self.my_doc)[0] 100 101 args = {'mto': 'user_email@gmail.com', 102 'mfrom': 'admin_email@gmail.com', 103 'obj': parent_reply, 104 'organization_name': 'org_name', 105 'name': parent_reply.getOwnerTuple()[1]} 95 106 96 107 msg = getMsg(self.portal, 'reply_notify_template', args) … … 106 117 self.portal.MailHost.reset() 107 118 setProperties(self.prefs) 108 self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 109 self.failIf(testMailExistance(self), 'Mail was sended when all notification was disabled.') 119 self.my_doc.discussion_reply('A Reply for my_doc', 120 'text of reply for my_doc') 121 self.failIf(testMailExistance(self), 122 'Mail was sended when all notification was disabled.') 110 123 111 124 def test_published_comment_notification(self): 112 125 self.portal.MailHost.reset() 113 126 setProperties(self.prefs, 'enable_published_notification') 114 self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 115 self.failUnless(testMailExistance(self), 'Mail was not sended when enable_published_notification.') 127 self.my_doc.discussion_reply('A Reply for my_doc', 128 'text of reply for my_doc') 129 self.failUnless(testMailExistance(self), 130 'Mail was not sended when enable_published_notification.') 116 131 117 132 def test_approve_comment_notification(self): 118 133 self.portal.MailHost.reset() 119 134 setProperties(self.prefs, 'enable_approve_notification') 120 self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 121 self.failUnless(testMailExistance(self), 'Mail was not sended when enable_approve_notification.') 135 self.my_doc.discussion_reply('A Reply for my_doc', 136 'text of reply for my_doc') 137 self.failUnless(testMailExistance(self), 138 'Mail was not sended when enable_approve_notification.') 122 139 123 140 def test_reply_comment_user_notification(self): 124 141 self.portal.MailHost.reset() 125 142 setProperties(self.prefs, 'enable_reply_user_notification') 126 self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 127 self.failIf(testMailExistance(self), 'Mail was sended for simple reply when enable_reply_user_notification.') 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] 132 self.failUnless(testMailExistance(self), 'Mail was not sended when enable_reply_user_notification.') 143 self.my_doc.discussion_reply('A Reply for my_doc', 144 'text of reply for my_doc') 145 self.failIf(testMailExistance(self), 146 'Mail was sended for simple reply ' 147 'when enable_reply_user_notification.') 148 149 reply = self.getDiscussionReplies(self.my_doc)[0] 150 reply.discussion_reply('A Reply for comment', 151 'text of reply for comment') 152 reply_for_comment = self.getDiscussionReplies(self.my_doc)[0] 153 self.failUnless(testMailExistance(self), 154 'Mail was not sended when enable_reply_user_notification.') 133 155 134 156 def test_rejected_comment_notification(self): 135 157 self.portal.MailHost.reset() 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') 138 self.failIf(testMailExistance(self), 'Mail was sended when enable_rejected_user_notification was enabled.') 139 140 reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 158 setProperties(self.prefs, 'enable_rejected_user_notification', 159 'enable_moderation') 160 self.my_doc.discussion_reply('A Reply for my_doc', 161 'text of reply for my_doc') 162 self.failIf(testMailExistance(self), 163 'Mail was sended when enable_rejected_user_notification' 164 ' was enabled.') 165 166 reply = self.getDiscussionReplies(self.my_doc)[0] 141 167 self.portal.REQUEST.set('ids', [reply.getId()]) 142 168 self.portal.prefs_recent_comments_delete() 143 self.failUnless(testMailExistance(self), 'Mail was not sended when enable_rejected_user_notification.') 169 self.failUnless(testMailExistance(self), 170 'Mail was not sended when enable_rejected_user_notification.') 144 171 145 172 def test_approve_comment_user__notification(self): 146 173 self.portal.MailHost.reset() 147 174 setProperties(self.prefs, 'enable_approve_user_notification') 148 self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 149 self.failUnless(testMailExistance(self), 'Mail was not sended when enable_approve_user_notification.') 175 self.my_doc.discussion_reply('A Reply for my_doc', 176 'text of reply for my_doc') 177 self.failUnless(testMailExistance(self), 178 'Mail was not sended when enable_approve_user_notification.') 150 179 151 180 def test_bug_notification_on_single_reply_publish(self): … … 155 184 for document creator about adding new comment. 156 185 """ 157 properties = ['enable_approve_user_notification', 'enable_reply_user_notification', 186 properties = ['enable_approve_user_notification', 187 'enable_reply_user_notification', 158 188 'enable_published_notification'] 159 189 setProperties(self.prefs, *properties) 160 190 #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] 191 self.my_doc.discussion_reply('A Reply for my_doc', 192 'text of reply for my_doc') 193 reply = self.getDiscussionReplies(self.my_doc)[0] 194 reply.discussion_reply('A Reply for reply for my_doc', 195 'text of reply on reply for my_doc') 196 reply2 = self.getDiscussionReplies(reply)[0] 165 197 166 198 self.portal.MailHost.reset() 167 199 reply2.discussion_publish_comment() 168 200 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)], 201 self.failUnless([1 for m in mails 202 if REXP_SUBJ.search(m) and \ 203 'replied' in REXP_SUBJ.search(m).group(1)], 170 204 'No notification for reply.' % properties) 171 self.failUnless([1 for m in mails if REXP_SUBJ.search(m) and 'added' in REXP_SUBJ.search(m).group(1)], 205 self.failUnless([1 for m in mails 206 if REXP_SUBJ.search(m) and \ 207 'added' in REXP_SUBJ.search(m).group(1)], 172 208 'No notification for adding comment.' % properties) 173 self.failUnless([1 for m in mails if REXP_SUBJ.search(m) and 'published' in REXP_SUBJ.search(m).group(1)], 209 self.failUnless([1 for m in mails 210 if REXP_SUBJ.search(m) and \ 211 'published' in REXP_SUBJ.search(m).group(1)], 174 212 'No notification for publishing comment.' % properties) 175 213 … … 178 216 Mail about rejecing comment should be sent to comentator. 179 217 """ 180 properties = ['enable_rejected_user_notification', ]218 properties = ['enable_rejected_user_notification', ] 181 219 setProperties(self.prefs, *properties) 182 220 #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] 221 self.my_doc.discussion_reply('A Reply for my_doc', 222 'text of reply for my_doc') 223 reply = self.getDiscussionReplies(self.my_doc)[0] 185 224 186 225 self.portal.MailHost.reset() … … 188 227 mails = [str(m) for m in self.portal.MailHost.messages] 189 228 subject = 'Your comment on Doc was not approved' 190 self.failUnless([1 for m in mails if REXP_SUBJ.search(m) and REXP_SUBJ.search(m).group(1)==subject], 229 self.failUnless([1 for m in mails 230 if REXP_SUBJ.search(m) and \ 231 REXP_SUBJ.search(m).group(1) == subject], 191 232 'No notification for rejecting comment.' % properties) 192 233
Note: See TracChangeset
for help on using the changeset viewer.