root/qPloneComments/trunk/tests/helperNotify.py

Revision 1144 (checked in by deo, 6 months ago)

SecureMailHost? creates instances of the email.Message.Message class, so we need to convert them to string before writing to the file.

  • Property svn:eol-style set to native
Line 
1 #########################################################
2 ##      Helper methods for testing Mail sending        ##
3 #########################################################
4
5 import sys
6 import os, os.path
7 from Products.SecureMailHost.SecureMailHost import SecureMailBase
8
9 PREFIX = os.path.abspath(os.path.dirname(__file__))
10
11 ALL_PROPS = ['enable_approve_user_notification', 'enable_reply_user_notification',
12              'enable_rejected_user_notification','enable_moderation',
13              'require_email', 'enable_anonymous_commenting',
14              'enable_published_notification', 'enable_approve_notification']
15
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 result
27
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 SecureMailHost
58     SecureMailBase.send = send_SMH
59     SecureMailBase._send = _send_SMH
60
61 def setProperties(prop_sheet, *props):
62     for p in ALL_PROPS:
63         prop_sheet._updateProperty(p, p in props)
64
65 def testMailExistance():
66     for f in os.listdir(output_file_path("")):
67         if f.startswith('mail'):
68             return True
69     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 TracBrowser for help on using the browser.