|
@@ -2,16 +2,44 @@
|
2
|
2
|
|
3
|
3
|
import unittest
|
4
|
4
|
|
|
5
|
+from lodel.editorial_model.model import EditorialModel
|
5
|
6
|
from lodel.editorial_model.components import EmComponent, EmClass, EmField, EmGroup
|
6
|
7
|
from lodel.utils.mlstring import MlString
|
7
|
8
|
from lodel.editorial_model.exceptions import *
|
8
|
9
|
|
|
10
|
+class EditorialModelTestCase(unittest.TestCase):
|
|
11
|
+
|
|
12
|
+ def test_d_hash(self):
|
|
13
|
+ """ Test the deterministic hash method """
|
|
14
|
+ model = EditorialModel("test model", description = "Test EM")
|
|
15
|
+ cls1 = model.new_class('testclass1', display_name = 'Classe de test 1', help_text = 'super aide')
|
|
16
|
+ c1f1 = cls1.new_field('c1testfield1', data_handler = None)
|
|
17
|
+ c1f2 = cls1.new_field('c1testfield2', data_handler = None)
|
|
18
|
+ cls2 = model.new_class('testclass2')
|
|
19
|
+ c2f1 = cls2.new_field('c2testfield1', data_handler = None)
|
|
20
|
+ c2f2 = cls2.new_field('c2testfield2', data_handler = None)
|
|
21
|
+ grp1 = model.new_group('testgroup1')
|
|
22
|
+ grp1.add_components((cls1, c1f1))
|
|
23
|
+ grp2 = model.new_group('testgroup2')
|
|
24
|
+ grp2.add_components((cls2, c1f2, c2f1, c2f2))
|
|
25
|
+ grp2.add_dependencie(grp1)
|
|
26
|
+ e_hash = 105398984207109703509695004279282115094
|
|
27
|
+ self.assertEqual(model.d_hash(), e_hash)
|
|
28
|
+
|
|
29
|
+ c2f1.uid = 'foobar'
|
|
30
|
+ self.assertNotEqual(model.d_hash(), e_hash)
|
|
31
|
+
|
|
32
|
+ c2f1.uid = 'c2testfield1'
|
|
33
|
+ self.assertEqual(model.d_hash(), e_hash)
|
|
34
|
+
|
|
35
|
+
|
9
|
36
|
class EmComponentTestCase(unittest.TestCase):
|
10
|
37
|
|
11
|
38
|
def test_abstract_init(self):
|
12
|
39
|
with self.assertRaises(NotImplementedError):
|
13
|
40
|
EmComponent('test')
|
14
|
41
|
|
|
42
|
+
|
15
|
43
|
class EmClassTestCase(unittest.TestCase):
|
16
|
44
|
|
17
|
45
|
def test_init(self):
|
|
@@ -34,6 +62,14 @@ class EmClassTestCase(unittest.TestCase):
|
34
|
62
|
set(['name', 'string', 'lodel_id'])
|
35
|
63
|
)
|
36
|
64
|
|
|
65
|
+ def test_d_hash(self):
|
|
66
|
+ """ Test the deterministic hash method """
|
|
67
|
+ field = EmField('test field', 'foobar')
|
|
68
|
+ e_hash = 16085043663725855508634914630594968402
|
|
69
|
+ self.assertEqual(field.d_hash(), e_hash)
|
|
70
|
+ field.uid = 'test field.'
|
|
71
|
+ self.assertNotEqual(field.d_hash(), e_hash)
|
|
72
|
+
|
37
|
73
|
class EmGroupTestCase(unittest.TestCase):
|
38
|
74
|
|
39
|
75
|
def test_init(self):
|
|
@@ -120,3 +156,9 @@ class EmGroupTestCase(unittest.TestCase):
|
120
|
156
|
for j in range(i+1,10):
|
121
|
157
|
with self.assertRaises(EditorialModelError):
|
122
|
158
|
grps[i].add_dependencie(grps[j])
|
|
159
|
+
|
|
160
|
+ def test_d_hash(self):
|
|
161
|
+ """ Test the deterministic hash method """
|
|
162
|
+ grp = EmGroup('testgrp', display_name = "Test group", help_text="No Help")
|
|
163
|
+ self.assertEqual(grp.d_hash(), 2280847427800301892840867965375148376323815160723628142616247375345365409972670566216414157235977332113867542043807295933781561540623070667142779076339712861412992217365501372435232184530261327450635383095)
|
|
164
|
+
|