Browse Source

Added test for EmComponent.get_max_rank(), replacing the default value for rank by the one processed by get_max_rank

Yann Weber 10 years ago
parent
commit
f41d164603
2 changed files with 13 additions and 17 deletions
  1. 4
    5
      EditorialModel/components.py
  2. 9
    12
      EditorialModel/test/test_component.py

+ 4
- 5
EditorialModel/components.py View File

@@ -203,7 +203,7 @@ class EmComponent(object):
203 203
         dbe = cls.db_engine()
204 204
         conn = dbe.connect()
205 205
 
206
-        kwargs['rank'] = -1 #Warning !!!
206
+        kwargs['rank'] = cls.get_max_rank( kwargs[cls.ranked_in] )+1
207 207
 
208 208
         table = sql.Table(cls.table, sqlutils.meta(dbe))
209 209
         req = table.insert(kwargs)
@@ -265,7 +265,8 @@ class EmComponent(object):
265 265
 
266 266
     ## get_max_rank
267 267
     # Retourne le rank le plus élevé pour le groupe de component au quel apartient l'objet actuelle
268
-    #return int
268
+    # @param ranked_in_value mixed: The rank "family"
269
+    # @param return -1 if no EmComponent found else return an integer >= 0
269 270
     @classmethod
270 271
     def get_max_rank(cls, ranked_in_value):
271 272
         dbe = cls.db_engine()
@@ -275,12 +276,10 @@ class EmComponent(object):
275 276
         res = c.execute(req)
276 277
         res = res.fetchone()
277 278
         c.close()
278
-        if(res != None):
279
+        if res != None:
279 280
             return res['rank']
280 281
         else:
281 282
             return -1
282
-            #logger.error("Bad argument")
283
-            #raise EmComponentRankingNotExistError('The ranking of the component named : ' + self.name + 'is empty')
284 283
 
285 284
     ## modify_rank
286 285
     #

+ 9
- 12
EditorialModel/test/test_component.py View File

@@ -39,18 +39,8 @@ def setUpModule():
39 39
         
40 40
         The goal are to overwrtie Db configs, and prepare objects for test_case initialisation
41 41
     """
42
-    #Overwritting db confs to make tests
43
-
42
+    cleanDb(TEST_COMPONENT_DBNAME)
44 43
 
45
-    """
46
-    settings.LODEL2SQLWRAPPER['db'] = {
47
-        'default': {
48
-            'ENGINE': 'sqlite',
49
-            'NAME': TEST_COMPONENT_DBNAME
50
-        }
51
-    }
52
-    
53
-    """
54 44
     setDbConf(TEST_COMPONENT_DBNAME)
55 45
     #Disable logging but CRITICAL
56 46
     logging.basicConfig(level=logging.CRITICAL)
@@ -440,7 +430,14 @@ class TestCreate(ComponentTestCase):
440 430
             self.fail("create raises but should return the existing EmComponent instance instead")
441 431
         self.assertEqual(tc.uid, tc2.uid, "Created twice the same EmComponent")
442 432
         pass
443
-        
433
+
434
+    def testGetMaxRank(self):
435
+        old = EmTestComp.get_max_rank('f')
436
+        EmTestComp.create(name="foobartest", rank_fam = 'f')
437
+        n = EmTestComp.get_max_rank('f')
438
+        self.assertEqual(old+1, n, "Excepted value was "+str(old+1)+" but got "+str(n))
439
+        self.assertEqual(EmTestComp.get_max_rank('z'), -1)
440
+        pass
444 441
 
445 442
 #====================#
446 443
 # EmComponent.delete #

Loading…
Cancel
Save