Changeset 36 in main


Ignore:
Timestamp:
06/24/10 15:16:35 (11 years ago)
Author:
pcosquer
Message:

more tests

Location:
trunk/openPLM/plmapp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/openPLM/plmapp/models.py

    r26 r36  
    8989        """ 
    9090         
    91         temp = [] 
    92         for lcs in LifecycleStates.objects.filter(lifecycle=self): 
    93             temp.append((lcs.rank, lcs.state.name)) 
    94         temp.sort() 
    95         return LifecycleList(self.name, *[state for rank, state in temp]) 
     91        lcs = LifecycleStates.objects.filter(lifecycle=self).order_by("rank") 
     92        return LifecycleList(self.name, *(l.state.name for l in lcs)) 
    9693 
    9794    def __iter__(self): 
  • trunk/openPLM/plmapp/tests.py

    r35 r36  
    1515 
    1616 
     17class LifecycleTest(TestCase): 
     18    def test_get_default(self): 
     19        lifecycle = get_default_lifecycle() 
     20     
     21    def test_to_list(self): 
     22        lifecycle = get_default_lifecycle() 
     23        lc_list = lifecycle.to_states_list() 
     24        self.assertEqual(lc_list.name, lifecycle.name) 
     25        lcs = LifecycleStates.objects.filter(lifecycle=lifecycle).order_by("rank") 
     26        self.assertEqual(len(lcs), len(lc_list)) 
     27 
     28    def test_from_list(self): 
     29        cycle = LifecycleList("cycle_name", "a", "b", "c") 
     30        lifecycle = Lifecycle.from_lifecyclelist(cycle) 
     31        self.assertEqual(cycle.name, lifecycle.name) 
     32 
     33    def test_iteration(self): 
     34        cycle = LifecycleList("cycle_name", "a", "b", "c") 
     35        lifecycle = Lifecycle.from_lifecyclelist(cycle) 
     36        for i, state in enumerate(lifecycle): 
     37            self.assertEqual(state, cycle[i]) 
     38 
     39    def test_get_default_state(self): 
     40        state = get_default_state() 
     41        self.assertEqual(state.name, "draft") 
     42         
    1743class ControllerTest(TestCase): 
    1844    CONTROLLER = PLMObjectController 
     
    308334     
    309335    def test_session_forms(self): 
     336        "Tests if form field are kept between two search" 
    310337        response = self.client.get("/home/", {"revision" : "c", "name" : "a name"}) 
    311338        self.assertEqual(response.status_code, 200) 
     
    318345 
    319346    def test_empty(self): 
     347        "Test a search with an empty database" 
    320348        # clear all plmobject so results is empty 
    321349        for obj in PLMObject.objects.all(): 
     
    325353 
    326354    def test_one_result(self): 
     355        "Test a search with one object in the database" 
    327356        results = self.search({"type" : self.TYPE})  
    328357        self.assertEqual(results, [self.controller.object]) 
Note: See TracChangeset for help on using the changeset viewer.