Browse Source

[#49] Changed the migration handler used in the tests for Model

Roland Haroutiounian 9 years ago
parent
commit
eaf0520d3b
1 changed files with 17 additions and 19 deletions
  1. 17
    19
      EditorialModel/test/test_model.py

+ 17
- 19
EditorialModel/test/test_model.py View File

7
 from EditorialModel.fields import EmField
7
 from EditorialModel.fields import EmField
8
 
8
 
9
 from EditorialModel.backend.json_backend import EmBackendJson
9
 from EditorialModel.backend.json_backend import EmBackendJson
10
-from EditorialModel.migrationhandler.dummy import DummyMigrationHandler
10
+#from EditorialModel.migrationhandler.dummy import DummyMigrationHandler
11
+from EditorialModel.migrationhandler.django import DjangoMigrationHandler
11
 
12
 
12
 class TestModel(unittest.TestCase):
13
 class TestModel(unittest.TestCase):
13
 
14
 
14
     def setUp(self):
15
     def setUp(self):
15
-        self.me =  Model(EmBackendJson('EditorialModel/test/me.json'))
16
+        self.me = Model(EmBackendJson('EditorialModel/test/me.json'))
16
 
17
 
17
     def test_init(self):
18
     def test_init(self):
18
         """ Instanciation test """
19
         """ Instanciation test """
19
         model = Model(EmBackendJson('EditorialModel/test/me.json'))
20
         model = Model(EmBackendJson('EditorialModel/test/me.json'))
20
         self.assertTrue(isinstance(model, Model))
21
         self.assertTrue(isinstance(model, Model))
21
-        model = Model(EmBackendJson('EditorialModel/test/me.json'), migration_handler = DummyMigrationHandler(True))
22
 
22
 
23
+        model = Model(EmBackendJson('EditorialModel/test/me.json'), migration_handler=DjangoMigrationHandler('test',debug=True))
23
         self.assertTrue(isinstance(model, Model))
24
         self.assertTrue(isinstance(model, Model))
24
 
25
 
25
     def test_components(self):
26
     def test_components(self):
27
         for comp_class in [EmClass, EmType, EmField, EmFieldGroup]:
28
         for comp_class in [EmClass, EmType, EmField, EmFieldGroup]:
28
             comp_l = self.me.components(comp_class)
29
             comp_l = self.me.components(comp_class)
29
             for component in comp_l:
30
             for component in comp_l:
30
-                self.assertTrue(isinstance(component, comp_class), "Model.components method don't return EmComponent of the right type. Asked for {} but got {}".format(type(comp_class), type(component)))
31
+                self.assertTrue(isinstance(component, comp_class), "Model.components method doesn't return EmComponent of the right type. Asked for {} but got {}".format(type(comp_class), type(component)))
31
 
32
 
32
     def test_sort_components(self):
33
     def test_sort_components(self):
33
         """ Test that Model.sort_components method actually sort components """
34
         """ Test that Model.sort_components method actually sort components """
34
-        #disordering an EmClass
35
+        # disordering an EmClass
35
         cl_l = self.me.components(EmClass)
36
         cl_l = self.me.components(EmClass)
36
         last_class = cl_l[0]
37
         last_class = cl_l[0]
37
         last_class.rank = 10000
38
         last_class.rank = 10000
38
         self.me.sort_components(EmClass)
39
         self.me.sort_components(EmClass)
39
-        self.assertEqual(self.me._components['EmClass'][-1].uid, last_class.uid, "The methode sort_components don't really sort by rank")
40
+        self.assertEqual(self.me._components['EmClass'][-1].uid, last_class.uid, "The sort_components method doesn't really sort by rank")
40
 
41
 
41
     def test_new_uid(self):
42
     def test_new_uid(self):
42
-        """ Test that Model.new_uid return a new uniq uid """
43
+        """ Test that model.new_uid return a new uniq uid """
43
         new_uid = self.me.new_uid()
44
         new_uid = self.me.new_uid()
44
         self.assertNotIn(new_uid, self.me._components['uids'].keys())
45
         self.assertNotIn(new_uid, self.me._components['uids'].keys())
45
 
46
 
46
-    
47
     def test_hash(self):
47
     def test_hash(self):
48
-        """ Test that __hash__ and __eq__ works properly on models """
49
-        me =  Model(EmBackendJson('EditorialModel/test/me.json'))
50
-        me2 =  Model(EmBackendJson('EditorialModel/test/me.json'), migration_handler = DummyMigrationHandler(True))
48
+        """ Test that __hash__ and __eq__ work properly on models """
49
+        me1 = Model(EmBackendJson('EditorialModel/test/me.json'))
50
+        me2 = Model(EmBackendJson('EditorialModel/test/me.json'), migration_handler=DjangoMigrationHandler('test', debug=True))
51
 
51
 
52
-        self.assertEqual(hash(me), hash(me2), "When instanciate from the same backend & file but with another migration handler the hashes differs")
53
-        self.assertTrue(me, me2)
52
+        self.assertEqual(hash(me1), hash(me2), "When instanciate from the same backend & file but with another migration handler the hashes differs")
53
+        self.assertTrue(me1, me2)
54
 
54
 
55
-        cl_l = me.classes()
55
+        cl_l = me1.classes()
56
         cl_l[0].modify_rank(1)
56
         cl_l[0].modify_rank(1)
57
 
57
 
58
-        self.assertNotEqual(hash(me), hash(me2), "After a class rank modification the hashes are the same")
59
-        self.assertFalse(me, me2)
58
+        self.assertNotEqual(hash(me1), hash(me2), "After a class rank modification the hashes are the same")
59
+        self.assertFalse(me1, me2)
60
 
60
 
61
         cl_l = me2.classes()
61
         cl_l = me2.classes()
62
         cl_l[0].modify_rank(1)
62
         cl_l[0].modify_rank(1)
63
 
63
 
64
         self.assertEqual(hash(me), hash(me2), "After doing sames modifications in the two models the hashes differs")
64
         self.assertEqual(hash(me), hash(me2), "After doing sames modifications in the two models the hashes differs")
65
-        self.assertTrue(me, me2)
66
-
67
-
65
+        self.assertTrue(me1, me2)

Loading…
Cancel
Save