Changeset 611

Show
Ignore:
Timestamp:
10/27/06 10:16:55
Author:
crchemist
Message:

New tests added.

Files:

Legend:

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

    r610 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 
     21Support Team 
    2222</tal:signature> 
    2323</div> 
  • qPloneComments/tags/2.2.0-rc1/tests/helperNotify.py

    r610 r611  
    1515PREFIX = os.path.abspath(os.path.dirname(__file__)) 
    1616 
    17 def verifyMail(text,  mail_type): 
    18     pass 
     17ALL_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'] 
    1921 
    2022def sample_file_path(file): 
     
    3133 
    3234def writeToFile(f_path, text): 
    33     result_f = open(f_path,"a"
     35    result_f = open(f_path,'w'
    3436    result_f.write(text+'\n') 
    3537    result_f.close() 
     
    4042    result_f.close() 
    4143 
    42 def 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  
    53 def 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  
    62 def testNotMail(self): 
    63     result = getFileContent(output_file_path('mail.res')) 
    64     self.assert_(not result, "Mail was sended") 
    65  
    6644def _send_MH( self, mfrom, mto, messageText ): 
    67     writeToFile(output_file_path('mail.res'), messageText) 
     45    files = [f for f in os.listdir('./output') if f.startswith('mail')] 
     46    fn = files[-1]+ '1' 
     47    writeToFile(output_file_path(fn), messageText) 
    6848 
    6949def _send_SMH(self, mfrom, mto, messageText, debug=False): 
    70     writeToFile(output_file_path('mail.res'), messageText) 
     50    files = [f for f in os.listdir('./output') if f.startswith('mail')] 
     51    fn = files[-1]+ '1' 
     52    writeToFile(output_file_path(fn), messageText) 
    7153 
    7254def send_SMH(self, message, mto=None, mfrom=None, subject=None, encode=None): 
    73     writeToFile(output_file_path('mail.res'), message) 
     55    files = [f for f in os.listdir('./output') if f.startswith('mail')] 
     56    if files: 
     57        fn = files[-1]+ '1' 
     58    else: 
     59        fn = 'mail' 
     60    writeToFile(output_file_path(fn), message) 
    7461 
    7562def prepareMailSendTest(): 
     
    8067        SecureMailBase.send = send_SMH 
    8168        SecureMailBase._send = _send_SMH 
    82     # clear 'mail.res' file 
    83     clearFile(output_file_path('mail.res')) 
     69 
     70def setProperties(prop_sheet, *props): 
     71    for p in ALL_PROPS: 
     72        prop_sheet._updateProperty(p, p in props) 
     73 
     74def testMailExistance(): 
     75    for f in os.listdir('./output'): 
     76        if f.startswith('mail'): 
     77            return True 
     78    return False 
     79 
     80def cleanOutputDir(): 
     81    for f in os.listdir('./output'): 
     82        if f.startswith('mail'): os.remove('./output/%s'%f) 
  • qPloneComments/tags/2.2.0-rc1/tests/testQPloneCommentsNotification.py

    r610 r611  
    1616PROPERTY_SHEET = "qPloneComments" 
    1717 
    18  
    1918PloneTestCase.installProduct(PRODUCT) 
    2019PloneTestCase.setupPloneSite() 
     
    2625        self.prefs._updateProperty('enable_approve_notification', swithA) 
    2726        self.prefs._updateProperty('enable_published_notification', swithP) 
    28  
    2927 
    3028    def afterSetUp(self): 
     
    5755        member = self.portal.portal_membership.getAuthenticatedMember() 
    5856        member.setMemberProperties({'email':'creator@test.com'}) 
    59          
     57 
    6058        # Add testing document to portal 
    6159        my_doc = self.portal.invokeFactory('Document', id='my_doc') 
     
    7169        prepareMailSendTest() 
    7270 
    73      
    74     def testPublishedOFF(self): 
     71    def test_notificafion_disabled(self): 
     72        cleanOutputDir() 
     73        setProperties(self.prefs) 
    7574        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    76         clearFile(output_file_path('mail.res')) 
     75        self.assert_(not testMailExistance(), 'Mail was sended when all notification was disabled') 
     76 
     77    def test_published_comment_notification(self): 
     78        cleanOutputDir() 
     79        setProperties(self.prefs, 'enable_published_notification') 
     80        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
     81        self.assert_(testMailExistance(), 'Mail was not sended when enable_published_notification') 
     82 
     83    def test_approve_comment_notification(self): 
     84        cleanOutputDir() 
     85        setProperties(self.prefs, 'enable_approve_notification') 
     86        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
     87        self.assert_(testMailExistance(), 'Mail was not sended when enable_approve_notification') 
     88 
     89    def test_reply_comment_user_notification(self): 
     90        cleanOutputDir() 
     91        setProperties(self.prefs, 'enable_reply_user_notification') 
     92        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
     93        self.assert_(not testMailExistance(), 'Mail was sended for simple reply when enable_reply_user_notification') 
     94 
    7795        reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
     96        reply.discussion_reply('A Reply for comment' ,'text of reply for comment') 
     97        reply_for_comment = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
     98        self.assert_(testMailExistance(), 'Mail was not sended when enable_reply_user_notification') 
    7899 
    79         # Set Published Notification OFF 
    80         self.setApprovePublished(swithA=0,swithP=0) 
    81         reply.discussion_publish_comment() 
    82         testNotMail(self) 
     100    def test_rejected_comment_notification(self): 
     101        cleanOutputDir() 
     102        setProperties(self.prefs, 'enable_rejected_user_notification', 'enable_moderation') 
     103        self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
     104        self.assert_(not testMailExistance(), 'Mail was sended when enable_rejected_user_notification was enabled') 
    83105 
    84     def testPublishedON(self): 
     106        reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
     107        self.portal.REQUEST.set('ids', [reply.getId()]) 
     108        self.portal.prefs_recent_comments_delete() 
     109        self.assert_(testMailExistance(), 'Mail was not sended when enable_rejected_user_notification') 
     110 
     111    def test_approve_comment_user__notification(self): 
     112        cleanOutputDir() 
     113        setProperties(self.prefs, 'enable_approve_user_notification') 
    85114        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') 
    93  
    94  
    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          
     115        self.assert_(testMailExistance(), 'Mail was not sended when enable_approve_user_notification') 
    148116 
    149117