Ignore:
Timestamp:
01/18/12 11:59:51 (9 years ago)
Author:
pcosquer
Message:

3D branch: merge changes from trunk (rev [661])

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3D/openPLM/plmapp/tests/controllers/part.py

    r472 r662  
    2929import datetime 
    3030 
    31 from openPLM.plmapp.controllers import PLMObjectController, PartController 
     31from openPLM.plmapp.controllers import PLMObjectController, PartController, \ 
     32        DocumentController 
     33import openPLM.plmapp.exceptions as exc 
     34import openPLM.plmapp.models as models 
     35from openPLM.plmapp.lifecycle import LifecycleList 
    3236 
    3337from openPLM.plmapp.tests.controllers.plmobject import ControllerTest 
     
    4852        self.controller4 = self.CONTROLLER.create("aPart4", self.TYPE, "a", 
    4953                                                  self.user, self.DATA) 
     54        self.document = DocumentController.create("Doc1", "Document", "a", 
     55                self.user, self.DATA) 
     56        self.document.add_file(self.get_file()) 
     57        self.document.promote() 
     58        for ctrl in (self.controller, self.controller2): 
     59            ctrl.attach_to_document(self.document) 
    5060 
    5161    def test_add_child(self): 
     
    102112 
    103113    def test_modify_child(self): 
    104         self.controller.add_child(self.controller2, 10, 15) 
    105         self.controller.modify_child(self.controller2, 3, 5) 
     114        self.controller.add_child(self.controller2, 10, 15, "-") 
     115        self.controller.modify_child(self.controller2, 3, 5, "kg") 
    106116        children = self.controller.get_children() 
    107117        level, link = children[0] 
    108118        self.assertEqual(link.quantity, 3) 
    109119        self.assertEqual(link.order, 5) 
     120        self.assertEqual(link.unit, "kg") 
    110121 
    111122    def test_delete_child(self): 
     
    152163 
    153164    def test_is_promotable1(self): 
     165        """Tests promotion from draft state, an official document is attached.""" 
    154166        self.failUnless(self.controller.is_promotable()) 
    155167 
    156168    def test_is_promotable2(self): 
     169        """Tests promotion from official state.""" 
    157170        self.controller.promote() 
    158171        self.failUnless(self.controller.is_promotable()) 
    159172     
    160173    def test_is_promotable3(self): 
     174        """Tests promotions with an official child.""" 
     175        self.controller2.promote() 
    161176        self.controller.add_child(self.controller2, 10, 15) 
    162177        self.failUnless(self.controller.is_promotable()) 
    163178         
    164179    def test_is_promotable4(self): 
     180        """Tests promotion from official state, with a deprecated child.""" 
    165181        self.controller2.promote() 
    166         self.controller.add_child(self.controller2, 10, 15) 
    167         self.failUnless(self.controller.is_promotable()) 
    168  
    169     def test_is_promotable5(self): 
    170         self.controller.add_child(self.controller2, 10, 15) 
    171         self.controller.promote() 
    172         self.failIf(self.controller.is_promotable()) 
    173  
    174  
     182        self.controller2.promote() 
     183        self.controller.add_child(self.controller2, 10, 15) 
     184        self.failUnless(self.controller.is_promotable()) 
     185 
     186    def test_is_promotable_no_document(self): 
     187        "Tests that a part with no document attached is not promotable.""" 
     188        self.failIf(self.controller3.is_promotable()) 
     189 
     190    def test_is_promotable_no_official_document(self): 
     191        "Tests that a part with no official document attached is not promotable." 
     192        doc = DocumentController.create("doc_2", "Document", "a", self.user, 
     193                self.DATA) 
     194        self.controller3.attach_to_document(doc) 
     195        self.failIf(self.controller3.is_promotable()) 
     196 
     197    def test_is_promotable_one_official_document(self): 
     198        """Tests that a part with one official document attached and another 
     199        not official is promotable.""" 
     200        doc = DocumentController.create("doc_2", "Document", "a", self.user, 
     201                self.DATA) 
     202        self.controller3.attach_to_document(self.document) 
     203        self.controller3.attach_to_document(doc) 
     204        self.failUnless(self.controller3.is_promotable()) 
     205 
     206    def test_promote(self): 
     207        controller = self.controller 
     208        self.assertEqual(controller.state.name, "draft") 
     209        controller.promote() 
     210        self.assertEqual(controller.state.name, "official") 
     211        self.failIf(controller.is_editable) 
     212        self.assertRaises(exc.PromotionError, controller.demote) 
     213        lcl = LifecycleList("diop", "official", "draft",  
     214                "issue1", "official", "deprecated") 
     215        lc = models.Lifecycle.from_lifecyclelist(lcl) 
     216        controller.lifecycle = lc 
     217        controller.state = models.State.objects.get(name="draft") 
     218        controller.save() 
     219        controller.promote() 
     220        self.assertEqual(controller.state.name, "issue1") 
     221        controller.demote() 
     222        self.assertEqual(controller.state.name, "draft") 
     223        self.failUnless(controller.is_editable) 
     224 
     225 
Note: See TracChangeset for help on using the changeset viewer.