|
@@ -7,19 +7,20 @@ from EditorialModel.fieldgroups import EmFieldGroup
|
7
|
7
|
from EditorialModel.fields import EmField
|
8
|
8
|
|
9
|
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
|
13
|
class TestModel(unittest.TestCase):
|
13
|
14
|
|
14
|
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
|
18
|
def test_init(self):
|
18
|
19
|
""" Instanciation test """
|
19
|
20
|
model = Model(EmBackendJson('EditorialModel/test/me.json'))
|
20
|
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
|
24
|
self.assertTrue(isinstance(model, Model))
|
24
|
25
|
|
25
|
26
|
def test_components(self):
|
|
@@ -27,41 +28,38 @@ class TestModel(unittest.TestCase):
|
27
|
28
|
for comp_class in [EmClass, EmType, EmField, EmFieldGroup]:
|
28
|
29
|
comp_l = self.me.components(comp_class)
|
29
|
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
|
33
|
def test_sort_components(self):
|
33
|
34
|
""" Test that Model.sort_components method actually sort components """
|
34
|
|
- #disordering an EmClass
|
|
35
|
+ # disordering an EmClass
|
35
|
36
|
cl_l = self.me.components(EmClass)
|
36
|
37
|
last_class = cl_l[0]
|
37
|
38
|
last_class.rank = 10000
|
38
|
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
|
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
|
44
|
new_uid = self.me.new_uid()
|
44
|
45
|
self.assertNotIn(new_uid, self.me._components['uids'].keys())
|
45
|
46
|
|
46
|
|
-
|
47
|
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
|
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
|
61
|
cl_l = me2.classes()
|
62
|
62
|
cl_l[0].modify_rank(1)
|
63
|
63
|
|
64
|
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)
|