Changeset 162

Show
Ignore:
Timestamp:
01/11/06 01:24:46
Author:
mylan
Message:

Add deleting discussion reply tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • qPloneComments/trunk/tests/testQPloneComments.py

    r161 r162  
    4545 
    4646    def afterSetUp(self): 
     47        self.loginAsPortalOwner() 
     48 
    4749        self.qi = self.portal.portal_quickinstaller 
    4850        self.qi.installProduct(PRODUCT) 
     
    124126 
    125127    def afterSetUp(self): 
     128        self.loginAsPortalOwner() 
     129 
    126130        self.qi = self.portal.portal_quickinstaller 
    127131        self.qi.installProduct(PRODUCT) 
    128132        # VERY IMPORTANT to guarantee product skin's content visibility 
    129133        self._refreshSkinData() 
    130          
    131         self.loginAsPortalOwner() 
     134 
    132135        '''Preparation for functional testing''' 
    133136        # add members 
     
    254257 
    255258class TestModeration(PloneTestCase.FunctionalTestCase): 
     259 
    256260    def afterSetUp(self): 
     261        self.loginAsPortalOwner() 
     262 
    257263        self.qi = self.portal.portal_quickinstaller 
    258264        self.qi.installProduct(PRODUCT) 
    259265        # VERY IMPORTANT to guarantee product skin's content visibility 
    260266        self._refreshSkinData() 
    261  
    262         #self.portal.changeSkin('Plone Default') 
    263  
    264         self.loginAsPortalOwner() 
    265267 
    266268        '''Preparation for functional testing''' 
     
    279281        # add Discussion Manager group 
    280282        portal_groups = self.portal.portal_groups 
    281         portal_groups.addGroup('DiscussionManagers', roles=['DiscussionManager']) 
    282         dm_group = portal_groups.getGroupById(id='DiscussionManagers') 
     283        portal_groups.addGroup('DiscussionManager', roles=['DiscussionManager']) 
     284        dm_group = portal_groups.getGroupById(id='DiscussionManager') 
    283285        dm_group.addMember('dm_admin') 
    284286        dm_group.addMember('dm_owner') 
     
    355357                             re.S|re.M) 
    356358        # FOR user without DiscussionManager role 
    357         # publish button MUST BE ABSENT in document view form  
     359        # publish reply button MUST BE ABSENT in document view form  
    358360        for u in ['admin', 'reviewer','owner','member','anonym']: 
    359361            self.logout() 
     
    365367            html = str(self.publish(self.portal.id+'/%s' % doc_id, auth)) 
    366368            m = pattern.match(html) 
    367             self.assert_(not m, "Publish button present for %s user without DiscussionManager role" % u) 
     369            self.assert_(not m, "Publish reply button present for %s user without DiscussionManager role" % u) 
    368370         
    369371        # Check users with DiscussionManager role 
     
    373375            auth = '%s:secret_%s' % (u,u) 
    374376            doc_id = "doc_%s" % u 
    375             # 1. Must PRESENT publish button 
     377            # 1. Must PRESENT publish reply button 
    376378            html = str(self.publish(self.portal.id+'/%s' % doc_id, auth)) 
    377379            m = pattern.match(html) 
     
    394396            self.assert_(replies, "User %s with DiscussionManager role not publish discussion" % u) 
    395397 
    396  
    397     #def testDeleting(self): 
     398     
     399    def testDeleting(self): 
     400        # Add testing documents and reply for it to portal 
     401        doc_ids = ['doc_dm_admin','doc_dm_reviewer','doc_dm_owner','doc_dm_member',\ 
     402                   'doc_admin', 'doc_reviewer','doc_owner','doc_member','doc_anonym'] 
     403        for doc in doc_ids: 
     404            my_doc = self.portal.invokeFactory('Document', id=doc) 
     405            doc_obj = getattr(self.portal, doc) 
     406            doc_obj.edit(text_format='plain', text='hello world from %s' % doc) 
     407            # Create talkback for document and Add comment to my_doc 
     408            self.discussion.getDiscussionFor(doc_obj) 
     409            doc_obj.discussion_reply('A Reply for %s' % doc,'text of reply for %s' % doc) 
     410 
     411        # Prepare pattern for delete reply button presence checking 
     412        pattern = re.compile('.*<input\\s*class="destructive"\\s*type="submit"\\s*value="Remove This Discussion"\\s*/>',\ 
     413                             re.S|re.M) 
     414        # FOR user without Manager role  
     415        # delete reply button MUST BE ABSENT in document view form  
     416        for u in ['dm_reviewer','dm_owner','dm_member','admin','reviewer','owner','member','anonym']: 
     417            self.logout() 
     418            auth = u 
     419            if not u=='anonym': 
     420                self.login(u) 
     421                auth = '%s:secret_%s' % (u,u) 
     422            doc_id = "doc_%s" % u 
     423            html = str(self.publish(self.portal.id+'/%s' % doc_id, auth)) 
     424            m = pattern.match(html) 
     425            self.assert_(not m, "Delete reply button present for %s user without both: DiscussionManager and Manager roles" % u) 
     426 
     427        # Publish doc_admin object, which has Manager role for checking 
     428        # is he can delete published discussion reply 
     429        self.logout() 
     430        self.login('dm_admin') 
     431        doc_obj = getattr(self.portal, "doc_admin") 
     432        getReplies = self.discussion.getDiscussionFor(doc_obj).getReplies 
     433        replies = getReplies()[0].discussion_publish_comment() 
     434 
     435        # Check users with Manager role for deleting 
     436        for u in ['dm_admin','admin']: 
     437            self.logout() 
     438            self.login(u) 
     439            auth = '%s:secret_%s' % (u,u) 
     440            doc_id = "doc_%s" % u 
     441            # 1. Must PRESENT delete reply button 
     442            html = str(self.publish(self.portal.id+'/%s' % doc_id, auth)) 
     443            m = pattern.match(html) 
     444            self.assert_(m, "It is absent Delete reply button for %s user with DiscussionManager role" % u) 
     445            # 2. Must perform real deleting 
     446            doc_obj = getattr(self.portal, doc_id) 
     447            getReplies = self.discussion.getDiscussionFor(doc_obj).getReplies 
     448            replies = getReplies()  
     449            self.assert_(replies, "User %s with Manager role not view discussion reply" % u) 
     450            replies[0].deleteDiscussion() 
     451            # Check whether discussion reply really deleted 
     452            replies = getReplies() 
     453            self.assert_(not replies, "User %s with Manager role not really delete discussion" % u) 
     454             
    398455         
    399456