source: products/qPloneComments/tags/2.3/tests/helperNotify.py @ 1591

Last change on this file since 1591 was 1, checked in by myroslav, 18 years ago

Building directory structure

File size: 2.7 KB
Line 
1#########################################################
2##      Helper methods for testing Mail sending        ##
3#########################################################
4
5import sys
6import os, os.path
7from Products.MailHost.MailHost import MailBase
8ver = "2.0.5"
9try:
10    from Products.SecureMailHost.SecureMailHost import SecureMailBase
11    ver = "2.1"
12except ImportError:
13    pass
14
15PREFIX = os.path.abspath(os.path.dirname(__file__))
16
17ALL_PROPS = ['enable_approve_user_notification', 'enable_reply_user_notification',
18             'enable_rejected_user_notification','enable_moderation',
19             'require_email', 'enable_anonymous_commenting',
20             'enable_published_notification', 'enable_approve_notification']
21
22def sample_file_path(file):
23    return os.path.join(PREFIX, 'sample', file)
24
25def output_file_path(file):
26    return os.path.join(PREFIX, 'output', file)
27
28def getFileContent(f_path):
29    result_f = open(f_path,"r")
30    result = result_f.read()
31    result_f.close()
32    return result
33
34def writeToFile(f_path, text):
35    result_f = open(f_path,'w')
36    result_f.write(text+'\n')
37    result_f.close()
38
39def clearFile(f_path):
40    result_f = open(f_path,"w")
41    result_f.write('')
42    result_f.close()
43
44def _send_MH( self, mfrom, mto, messageText ):
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
50def _send_SMH(self, mfrom, mto, messageText, debug=False):
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), messageText)
55
56def send_SMH(self, message, mto=None, mfrom=None, subject=None, encode=None):
57    files = [f for f in os.listdir(output_file_path("")) if f.startswith('mail')]
58    files.sort()
59    fn = files and (files[-1]+ '1') or 'mail'
60    writeToFile(output_file_path(fn), message)
61
62def prepareMailSendTest():
63    # patch MailHost
64    MailBase._send = _send_MH
65    if ver == "2.1":
66        # patch SecureMailHost
67        SecureMailBase.send = send_SMH
68        SecureMailBase._send = _send_SMH
69
70def setProperties(prop_sheet, *props):
71    for p in ALL_PROPS:
72        prop_sheet._updateProperty(p, p in props)
73
74def testMailExistance():
75    for f in os.listdir(output_file_path("")):
76        if f.startswith('mail'):
77            return True
78    return False
79
80def getMails():
81    return [file(output_file_path(f),'r').read() for f in os.listdir(output_file_path("")) if f.startswith('mail')]
82
83
84def cleanOutputDir():
85    for f in os.listdir(output_file_path("")):
86        if f.startswith('mail'): os.remove(output_file_path(f))
Note: See TracBrowser for help on using the repository browser.