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

Last change on this file since 1591 was 105, checked in by crchemist, 18 years ago
  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1#########################################################
2##      Helper methods for testing Mail sending        ##
3#########################################################
4
5import sys
6import os, os.path
7from Products.SecureMailHost.SecureMailHost import SecureMailBase
8
9PREFIX = os.path.abspath(os.path.dirname(__file__))
10
11ALL_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
16def sample_file_path(file):
17    return os.path.join(PREFIX, 'sample', file)
18
19def output_file_path(file):
20    return os.path.join(PREFIX, 'output', file)
21
22def getFileContent(f_path):
23    result_f = open(f_path,"r")
24    result = result_f.read()
25    result_f.close()
26    return result
27
28def writeToFile(f_path, text):
29    result_f = open(f_path,'w')
30    result_f.write(text.as_string()+'\n')
31    result_f.close()
32
33def clearFile(f_path):
34    result_f = open(f_path,"w")
35    result_f.write('')
36    result_f.close()
37
38def _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
44def _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
50def 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
56def prepareMailSendTest():
57    # patch SecureMailHost
58    SecureMailBase.send = send_SMH
59    SecureMailBase._send = _send_SMH
60
61def setProperties(prop_sheet, *props):
62    for p in ALL_PROPS:
63        prop_sheet._updateProperty(p, p in props)
64
65def testMailExistance():
66    for f in os.listdir(output_file_path("")):
67        if f.startswith('mail'):
68            return True
69    return False
70
71def 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
76def 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 repository browser.