Changeset 611 in products


Ignore:
Timestamp:
Oct 27, 2006 3:16:55 PM (18 years ago)
Author:
crchemist
Message:

New tests added.

Location:
qPloneComments/tags/2.2.0-rc1
Files:
2 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • qPloneComments/tags/2.2.0-rc1/skins/qplonecomments/approve_comment_template.pt

    r571 r611  
    1 <div i18n:domain="plonecomments" 
     1<div i18n:domain="plonecomments"  
    22     tal:omit-tag="" 
    33     tal:define="charset here/portal_properties/site_properties/default_charset|string:utf-8; 
     
    1515 
    1616-- 
    17 <tal:signature i18n:translate="signature"> 
    18     <tal:organization_name condition="organization_name" 
    19                            replace="string:$organization_name" 
     17<tal:signature i18n:translate="signature">  
     18    <tal:organization_name condition="organization_name"  
     19                           replace="string:$organization_name"  
    2020                           i18n:name="organization_name"/> 
    21 Support Team 
     21    Support Team 
    2222</tal:signature> 
    2323</div> 
  • qPloneComments/tags/2.2.0-rc1/tests/helperNotify.py

    r493 r611  
    1515PREFIX = os.path.abspath(os.path.dirname(__file__)) 
    1616 
    17 ALL_PROPS = ['enable_approve_user_notification', 'enable_reply_user_notification', 
    18              'enable_rejected_user_notification','enable_moderation', 
    19              'require_email', 'enable_anonymous_commenting', 
    20              'enable_published_notification', 'enable_approve_notification'] 
     17def verifyMail(text,  mail_type): 
     18    pass 
    2119 
    2220def sample_file_path(file): 
     
    3331 
    3432def writeToFile(f_path, text): 
    35     result_f = open(f_path,'w') 
     33    result_f = open(f_path,"a") 
    3634    result_f.write(text+'\n') 
    3735    result_f.close() 
     
    4240    result_f.close() 
    4341 
     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 
    4466def _send_MH( self, mfrom, mto, messageText ): 
    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) 
     67    writeToFile(output_file_path('mail.res'), messageText) 
    4968 
    5069def _send_SMH(self, mfrom, mto, messageText, debug=False): 
    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), messageText) 
     70    writeToFile(output_file_path('mail.res'), messageText) 
    5571 
    5672def send_SMH(self, message, mto=None, mfrom=None, subject=None, encode=None): 
    57     files = [f for f in os.listdir(output_file_path("")) if f.startswith('mail')] 
    58     files.sort() 
    59     fn = files and (files[-1]+ '1') or 'mail' 
    60     writeToFile(output_file_path(fn), message) 
     73    writeToFile(output_file_path('mail.res'), message) 
    6174 
    6275def prepareMailSendTest(): 
     
    6780        SecureMailBase.send = send_SMH 
    6881        SecureMailBase._send = _send_SMH 
    69  
    70 def setProperties(prop_sheet, *props): 
    71     for p in ALL_PROPS: 
    72         prop_sheet._updateProperty(p, p in props) 
    73  
    74 def testMailExistance(): 
    75     for f in os.listdir(output_file_path("")): 
    76         if f.startswith('mail'): 
    77             return True 
    78     return False 
    79  
    80 def getMails(): 
    81     return [file(output_file_path(f),'r').read() for f in os.listdir(output_file_path("")) if f.startswith('mail')] 
    82  
    83  
    84 def cleanOutputDir(): 
    85     for f in os.listdir(output_file_path("")): 
    86         if f.startswith('mail'): os.remove(output_file_path(f)) 
     82    # clear 'mail.res' file 
     83    clearFile(output_file_path('mail.res')) 
  • qPloneComments/tags/2.2.0-rc1/tests/testQPloneCommentsNotification.py

    r493 r611  
    1 #    
     1# 
    22# Test configuration form working 
    33# 
    44 
    55import os, sys, string 
    6  
    76if __name__ == '__main__': 
    87    execfile(os.path.join(sys.path[0], 'framework.py')) 
     
    1211from Products.CMFCore.CMFCorePermissions import ManagePortal, ReplyToItem 
    1312from Products.MailHost.MailHost import MailBase 
    14  
    15 import re 
    16  
    17 from Products.qPloneComments.utils import getMsg 
    1813from helperNotify import * 
    1914 
    2015PRODUCT = 'qPloneComments' 
    2116PROPERTY_SHEET = "qPloneComments" 
     17 
    2218 
    2319PloneTestCase.installProduct(PRODUCT) 
     
    3026        self.prefs._updateProperty('enable_approve_notification', swithA) 
    3127        self.prefs._updateProperty('enable_published_notification', swithP) 
     28 
    3229 
    3330    def afterSetUp(self): 
     
    6057        member = self.portal.portal_membership.getAuthenticatedMember() 
    6158        member.setMemberProperties({'email':'creator@test.com'}) 
    62  
     59         
    6360        # Add testing document to portal 
    6461        my_doc = self.portal.invokeFactory('Document', id='my_doc') 
     
    7471        prepareMailSendTest() 
    7572 
    76     def test_bug_parent_reply(self): 
    77         setProperties(self.prefs, 'enable_reply_user_notification') 
     73     
     74    def testPublishedOFF(self): 
    7875        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    79         parent_reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
    80         parent_reply.discussion_reply('reply', 'text') 
    81  
    82     def test_bug_mistakable_names(self): 
    83         setProperties(self.prefs, 'enable_reply_user_notification') 
    84         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    85         parent_reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
    86  
    87         args={'mto': 'user_email@gmail.com', 
    88               'mfrom': 'admin_email@gmail.com', 
    89               'obj': parent_reply, 
    90               'organization_name': 'org_name', 
    91               'name': parent_reply.getOwnerTuple()[1]} 
    92  
    93         msg = getMsg(self.portal, 'reply_notify_template', args) 
    94         patt = re.compile('\\n\\n([^,]*)') 
    95         m = patt.search(msg) 
    96         if m: 
    97             name = m.group(1) 
    98             self.assertEqual(parent_reply.getOwnerTuple()[1], name) 
    99         else: 
    100             raise "No name" 
    101  
    102     def test_notificafion_disabled(self): 
    103         cleanOutputDir() 
    104         setProperties(self.prefs) 
    105         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    106         self.assert_(not testMailExistance(), 'Mail was sended when all notification was disabled') 
    107  
    108     def test_published_comment_notification(self): 
    109         cleanOutputDir() 
    110         setProperties(self.prefs, 'enable_published_notification') 
    111         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    112         self.assert_(testMailExistance(), 'Mail was not sended when enable_published_notification') 
    113  
    114     def test_approve_comment_notification(self): 
    115         cleanOutputDir() 
    116         setProperties(self.prefs, 'enable_approve_notification') 
    117         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    118         self.assert_(testMailExistance(), 'Mail was not sended when enable_approve_notification') 
    119  
    120     def test_reply_comment_user_notification(self): 
    121         cleanOutputDir() 
    122         setProperties(self.prefs, 'enable_reply_user_notification') 
    123         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    124         self.assert_(not testMailExistance(), 'Mail was sended for simple reply when enable_reply_user_notification') 
    125  
    126         reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
    127         reply.discussion_reply('A Reply for comment' ,'text of reply for comment') 
    128         reply_for_comment = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
    129         self.assert_(testMailExistance(), 'Mail was not sended when enable_reply_user_notification') 
    130  
    131     def test_rejected_comment_notification(self): 
    132         cleanOutputDir() 
    133         setProperties(self.prefs, 'enable_rejected_user_notification', 'enable_moderation') 
    134         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    135         self.assert_(not testMailExistance(), 'Mail was sended when enable_rejected_user_notification was enabled') 
    136  
    137         reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
    138         self.portal.REQUEST.set('ids', [reply.getId()]) 
    139         self.portal.prefs_recent_comments_delete() 
    140         self.assert_(testMailExistance(), 'Mail was not sended when enable_rejected_user_notification') 
    141  
    142     def test_approve_comment_user__notification(self): 
    143         cleanOutputDir() 
    144         setProperties(self.prefs, 'enable_approve_user_notification') 
    145         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    146         self.assert_(testMailExistance(), 'Mail was not sended when enable_approve_user_notification') 
    147  
    148     def test_bug_notification_on_single_reply_publish(self): 
    149         """ Bug: no notification sent on publishing single comment. 
    150             Must be 3 mails: for replier about replying on his commen; 
    151                              for replier about publishig his comment; 
    152                              for document creator about adding new comment. 
    153         """ 
    154         properties = ['enable_approve_user_notification', 'enable_reply_user_notification', 
    155                       'enable_published_notification'] 
    156         setProperties(self.prefs, *properties) 
    157         #setProperties(self.prefs, 'enable_published_notification', ) 
    158         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    159         reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
    160         reply.discussion_reply('A Reply for reply for my_doc' ,'text of reply on reply for my_doc') 
    161         reply2 = self.discussion.getDiscussionFor(reply).getReplies()[0] 
    162  
    163         cleanOutputDir() 
    164         reply2.discussion_publish_comment() 
    165         mails = getMails() 
    166         self.assert_([1 for m in mails if re.search('^Subject:.*(replied).*$', m, re.I|re.M)] \ 
    167                      ,'No notification for reply' % properties) 
    168         self.assert_([1 for m in mails if re.search('^Subject:.*(added).*$', m, re.I|re.M)] \ 
    169                      , 'No notification for adding comment' % properties) 
    170         self.assert_([1 for m in mails if re.search('^Subject:.*(published).*$', m, re.I|re.M)] \ 
    171                      , 'No notification for publishing comment' % properties) 
    172  
    173     def test_bug_notification_on_single_reply_delete(self): 
    174         """ Bug: no notification sent on deleting single comment. 
    175             Mail about rejecing comment should be sent to comentator. 
    176         """ 
    177         properties = ['enable_rejected_user_notification',] 
    178         setProperties(self.prefs, *properties) 
    179         #setProperties(self.prefs, 'enable_published_notification', ) 
    180         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
     76        clearFile(output_file_path('mail.res')) 
    18177        reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
    18278 
    183         cleanOutputDir() 
    184         reply.deleteDiscussion() 
    185         mails = getMails() 
    186         self.assert_([1 for m in mails if re.search('^Subject:.*(not approved).*$', m, re.I|re.M)] \ 
    187                      ,'No notification for rejecting comment' % properties) 
     79        # Set Published Notification OFF 
     80        self.setApprovePublished(swithA=0,swithP=0) 
     81        reply.discussion_publish_comment() 
     82        testNotMail(self) 
     83 
     84    def testPublishedON(self): 
     85        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
     86        clearFile(output_file_path('mail.res')) 
     87        reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
     88 
     89        # Set Published Notification ON 
     90        self.setApprovePublished(swithA=0,swithP=1) 
     91        reply.discussion_publish_comment() 
     92        testMailSend(self, state='published') 
    18893 
    18994 
    190     #def test_ 
     95    def testApproveOFF(self): 
     96        # Set Approve Notification OFF 
     97        self.setApprovePublished(swithA=0,swithP=0) 
     98        self.my_doc.discussion_reply('Reply 1', 'text of reply') 
     99        testNotMail(self) 
     100 
     101 
     102    def testApproveON(self): 
     103        # Set Approve Notification ON 
     104        self.setApprovePublished(swithA=1,swithP=0) 
     105        self.my_doc.discussion_reply('Reply 1', 'text of reply') 
     106        testMailSend(self, state='approve') 
     107 
     108 
     109    def testOFFModerationApprovePublished(self): 
     110        self.prefs._updateProperty('enable_moderation', 0) 
     111 
     112        # Test Enable Approve Notification & Enable Published Notification 
     113        self.setApprovePublished(swithA=1, swithP=1) 
     114        self.my_doc.discussion_reply('Reply 1', 'text of reply') 
     115        testMailSend(self, state='approve') 
     116        testMailSend(self, state='published') 
     117 
     118     
     119    def testOFFModerationApprove(self): 
     120        self.prefs._updateProperty('enable_moderation', 0) 
     121         
     122        # Test Enable Approve Notification & Disable Published Notification 
     123        self.setApprovePublished(swithA=1,swithP=0) 
     124        self.my_doc.discussion_reply('Reply 1', 'text of reply') 
     125        testMailSend(self, state='approve') 
     126        testNotMailSend(self, state='published') 
     127 
     128 
     129    def testOFFModerationPublished(self):  
     130        self.prefs._updateProperty('enable_moderation', 0) 
     131         
     132        # Test Enable Published Notification  & Disable Approve Notification 
     133        self.setApprovePublished(swithA=0,swithP=1) 
     134        self.my_doc.discussion_reply('Reply 1', 'text of reply') 
     135        testNotMailSend(self, state='approve') 
     136        testMailSend(self, state='published') 
     137 
     138 
     139    def testOFFModeration(self):  
     140        self.prefs._updateProperty('enable_moderation', 0) 
     141         
     142        # Test Disable Published Notification & Disable Approve Notification 
     143        self.setApprovePublished(swithA=0,swithP=0) 
     144        self.my_doc.discussion_reply('Reply 1', 'text of reply') 
     145        testNotMailSend(self, state='approve') 
     146        testNotMailSend(self, state='published') 
     147         
     148 
    191149 
    192150TESTS = [TestNotification] 
Note: See TracChangeset for help on using the changeset viewer.