Ignore:
Timestamp:
Apr 16, 2010 12:13:55 PM (14 years ago)
Author:
kroman0
Message:

PEP8 fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.plonecomments/branches/jquery/quintagroup/plonecomments/tests/testQPloneCommentsNotification.py

    r1719 r2137  
    1515from Products.CMFPlone.tests.utils import MockMailHost 
    1616 
    17 REXP_TO = re.compile("To:\s*(.*?)$",re.M) 
    18 REXP_SUBJ = re.compile("Subject:\s*(.*?)$",re.M) 
     17REXP_TO = re.compile("To:\s*(.*?)$", re.M) 
     18REXP_SUBJ = re.compile("Subject:\s*(.*?)$", re.M) 
    1919 
    2020 
    2121class TestNotification(FunctionalTestCase): 
    2222 
    23     def setApprovePublished(self, swithA=1,swithP=1): 
     23    def getDiscussionReplies(self, obj): 
     24        return self.discussion.getDiscussionFor(obj).getReplies() 
     25 
     26    def setApprovePublished(self, swithA=1, swithP=1): 
    2427        self.prefs._updateProperty('enable_approve_notification', swithA) 
    2528        self.prefs._updateProperty('enable_published_notification', swithP) 
     
    4649        # Make sure Documents are visible by default 
    4750        # XXX only do this for plone 3 
    48         self.portal.portal_workflow.setChainForPortalTypes(('Document',), 'plone_workflow') 
    49  
    50         portal_properties = getToolByName(self.portal, 'portal_properties', None) 
     51        self.portal.portal_workflow.setChainForPortalTypes(('Document',), 
     52                                                           'plone_workflow') 
     53 
     54        portal_properties = getToolByName(self.portal, 'portal_properties', 
     55                                          None) 
    5156        self.prefs = portal_properties[PROPERTY_SHEET] 
    5257 
    5358        # Add Manager user - 'dm' and add him to Discussion Manager group 
    54         self.portal.portal_membership.addMember('dm', 'secret' , ['Manager'], []) 
     59        self.portal.portal_membership.addMember('dm', 'secret', 
     60                                                ['Manager'], []) 
    5561        portal_groups = getToolByName(self.portal, 'portal_groups') 
    5662        dm_group = portal_groups.getGroupById('DiscussionManager') 
     
    6066        # For prepare mail sending - enter an e-mail adress 
    6167        self.portal.email_from_address = 'mail@plone.test' 
    62         self.prefs._updateProperty('email_discussion_manager', 'discussion.manager@test.com') 
     68        self.prefs._updateProperty('email_discussion_manager', 
     69                                   'discussion.manager@test.com') 
    6370        member = self.portal.portal_membership.getAuthenticatedMember() 
    64         member.setMemberProperties({'email':'creator@test.com'}) 
     71        member.setMemberProperties({'email': 'creator@test.com'}) 
    6572 
    6673        # Add testing document to portal 
    67         my_doc = self.portal.invokeFactory('Document', id='my_doc', title='Doc') 
     74        my_doc = self.portal.invokeFactory('Document', id='my_doc', 
     75                                           title='Doc') 
    6876        self.my_doc = self.portal['my_doc'] 
    6977        self.my_doc.edit(text_format='plain', text='hello world') 
     
    7179        self.discussion.getDiscussionFor(self.my_doc) 
    7280        self.request = self.app.REQUEST 
    73         self.request.form['Creator'] = self.portal.portal_membership.getAuthenticatedMember().getUserName() 
     81        authmember = self.portal.portal_membership.getAuthenticatedMember() 
     82        self.request.form['Creator'] = authmember.getUserName() 
    7483        self.request.form['subject'] = "Reply 1" 
    7584        self.request.form['body_text'] = "text of reply" 
     
    7988    def test_bug_parent_reply(self): 
    8089        setProperties(self.prefs, 'enable_reply_user_notification') 
    81         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    82         parent_reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
     90        self.my_doc.discussion_reply('A Reply for my_doc', 
     91                                     'text of reply for my_doc') 
     92        parent_reply = self.getDiscussionReplies(self.my_doc)[0] 
    8393        parent_reply.discussion_reply('reply', 'text') 
    8494 
    8595    def test_bug_mistakable_names(self): 
    8696        setProperties(self.prefs, 'enable_reply_user_notification') 
    87         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    88         parent_reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
    89  
    90         args={'mto': 'user_email@gmail.com', 
    91               'mfrom': 'admin_email@gmail.com', 
    92               'obj': parent_reply, 
    93               'organization_name': 'org_name', 
    94               'name': parent_reply.getOwnerTuple()[1]} 
     97        self.my_doc.discussion_reply('A Reply for my_doc', 
     98                                     'text of reply for my_doc') 
     99        parent_reply = self.getDiscussionReplies(self.my_doc)[0] 
     100 
     101        args = {'mto': 'user_email@gmail.com', 
     102                'mfrom': 'admin_email@gmail.com', 
     103                'obj': parent_reply, 
     104                'organization_name': 'org_name', 
     105                'name': parent_reply.getOwnerTuple()[1]} 
    95106 
    96107        msg = getMsg(self.portal, 'reply_notify_template', args) 
     
    106117        self.portal.MailHost.reset() 
    107118        setProperties(self.prefs) 
    108         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    109         self.failIf(testMailExistance(self), 'Mail was sended when all notification was disabled.') 
     119        self.my_doc.discussion_reply('A Reply for my_doc', 
     120                                     'text of reply for my_doc') 
     121        self.failIf(testMailExistance(self), 
     122            'Mail was sended when all notification was disabled.') 
    110123 
    111124    def test_published_comment_notification(self): 
    112125        self.portal.MailHost.reset() 
    113126        setProperties(self.prefs, 'enable_published_notification') 
    114         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    115         self.failUnless(testMailExistance(self), 'Mail was not sended when enable_published_notification.') 
     127        self.my_doc.discussion_reply('A Reply for my_doc', 
     128                                     'text of reply for my_doc') 
     129        self.failUnless(testMailExistance(self), 
     130            'Mail was not sended when enable_published_notification.') 
    116131 
    117132    def test_approve_comment_notification(self): 
    118133        self.portal.MailHost.reset() 
    119134        setProperties(self.prefs, 'enable_approve_notification') 
    120         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    121         self.failUnless(testMailExistance(self), 'Mail was not sended when enable_approve_notification.') 
     135        self.my_doc.discussion_reply('A Reply for my_doc', 
     136                                     'text of reply for my_doc') 
     137        self.failUnless(testMailExistance(self), 
     138            'Mail was not sended when enable_approve_notification.') 
    122139 
    123140    def test_reply_comment_user_notification(self): 
    124141        self.portal.MailHost.reset() 
    125142        setProperties(self.prefs, 'enable_reply_user_notification') 
    126         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    127         self.failIf(testMailExistance(self), 'Mail was sended for simple reply when enable_reply_user_notification.') 
    128  
    129         reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
    130         reply.discussion_reply('A Reply for comment' ,'text of reply for comment') 
    131         reply_for_comment = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
    132         self.failUnless(testMailExistance(self), 'Mail was not sended when enable_reply_user_notification.') 
     143        self.my_doc.discussion_reply('A Reply for my_doc', 
     144                                     'text of reply for my_doc') 
     145        self.failIf(testMailExistance(self), 
     146            'Mail was sended for simple reply ' 
     147            'when enable_reply_user_notification.') 
     148 
     149        reply = self.getDiscussionReplies(self.my_doc)[0] 
     150        reply.discussion_reply('A Reply for comment', 
     151                               'text of reply for comment') 
     152        reply_for_comment = self.getDiscussionReplies(self.my_doc)[0] 
     153        self.failUnless(testMailExistance(self), 
     154            'Mail was not sended when enable_reply_user_notification.') 
    133155 
    134156    def test_rejected_comment_notification(self): 
    135157        self.portal.MailHost.reset() 
    136         setProperties(self.prefs, 'enable_rejected_user_notification', 'enable_moderation') 
    137         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    138         self.failIf(testMailExistance(self), 'Mail was sended when enable_rejected_user_notification was enabled.') 
    139  
    140         reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
     158        setProperties(self.prefs, 'enable_rejected_user_notification', 
     159                      'enable_moderation') 
     160        self.my_doc.discussion_reply('A Reply for my_doc', 
     161                                     'text of reply for my_doc') 
     162        self.failIf(testMailExistance(self), 
     163            'Mail was sended when enable_rejected_user_notification' 
     164            ' was enabled.') 
     165 
     166        reply = self.getDiscussionReplies(self.my_doc)[0] 
    141167        self.portal.REQUEST.set('ids', [reply.getId()]) 
    142168        self.portal.prefs_recent_comments_delete() 
    143         self.failUnless(testMailExistance(self), 'Mail was not sended when enable_rejected_user_notification.') 
     169        self.failUnless(testMailExistance(self), 
     170            'Mail was not sended when enable_rejected_user_notification.') 
    144171 
    145172    def test_approve_comment_user__notification(self): 
    146173        self.portal.MailHost.reset() 
    147174        setProperties(self.prefs, 'enable_approve_user_notification') 
    148         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    149         self.failUnless(testMailExistance(self), 'Mail was not sended when enable_approve_user_notification.') 
     175        self.my_doc.discussion_reply('A Reply for my_doc', 
     176                                     'text of reply for my_doc') 
     177        self.failUnless(testMailExistance(self), 
     178            'Mail was not sended when enable_approve_user_notification.') 
    150179 
    151180    def test_bug_notification_on_single_reply_publish(self): 
     
    155184                             for document creator about adding new comment. 
    156185        """ 
    157         properties = ['enable_approve_user_notification', 'enable_reply_user_notification', 
     186        properties = ['enable_approve_user_notification', 
     187                      'enable_reply_user_notification', 
    158188                      'enable_published_notification'] 
    159189        setProperties(self.prefs, *properties) 
    160190        #setProperties(self.prefs, 'enable_published_notification', ) 
    161         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    162         reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
    163         reply.discussion_reply('A Reply for reply for my_doc' ,'text of reply on reply for my_doc') 
    164         reply2 = self.discussion.getDiscussionFor(reply).getReplies()[0] 
     191        self.my_doc.discussion_reply('A Reply for my_doc', 
     192                                     'text of reply for my_doc') 
     193        reply = self.getDiscussionReplies(self.my_doc)[0] 
     194        reply.discussion_reply('A Reply for reply for my_doc', 
     195                               'text of reply on reply for my_doc') 
     196        reply2 = self.getDiscussionReplies(reply)[0] 
    165197 
    166198        self.portal.MailHost.reset() 
    167199        reply2.discussion_publish_comment() 
    168200        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)], 
     201        self.failUnless([1 for m in mails 
     202            if REXP_SUBJ.search(m) and \ 
     203            'replied' in REXP_SUBJ.search(m).group(1)], 
    170204            'No notification for reply.' % properties) 
    171         self.failUnless([1 for m in mails if REXP_SUBJ.search(m) and 'added' in REXP_SUBJ.search(m).group(1)], 
     205        self.failUnless([1 for m in mails 
     206            if REXP_SUBJ.search(m) and \ 
     207            'added' in REXP_SUBJ.search(m).group(1)], 
    172208            'No notification for adding comment.' % properties) 
    173         self.failUnless([1 for m in mails if REXP_SUBJ.search(m) and 'published' in REXP_SUBJ.search(m).group(1)], 
     209        self.failUnless([1 for m in mails 
     210            if REXP_SUBJ.search(m) and \ 
     211            'published' in REXP_SUBJ.search(m).group(1)], 
    174212            'No notification for publishing comment.' % properties) 
    175213 
     
    178216            Mail about rejecing comment should be sent to comentator. 
    179217        """ 
    180         properties = ['enable_rejected_user_notification',] 
     218        properties = ['enable_rejected_user_notification', ] 
    181219        setProperties(self.prefs, *properties) 
    182220        #setProperties(self.prefs, 'enable_published_notification', ) 
    183         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') 
    184         reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] 
     221        self.my_doc.discussion_reply('A Reply for my_doc', 
     222                                     'text of reply for my_doc') 
     223        reply = self.getDiscussionReplies(self.my_doc)[0] 
    185224 
    186225        self.portal.MailHost.reset() 
     
    188227        mails = [str(m) for m in self.portal.MailHost.messages] 
    189228        subject = 'Your comment on Doc was not approved' 
    190         self.failUnless([1 for m in mails if REXP_SUBJ.search(m) and REXP_SUBJ.search(m).group(1)==subject], 
     229        self.failUnless([1 for m in mails 
     230            if REXP_SUBJ.search(m) and \ 
     231            REXP_SUBJ.search(m).group(1) == subject], 
    191232            'No notification for rejecting comment.' % properties) 
    192233 
Note: See TracChangeset for help on using the changeset viewer.