source: products/qPloneComments/tags/2.2.0-rc1/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
17def verifyMail(text,  mail_type):
18    pass
19
20def sample_file_path(file):
21    return os.path.join(PREFIX, 'sample', file)
22
23def output_file_path(file):
24    return os.path.join(PREFIX, 'output', file)
25
26def getFileContent(f_path):
27    result_f = open(f_path,"r")
28    result = result_f.read()
29    result_f.close()
30    return result
31
32def writeToFile(f_path, text):
33    result_f = open(f_path,"a")
34    result_f.write(text+'\n')
35    result_f.close()
36
37def clearFile(f_path):
38    result_f = open(f_path,"w")
39    result_f.write('')
40    result_f.close()
41
42def testMailSend(self, state='approve'):
43    result = getFileContent(output_file_path('mail.res'))
44    sample = getFileContent(sample_file_path(state+'.mail'))
45    # Check headers
46    sample_headers = sample.split('\n')[:2]
47    for header in sample_headers:
48        self.assert_(header in result, "State:'%s'. Header '%s' not present in sended mail" % (state, header) )
49    # Check footer
50    sample_footer = sample.split('\n')[-2:-1]
51    self.assert_(sample_footer[0] in result, "State:'%s'. Footer '%s' not present in sended mail" % (state, sample_footer[0]) )
52
53def testNotMailSend(self, state='approve'):
54    result = getFileContent(output_file_path('mail.res'))
55    sample = getFileContent(sample_file_path(state+'.mail'))
56    # Check headers
57    sample_headers = sample.split('\n')[:2]
58    del sample_headers[1]
59    for header in sample_headers:
60        self.assert_(not header in result, "State:'%s'. Header '%s' present in sended mail" % (state, header) )
61
62def testNotMail(self):
63    result = getFileContent(output_file_path('mail.res'))
64    self.assert_(not result, "Mail was sended")
65
66def _send_MH( self, mfrom, mto, messageText ):
67    writeToFile(output_file_path('mail.res'), messageText)
68
69def _send_SMH(self, mfrom, mto, messageText, debug=False):
70    writeToFile(output_file_path('mail.res'), messageText)
71
72def send_SMH(self, message, mto=None, mfrom=None, subject=None, encode=None):
73    writeToFile(output_file_path('mail.res'), message)
74
75def prepareMailSendTest():
76    # patch MailHost
77    MailBase._send = _send_MH
78    if ver == "2.1":
79        # patch SecureMailHost
80        SecureMailBase.send = send_SMH
81        SecureMailBase._send = _send_SMH
82    # clear 'mail.res' file
83    clearFile(output_file_path('mail.res'))
Note: See TracBrowser for help on using the repository browser.