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/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 
Note: See TracChangeset for help on using the changeset viewer.