Ignore:
Timestamp:
Feb 3, 2010 4:37:25 PM (14 years ago)
Author:
kroman0
Message:

Fixed tests for quintagroup.plonecomments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/helperNotify.py

    r832 r1633  
    22##      Helper methods for testing Mail sending        ## 
    33######################################################### 
    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__)) 
    104 
    115ALL_PROPS = ['enable_approve_user_notification', 'enable_reply_user_notification', 
     
    148             'enable_published_notification', 'enable_approve_notification'] 
    159 
    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  
    6110def setProperties(prop_sheet, *props): 
    6211    for p in ALL_PROPS: 
    6312        prop_sheet._updateProperty(p, p in props) 
    6413 
    65 def testMailExistance(): 
    66     for f in os.listdir(output_file_path("")): 
    67         if f.startswith('mail'): 
    68             return True 
     14def testMailExistance(sel): 
     15    mailhost = sel.portal.MailHost 
     16    if mailhost.messages:  
     17        return True 
    6918    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.