Changeset 1210 in main


Ignore:
Timestamp:
06/12/12 09:16:11 (7 years ago)
Author:
zali
Message:

PLMObject controller: safe_cancel added, tests added for cancel

Location:
trunk/openPLM/plmapp
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/openPLM/plmapp/controllers/plmobject.py

    r1209 r1210  
    737737        """ 
    738738        return self.check_cancel(raise_=False) 
    739  
    740  
     739     
     740    def safe_cancel(self): 
     741        self.check_cancel() 
     742        self.cancel() 
  • trunk/openPLM/plmapp/tests/controllers/plmobject.py

    r1182 r1210  
    567567 
    568568    def test_unpublish_deprecated(self): 
    569         """ Tests that a deprecated opublished bject can be unpublished.""" 
     569        """ Tests that a deprecated published object can be unpublished.""" 
    570570        controller = self.get_published_ctrl() 
    571571        self.promote_to_deprecated(controller) 
     
    597597        ctrl = self.CONTROLLER(controller.object, publisher) 
    598598        self.assertUnpublishError(ctrl) 
    599  
     599     
     600    # cancel test 
     601     
     602    def get_created_ctrl(self): 
     603        controller = self.create("P1") 
     604        controller.object.save() 
     605        return controller 
     606         
     607    def assertCancel(self,ctrl): 
     608        self.assertTrue(ctrl.check_cancel()) 
     609        self.assertTrue(ctrl.can_cancel()) 
     610        ctrl.cancel() 
     611        self.check_cancelled_object(ctrl) 
     612         
     613    def assertCancelError(self, ctrl): 
     614        self.assertRaises(exc.PermissionError, ctrl.check_cancel) 
     615        self.assertRaises(exc.PermissionError, ctrl.check_cancel) 
     616        self.assertRaises(exc.PermissionError, ctrl.check_cancel) 
     617        res = not ctrl.is_draft 
     618        res = res or len(ctrl.get_all_revisions()) > 1 
     619        res = res or not ctrl.check_permission("owner",raise_=False) 
     620        self.assertTrue(res) 
     621     
     622    def test_cancel_draft(self): 
     623        """ Tests that a draft object with only one revision can be cancelled""" 
     624        controller = self.get_created_ctrl() 
     625        self.assertCancel(controller) 
     626         
     627    def test_cancel_not_draft(self): 
     628        """ Tests that a non-draft object can *not* be cancelled""" 
     629        controller = self.get_created_ctrl() 
     630        state = controller.object.state 
     631        lifecycle = controller.object.lifecycle 
     632        lcl = lifecycle.to_states_list() 
     633        new_state = lcl.next_state(state.name) 
     634        controller.object.state = models.State.objects.get_or_create(name=new_state)[0] 
     635        controller.object.save() 
     636        self.assertFalse(controller.is_draft) 
     637        self.assertCancelError(controller) 
     638         
     639    def test_cancel_official(self): 
     640        """ Tests that an official object can *not* be cancelled (even by its creator/owner)""" 
     641        controller = self.get_created_ctrl() 
     642        self.promote_to_official(controller) 
     643        self.assertCancelError(controller) 
     644 
     645    def test_cancel_deprecated(self): 
     646        """ Tests that a deprecated object can *not* be cancelled""" 
     647        controller = self.get_created_ctrl() 
     648        self.promote_to_deprecated(controller) 
     649        self.assertCancelError(controller) 
     650         
     651    def test_cancel_cancelled(self): 
     652        """ Tests that a cancelled object can *not* be cancelled""" 
     653        controller = self.get_created_ctrl() 
     654        controller.cancel() 
     655        self.assertCancelError(controller) 
     656 
     657    def test_cancel_not_owner(self): 
     658        """ Tests that only a user who does not have owner rights on the object 
     659        can not cancel.""" 
     660        controller = self.get_created_ctrl() 
     661        user = self.get_contributor() 
     662        ctrl = self.CONTROLLER(controller.object, user) 
     663        self.assertCancelError(ctrl) 
     664         
     665    def test_cancel_revised(self): 
     666        """Tests that an object (here a draft) with more than one revision can *not* be cancelled""" 
     667        controller = self.get_created_ctrl() 
     668        ctrl = controller.revise("b") 
     669        self.assertCancelError(ctrl) 
  • trunk/openPLM/plmapp/views/main.py

    r1209 r1210  
    268268        actions = (("demote", obj.demote), ("promote", obj.promote), 
    269269                   ("publish", obj.publish), ("unpublish", obj.unpublish), 
    270                    ("cancel", obj.cancel,)) 
     270                   ("cancel", obj.safe_cancel,)) 
    271271        if password_form.is_valid(): 
    272272            for action_name, method in actions: 
Note: See TracChangeset for help on using the changeset viewer.