Changeset 1633 in products
- Timestamp:
- Feb 3, 2010 4:37:25 PM (15 years ago)
- Location:
- quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/helperNotify.py
r832 r1633 2 2 ## Helper methods for testing Mail sending ## 3 3 ######################################################### 4 5 import sys6 import os, os.path7 from Products.SecureMailHost.SecureMailHost import SecureMailBase8 9 PREFIX = os.path.abspath(os.path.dirname(__file__))10 4 11 5 ALL_PROPS = ['enable_approve_user_notification', 'enable_reply_user_notification', … … 14 8 'enable_published_notification', 'enable_approve_notification'] 15 9 16 def sample_file_path(file):17 return os.path.join(PREFIX, 'sample', file)18 19 def output_file_path(file):20 return os.path.join(PREFIX, 'output', file)21 22 def getFileContent(f_path):23 result_f = open(f_path,"r")24 result = result_f.read()25 result_f.close()26 return result27 28 def writeToFile(f_path, text):29 result_f = open(f_path,'w')30 result_f.write(text.as_string()+'\n')31 result_f.close()32 33 def clearFile(f_path):34 result_f = open(f_path,"w")35 result_f.write('')36 result_f.close()37 38 def _send_MH( self, mfrom, mto, messageText ):39 files = [f for f in os.listdir(output_file_path("")) if f.startswith('mail')]40 files.sort()41 fn = files and (files[-1]+ '1') or 'mail'42 writeToFile(output_file_path(fn), messageText)43 44 def _send_SMH(self, mfrom, mto, messageText, debug=False):45 files = [f for f in os.listdir(output_file_path("")) if f.startswith('mail')]46 files.sort()47 fn = files and (files[-1]+ '1') or 'mail'48 writeToFile(output_file_path(fn), messageText)49 50 def send_SMH(self, message, mto=None, mfrom=None, subject=None, encode=None):51 files = [f for f in os.listdir(output_file_path("")) if f.startswith('mail')]52 files.sort()53 fn = files and (files[-1]+ '1') or 'mail'54 writeToFile(output_file_path(fn), message)55 56 def prepareMailSendTest():57 # patch SecureMailHost58 SecureMailBase.send = send_SMH59 SecureMailBase._send = _send_SMH60 61 10 def setProperties(prop_sheet, *props): 62 11 for p in ALL_PROPS: 63 12 prop_sheet._updateProperty(p, p in props) 64 13 65 def testMailExistance( ):66 for f in os.listdir(output_file_path("")):67 if f.startswith('mail'):68 14 def testMailExistance(sel): 15 mailhost = sel.portal.MailHost 16 if mailhost.messages: 17 return True 69 18 return False 70 71 def getMails():72 return [file(output_file_path(f),'r').read()73 for f in os.listdir(output_file_path(""))74 if f.startswith('mail')]75 76 def cleanOutputDir():77 for f in os.listdir(output_file_path("")):78 if f.startswith('mail'):79 os.remove(output_file_path(f)) -
quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/testQPloneCommentsNotification.py
r1465 r1633 13 13 from config import * 14 14 15 from Products.CMFPlone.tests.utils import MockMailHost 16 17 REXP_TO = re.compile("To:\s*(.*?)$",re.M) 18 REXP_SUBJ = re.compile("Subject:\s*(.*?)$",re.M) 19 15 20 16 21 class TestNotification(FunctionalTestCase): … … 20 25 self.prefs._updateProperty('enable_published_notification', swithP) 21 26 27 def beforeTearDown(self): 28 self.portal.MailHost = self.portal._original_MailHost 29 22 30 def afterSetUp(self): 31 self.portal._original_MailHost = self.portal.MailHost 32 self.portal.MailHost = mailhost = MockMailHost('MailHost') 33 23 34 self.loginAsPortalOwner() 24 35 … … 64 75 self.request.form['body_text'] = "text of reply" 65 76 66 prepareMailSendTest()77 #prepareMailSendTest() 67 78 68 79 def test_bug_parent_reply(self): … … 93 104 94 105 def test_notificafion_disabled(self): 95 cleanOutputDir()106 self.portal.MailHost.reset() 96 107 setProperties(self.prefs) 97 108 self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 98 self.failIf(testMailExistance( ), 'Mail was sended when all notification was disabled.')109 self.failIf(testMailExistance(self), 'Mail was sended when all notification was disabled.') 99 110 100 111 def test_published_comment_notification(self): 101 cleanOutputDir()112 self.portal.MailHost.reset() 102 113 setProperties(self.prefs, 'enable_published_notification') 103 114 self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 104 self.failUnless(testMailExistance( ), 'Mail was not sended when enable_published_notification.')115 self.failUnless(testMailExistance(self), 'Mail was not sended when enable_published_notification.') 105 116 106 117 def test_approve_comment_notification(self): 107 cleanOutputDir()118 self.portal.MailHost.reset() 108 119 setProperties(self.prefs, 'enable_approve_notification') 109 120 self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 110 self.failUnless(testMailExistance( ), 'Mail was not sended when enable_approve_notification.')121 self.failUnless(testMailExistance(self), 'Mail was not sended when enable_approve_notification.') 111 122 112 123 def test_reply_comment_user_notification(self): 113 cleanOutputDir()124 self.portal.MailHost.reset() 114 125 setProperties(self.prefs, 'enable_reply_user_notification') 115 126 self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 116 self.failIf(testMailExistance( ), 'Mail was sended for simple reply when enable_reply_user_notification.')127 self.failIf(testMailExistance(self), 'Mail was sended for simple reply when enable_reply_user_notification.') 117 128 118 129 reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 119 130 reply.discussion_reply('A Reply for comment' ,'text of reply for comment') 120 131 reply_for_comment = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 121 self.failUnless(testMailExistance( ), 'Mail was not sended when enable_reply_user_notification.')132 self.failUnless(testMailExistance(self), 'Mail was not sended when enable_reply_user_notification.') 122 133 123 134 def test_rejected_comment_notification(self): 124 cleanOutputDir()135 self.portal.MailHost.reset() 125 136 setProperties(self.prefs, 'enable_rejected_user_notification', 'enable_moderation') 126 137 self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 127 self.failIf(testMailExistance( ), 'Mail was sended when enable_rejected_user_notification was enabled.')138 self.failIf(testMailExistance(self), 'Mail was sended when enable_rejected_user_notification was enabled.') 128 139 129 140 reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 130 141 self.portal.REQUEST.set('ids', [reply.getId()]) 131 142 self.portal.prefs_recent_comments_delete() 132 self.failUnless(testMailExistance( ), 'Mail was not sended when enable_rejected_user_notification.')143 self.failUnless(testMailExistance(self), 'Mail was not sended when enable_rejected_user_notification.') 133 144 134 145 def test_approve_comment_user__notification(self): 135 cleanOutputDir()146 self.portal.MailHost.reset() 136 147 setProperties(self.prefs, 'enable_approve_user_notification') 137 148 self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 138 self.failUnless(testMailExistance( ), 'Mail was not sended when enable_approve_user_notification.')149 self.failUnless(testMailExistance(self), 'Mail was not sended when enable_approve_user_notification.') 139 150 140 151 def test_bug_notification_on_single_reply_publish(self): … … 153 164 reply2 = self.discussion.getDiscussionFor(reply).getReplies()[0] 154 165 155 cleanOutputDir()166 self.portal.MailHost.reset() 156 167 reply2.discussion_publish_comment() 157 mails = getMails()158 self.failUnless([1 for m in mails if re.search('^Subject:.*(replied).*$', m, re.I|re.M)],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)], 159 170 'No notification for reply.' % properties) 160 self.failUnless([1 for m in mails if re.search('^Subject:.*(added).*$', m, re.I|re.M)],171 self.failUnless([1 for m in mails if REXP_SUBJ.search(m) and 'added' in REXP_SUBJ.search(m).group(1)], 161 172 'No notification for adding comment.' % properties) 162 self.failUnless([1 for m in mails if re.search('^Subject:.*(published).*$', m, re.I|re.M)],173 self.failUnless([1 for m in mails if REXP_SUBJ.search(m) and 'published' in REXP_SUBJ.search(m).group(1)], 163 174 'No notification for publishing comment.' % properties) 164 175 … … 173 184 reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 174 185 175 cleanOutputDir()186 self.portal.MailHost.reset() 176 187 reply.deleteDiscussion() 177 mails = getMails()188 mails = [str(m) for m in self.portal.MailHost.messages] 178 189 subject = str(Header('Your comment on Doc was not approved', 'utf-8')) 179 subjs = [message_from_string(m)['Subject'] for m in mails] 180 self.failUnless([1 for m in subjs if m == subject], 190 self.failUnless([1 for m in mails if REXP_SUBJ.search(m) and REXP_SUBJ.search(m).group(1)==subject], 181 191 'No notification for rejecting comment.' % properties) 182 192 -
quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/testQPloneCommentsNotificationRecipients.py
r1059 r1633 9 9 import re 10 10 from helperNotify import * 11 from email import message_from_string 11 12 from email.Header import Header 12 13 from base import getToolByName, FunctionalTestCase 13 14 from common import * 14 15 from config import * 16 17 from Products.CMFPlone.tests.utils import MockMailHost 15 18 16 19 USERS = {# Common Members … … 38 41 self.request.form['body_text'] = "text of reply" 39 42 43 def beforeTearDown(self): 44 self.portal.MailHost = self.portal._original_MailHost 45 40 46 def afterSetUp(self): 47 self.portal._original_MailHost = self.portal.MailHost 48 self.portal.MailHost = mailhost = MockMailHost('MailHost') 49 41 50 self.loginAsPortalOwner() 42 51 … … 79 88 # Create talkback for document and Prepare REQUEST 80 89 self.discussion.getDiscussionFor(self.my_doc) 81 prepareMailSendTest()90 #prepareMailSendTest() 82 91 83 92 def checkToANDSubj(self, mails, to, subj): 84 messages = [ m for m in mails if REXP_TO.search(m) and REXP_TO.search(m).group(1)==to]93 messages = [str(m) for m in mails if REXP_TO.search(str(m)) and REXP_TO.search(str(m)).group(1)==to] 85 94 self.failUnless(len(messages) > 0, "No message sent to '%s' recipient" % to) 86 95 mangled = str(Header(subj, 'utf-8')) … … 89 98 90 99 def test_Reply(self): 91 cleanOutputDir() 100 self.portal.MailHost.reset() 101 92 102 self.prepareRequest4Reply('replier1') 93 103 self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 94 104 95 mails = getMails()105 mails = self.portal.MailHost.messages 96 106 self.assertEqual(len(mails), 1) 97 107 self.checkToANDSubj(mails, to="discussion.manager@test.com", … … 103 113 self.login('dm_admin') 104 114 reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 105 cleanOutputDir() 115 self.portal.MailHost.reset() 116 106 117 107 118 reply.discussion_publish_comment() 108 mails = getMails()119 mails = self.portal.MailHost.messages 109 120 self.assertEqual(len(mails), 2) 110 121 self.checkToANDSubj(mails, to="owner@test.com", subj="[PREFIX] New comment added") … … 121 132 self.login('dm_admin') 122 133 reply2 = self.discussion.getDiscussionFor(reply).getReplies()[0] 123 cleanOutputDir() 134 self.portal.MailHost.reset() 135 124 136 125 137 reply2.discussion_publish_comment() 126 mails = getMails()138 mails = self.portal.MailHost.messages 127 139 self.assertEqual(len(mails), 3) 128 140 self.checkToANDSubj(mails, to="owner@test.com", subj="[PREFIX] New comment added") … … 135 147 self.login('dm_admin') 136 148 reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 137 cleanOutputDir() 149 self.portal.MailHost.reset() 150 138 151 139 152 reply.deleteDiscussion() 140 mails = getMails()153 mails = self.portal.MailHost.messages 141 154 self.assertEqual(len(mails), 1) 142 155 self.checkToANDSubj(mails, to="replier1@test.com", subj='Your comment on Test document was not approved') -
quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/testQPloneCommentsUninstall.py
r965 r1633 14 14 self.loginAsPortalOwner() 15 15 self.qi = self.portal.portal_quickinstaller 16 self.qi.installProduct(PRODUCT) 17 self.qi.uninstallProducts([PRODUCT]) 16 18 17 19 def test_package_uninstall(self):
Note: See TracChangeset
for help on using the changeset viewer.