Changeset 1633 in products


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

Fixed tests for quintagroup.plonecomments

Location:
quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests
Files:
4 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)) 
  • quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/testQPloneCommentsNotification.py

    r1465 r1633  
    1313from config import * 
    1414 
     15from Products.CMFPlone.tests.utils import MockMailHost 
     16 
     17REXP_TO = re.compile("To:\s*(.*?)$",re.M) 
     18REXP_SUBJ = re.compile("Subject:\s*(.*?)$",re.M) 
     19 
    1520 
    1621class TestNotification(FunctionalTestCase): 
     
    2025        self.prefs._updateProperty('enable_published_notification', swithP) 
    2126 
     27    def beforeTearDown(self): 
     28        self.portal.MailHost = self.portal._original_MailHost 
     29 
    2230    def afterSetUp(self): 
     31        self.portal._original_MailHost = self.portal.MailHost 
     32        self.portal.MailHost = mailhost = MockMailHost('MailHost') 
     33 
    2334        self.loginAsPortalOwner() 
    2435 
     
    6475        self.request.form['body_text'] = "text of reply" 
    6576 
    66         prepareMailSendTest() 
     77        #prepareMailSendTest() 
    6778 
    6879    def test_bug_parent_reply(self): 
     
    93104 
    94105    def test_notificafion_disabled(self): 
    95         cleanOutputDir() 
     106        self.portal.MailHost.reset() 
    96107        setProperties(self.prefs) 
    97108        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    98         self.failIf(testMailExistance(), 'Mail was sended when all notification was disabled.') 
     109        self.failIf(testMailExistance(self), 'Mail was sended when all notification was disabled.') 
    99110 
    100111    def test_published_comment_notification(self): 
    101         cleanOutputDir() 
     112        self.portal.MailHost.reset() 
    102113        setProperties(self.prefs, 'enable_published_notification') 
    103114        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    104         self.failUnless(testMailExistance(), 'Mail was not sended when enable_published_notification.') 
     115        self.failUnless(testMailExistance(self), 'Mail was not sended when enable_published_notification.') 
    105116 
    106117    def test_approve_comment_notification(self): 
    107         cleanOutputDir() 
     118        self.portal.MailHost.reset() 
    108119        setProperties(self.prefs, 'enable_approve_notification') 
    109120        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    110         self.failUnless(testMailExistance(), 'Mail was not sended when enable_approve_notification.') 
     121        self.failUnless(testMailExistance(self), 'Mail was not sended when enable_approve_notification.') 
    111122 
    112123    def test_reply_comment_user_notification(self): 
    113         cleanOutputDir() 
     124        self.portal.MailHost.reset() 
    114125        setProperties(self.prefs, 'enable_reply_user_notification') 
    115126        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    116         self.failIf(testMailExistance(), 'Mail was sended for simple reply when enable_reply_user_notification.') 
     127        self.failIf(testMailExistance(self), 'Mail was sended for simple reply when enable_reply_user_notification.') 
    117128 
    118129        reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
    119130        reply.discussion_reply('A Reply for comment' ,'text of reply for comment') 
    120131        reply_for_comment = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
    121         self.failUnless(testMailExistance(), 'Mail was not sended when enable_reply_user_notification.') 
     132        self.failUnless(testMailExistance(self), 'Mail was not sended when enable_reply_user_notification.') 
    122133 
    123134    def test_rejected_comment_notification(self): 
    124         cleanOutputDir() 
     135        self.portal.MailHost.reset() 
    125136        setProperties(self.prefs, 'enable_rejected_user_notification', 'enable_moderation') 
    126137        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    127         self.failIf(testMailExistance(), 'Mail was sended when enable_rejected_user_notification was enabled.') 
     138        self.failIf(testMailExistance(self), 'Mail was sended when enable_rejected_user_notification was enabled.') 
    128139 
    129140        reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
    130141        self.portal.REQUEST.set('ids', [reply.getId()]) 
    131142        self.portal.prefs_recent_comments_delete() 
    132         self.failUnless(testMailExistance(), 'Mail was not sended when enable_rejected_user_notification.') 
     143        self.failUnless(testMailExistance(self), 'Mail was not sended when enable_rejected_user_notification.') 
    133144 
    134145    def test_approve_comment_user__notification(self): 
    135         cleanOutputDir() 
     146        self.portal.MailHost.reset() 
    136147        setProperties(self.prefs, 'enable_approve_user_notification') 
    137148        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    138         self.failUnless(testMailExistance(), 'Mail was not sended when enable_approve_user_notification.') 
     149        self.failUnless(testMailExistance(self), 'Mail was not sended when enable_approve_user_notification.') 
    139150 
    140151    def test_bug_notification_on_single_reply_publish(self): 
     
    153164        reply2 = self.discussion.getDiscussionFor(reply).getReplies()[0] 
    154165 
    155         cleanOutputDir() 
     166        self.portal.MailHost.reset() 
    156167        reply2.discussion_publish_comment() 
    157         mails = getMails() 
    158         self.failUnless([1 for m in mails if re.search('^Subject:.*(replied).*$', m, re.I|re.M)], 
     168        mails = [str(m) for m in self.portal.MailHost.messages] 
     169        self.failUnless([1 for m in mails if REXP_SUBJ.search(m) and 'replied' in REXP_SUBJ.search(m).group(1)], 
    159170            'No notification for reply.' % properties) 
    160         self.failUnless([1 for m in mails if re.search('^Subject:.*(added).*$', m, re.I|re.M)], 
     171        self.failUnless([1 for m in mails if REXP_SUBJ.search(m) and 'added' in REXP_SUBJ.search(m).group(1)], 
    161172            'No notification for adding comment.' % properties) 
    162         self.failUnless([1 for m in mails if re.search('^Subject:.*(published).*$', m, re.I|re.M)], 
     173        self.failUnless([1 for m in mails if REXP_SUBJ.search(m) and 'published' in REXP_SUBJ.search(m).group(1)], 
    163174            'No notification for publishing comment.' % properties) 
    164175 
     
    173184        reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
    174185 
    175         cleanOutputDir() 
     186        self.portal.MailHost.reset() 
    176187        reply.deleteDiscussion() 
    177         mails = getMails() 
     188        mails = [str(m) for m in self.portal.MailHost.messages] 
    178189        subject = str(Header('Your comment on Doc was not approved', 'utf-8')) 
    179         subjs = [message_from_string(m)['Subject'] for m in mails] 
    180         self.failUnless([1 for m in subjs if m == subject], 
     190        self.failUnless([1 for m in mails if REXP_SUBJ.search(m) and REXP_SUBJ.search(m).group(1)==subject], 
    181191            'No notification for rejecting comment.' % properties) 
    182192 
  • quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/testQPloneCommentsNotificationRecipients.py

    r1059 r1633  
    99import re 
    1010from helperNotify import * 
     11from email import message_from_string 
    1112from email.Header import Header 
    1213from base import getToolByName, FunctionalTestCase 
    1314from common import * 
    1415from config import * 
     16 
     17from Products.CMFPlone.tests.utils import MockMailHost 
    1518 
    1619USERS = {# Common Members 
     
    3841        self.request.form['body_text'] = "text of reply" 
    3942 
     43    def beforeTearDown(self): 
     44        self.portal.MailHost = self.portal._original_MailHost 
     45 
    4046    def afterSetUp(self): 
     47        self.portal._original_MailHost = self.portal.MailHost 
     48        self.portal.MailHost = mailhost = MockMailHost('MailHost') 
     49 
    4150        self.loginAsPortalOwner() 
    4251 
     
    7988        # Create talkback for document and Prepare REQUEST 
    8089        self.discussion.getDiscussionFor(self.my_doc) 
    81         prepareMailSendTest() 
     90        #prepareMailSendTest() 
    8291 
    8392    def checkToANDSubj(self, mails, to, subj): 
    84         messages = [m for m in mails if REXP_TO.search(m) and REXP_TO.search(m).group(1)==to] 
     93        messages = [str(m) for m in mails if REXP_TO.search(str(m)) and REXP_TO.search(str(m)).group(1)==to] 
    8594        self.failUnless(len(messages) > 0, "No message sent to '%s' recipient" % to) 
    8695        mangled = str(Header(subj, 'utf-8')) 
     
    8998 
    9099    def test_Reply(self): 
    91         cleanOutputDir() 
     100        self.portal.MailHost.reset() 
     101         
    92102        self.prepareRequest4Reply('replier1') 
    93103        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    94104 
    95         mails = getMails() 
     105        mails = self.portal.MailHost.messages 
    96106        self.assertEqual(len(mails), 1) 
    97107        self.checkToANDSubj(mails, to="discussion.manager@test.com", 
     
    103113        self.login('dm_admin') 
    104114        reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
    105         cleanOutputDir() 
     115        self.portal.MailHost.reset() 
     116         
    106117 
    107118        reply.discussion_publish_comment() 
    108         mails = getMails() 
     119        mails = self.portal.MailHost.messages 
    109120        self.assertEqual(len(mails), 2) 
    110121        self.checkToANDSubj(mails, to="owner@test.com", subj="[PREFIX] New comment added") 
     
    121132        self.login('dm_admin') 
    122133        reply2 = self.discussion.getDiscussionFor(reply).getReplies()[0] 
    123         cleanOutputDir() 
     134        self.portal.MailHost.reset() 
     135         
    124136 
    125137        reply2.discussion_publish_comment() 
    126         mails = getMails() 
     138        mails = self.portal.MailHost.messages 
    127139        self.assertEqual(len(mails), 3) 
    128140        self.checkToANDSubj(mails, to="owner@test.com", subj="[PREFIX] New comment added") 
     
    135147        self.login('dm_admin') 
    136148        reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
    137         cleanOutputDir() 
     149        self.portal.MailHost.reset() 
     150         
    138151 
    139152        reply.deleteDiscussion() 
    140         mails = getMails() 
     153        mails = self.portal.MailHost.messages 
    141154        self.assertEqual(len(mails), 1) 
    142155        self.checkToANDSubj(mails, to="replier1@test.com", subj='Your comment on Test document was not approved') 
  • quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/testQPloneCommentsUninstall.py

    r965 r1633  
    1414        self.loginAsPortalOwner() 
    1515        self.qi = self.portal.portal_quickinstaller 
     16        self.qi.installProduct(PRODUCT) 
     17        self.qi.uninstallProducts([PRODUCT]) 
    1618 
    1719    def test_package_uninstall(self): 
Note: See TracChangeset for help on using the changeset viewer.