Changeset 1633 in products for quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/helperNotify.py
- Timestamp:
- Feb 3, 2010 4:37:25 PM (14 years ago)
- File:
-
- 1 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))
Note: See TracChangeset
for help on using the changeset viewer.