|
@@ -18,7 +18,7 @@ from EditorialModel.fields import EmField
|
18
|
18
|
import EditorialModel.fieldtypes as fieldTypes
|
19
|
19
|
from EditorialModel.model import Model
|
20
|
20
|
from EditorialModel.backend.json_backend import EmBackendJson
|
21
|
|
-
|
|
21
|
+from EditorialModel.migrationhandler.django import DjangoMigrationHandler
|
22
|
22
|
#from Database import sqlutils, sqlsetup
|
23
|
23
|
#import sqlalchemy as sqla
|
24
|
24
|
|
|
@@ -31,9 +31,8 @@ EM_TEST_OBJECT = None
|
31
|
31
|
# define the Database for this module (an sqlite database)
|
32
|
32
|
def setUpModule():
|
33
|
33
|
global EM_TEST_OBJECT
|
34
|
|
- EM_TEST_OBJECT = Model(EmBackendJson(EM_TEST))
|
|
34
|
+ EM_TEST_OBJECT = Model(EmBackendJson(EM_TEST)) # , migration_handler=DjangoMigrationHandler('LodelTestInstance'))
|
35
|
35
|
logging.basicConfig(level=logging.CRITICAL)
|
36
|
|
- #settings.LODEL2SQLWRAPPER['db']['default'] = {'ENGINE':'sqlite', 'NAME':'/tmp/testdb.sqlite'}
|
37
|
36
|
|
38
|
37
|
class ClassesTestCase(TestCase):
|
39
|
38
|
|
|
@@ -59,7 +58,7 @@ class TestEmClassCreation(ClassesTestCase):
|
59
|
58
|
testClass = EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': 'testclass1', 'classtype': EmClassType.entity['name']})
|
60
|
59
|
|
61
|
60
|
#We check the uid
|
62
|
|
- self.assertEqual(testClass.uid, 22)
|
|
61
|
+ self.assertEqual(testClass.uid, 18)
|
63
|
62
|
|
64
|
63
|
# We check that the class has been added in the right list in the model object
|
65
|
64
|
class_components_records = EM_TEST_OBJECT.components(EmClass)
|
|
@@ -76,49 +75,41 @@ class TestEmClassCreation(ClassesTestCase):
|
76
|
75
|
|
77
|
76
|
# Testing class deletion (and associated table drop)
|
78
|
77
|
class TestEmClassDeletion(ClassesTestCase):
|
79
|
|
-
|
|
78
|
+
|
80
|
79
|
def setUp(self):
|
81
|
|
- self.names = ['testClass1', 'testClass2', 'testClass3']
|
82
|
|
- EmClass.create(self.names[0], EmClassType.entity)
|
83
|
|
- EmClass.create(self.names[1], EmClassType.entry)
|
84
|
|
- EmClass.create(self.names[2], EmClassType.person)
|
85
|
|
- pass
|
86
|
|
-
|
87
|
|
- # test if the table is deleted after a call to delete
|
|
80
|
+ self.names = ['testClasse1', 'testClasse2', 'testClasse3']
|
|
81
|
+ self.emclasses = []
|
|
82
|
+ self.emclasses.append(EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': self.names[0], 'classtype': EmClassType.entity['name']}))
|
|
83
|
+ self.emclasses.append(EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': self.names[1], 'classtype': EmClassType.entry['name']}))
|
|
84
|
+ self.emclasses.append(EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': self.names[2], 'classtype': EmClassType.person['name']}))
|
|
85
|
+
|
|
86
|
+ # tests if the table is deleted after a call to delete
|
88
|
87
|
def test_table_delete(self):
|
89
|
|
- """ Test associated table deletetion on EmClass deletion """
|
90
|
|
- dbe = sqlutils.get_engine()
|
91
|
|
- for i,class_name in enumerate(self.names):
|
92
|
|
- cur_class = EmClass(class_name)
|
93
|
|
- self.assertTrue(cur_class.delete(), "delete method didn't return True but the class has no fieldgroups")
|
94
|
|
- meta = sqlutils.meta(dbe)
|
95
|
|
- table_list = meta.tables.keys()
|
96
|
|
- for deleted_name in self.names[:i+1]:
|
97
|
|
- self.assertNotIn(deleted_name, table_list, "Table still exist but the class was deleted")
|
98
|
|
- for not_deleted_name in self.names[i+1:]:
|
99
|
|
- self.assertIn(not_deleted_name, table_list, "Table don't exist but the class was NOT deleted")
|
100
|
|
- with self.assertRaises(EmComponentNotExistError,msg="This EmClass should be deleted"):
|
101
|
|
- EmClass(class_name)
|
102
|
|
- pass
|
103
|
|
-
|
104
|
|
- # test if delete refuse to delete if a class had fieldgroups
|
|
88
|
+ """ Test associated table deletion on EmClass deletion """
|
|
89
|
+ for i, class_object in enumerate(self.emclasses):
|
|
90
|
+ self.assertTrue(EM_TEST_OBJECT.delete_component(class_object.uid), "delete method didn't return True but the class has no fieldgroups")
|
|
91
|
+
|
|
92
|
+ # TODO check : "table still exists but the class was deleted"
|
|
93
|
+ # TODO check : "table doesn't exist but the class was not deleted"
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+ # tests if delete refuse to delete if a class had fieldgroups
|
105
|
97
|
def test_table_refuse_delete(self):
|
106
|
|
- """ Test delete on an EmClass has fieldgroup """
|
107
|
|
- test_class = EmClass(self.names[0])
|
108
|
|
- fieldgroup = EmFieldGroup.create('fooFieldGroup', test_class)
|
109
|
|
- self.assertFalse(test_class.delete(), "delete method returns True but the class has fieldgroup")
|
110
|
|
- dbe = sqlutils.get_engine()
|
111
|
|
- meta = sqlutils.meta(dbe)
|
112
|
|
- self.assertIn(self.names[0], meta.tables, "Table has been deleted but the class has fieldgroup")
|
|
98
|
+ """ Test delete on an EmClass that has fieldgroup """
|
|
99
|
+ test_class = EM_TEST_OBJECT.create_component(EmClass.__name__,{'name': 'testfgclass1', 'classtype': EmClassType.entity['name']})
|
|
100
|
+ fieldgroup = EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': 'testsubfg1', 'class_id': test_class.uid})
|
|
101
|
+ self.assertFalse(EM_TEST_OBJECT.delete_component(test_class.uid), "delete method returns True but the class has fieldgroup(s)")
|
|
102
|
+
|
|
103
|
+ # TODO check : "table has been deleted but the class has fieldgroup"
|
|
104
|
+
|
113
|
105
|
try:
|
114
|
|
- EmClass(self.names[0])
|
|
106
|
+ EM_TEST_OBJECT.component(test_class.uid)
|
115
|
107
|
except EmComponentNotExistError:
|
116
|
108
|
self.fail("The class has been deleted but it has fieldgroups")
|
117
|
|
- pass
|
118
|
109
|
|
119
|
110
|
|
120
|
|
-# interface to fieldGroups
|
121
|
|
-class TestEmClassFieldgroups(ClassesTestCase):
|
|
111
|
+# Interface to fieldgroups
|
|
112
|
+class TestEmClassFieldgrousp(ClassesTestCase):
|
122
|
113
|
|
123
|
114
|
@classmethod
|
124
|
115
|
def setUpClass(cls):
|
|
@@ -126,28 +117,29 @@ class TestEmClassFieldgroups(ClassesTestCase):
|
126
|
117
|
|
127
|
118
|
def setUp(self):
|
128
|
119
|
ClassesTestCase.setUpClass()
|
129
|
|
- test_class = EmClass.create('testClass', EmClassType.entity)
|
|
120
|
+ self.test_class = EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': 'testClassFg', 'classtype': EmClassType.entity['name']})
|
130
|
121
|
|
131
|
|
- # test if fieldgroups() return a list of EmFieldGroup
|
|
122
|
+ # tests if fieldgroups() returns a list of EmFieldGroup
|
132
|
123
|
def test_fieldgroups(self):
|
133
|
|
- """ Test if fieldgroups method return the right list of EmFielGroup """
|
134
|
|
- test_class = EmClass('testClass')
|
135
|
|
- fg1 = EmFieldGroup.create('fg1', test_class)
|
136
|
|
- fg2 = EmFieldGroup.create('fg2', test_class)
|
|
124
|
+ """ Tests if fieldgroups method returns the right list of EmFieldGroup """
|
|
125
|
+ test_class = EM_TEST_OBJECT.component(self.test_class.uid)
|
|
126
|
+ fg1 = EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': 'testClassFg1', 'class_id': test_class.uid})
|
|
127
|
+ fg2 = EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': 'testClassFg2', 'class_id': test_class.uid})
|
137
|
128
|
|
138
|
129
|
fieldgroups = test_class.fieldgroups()
|
139
|
130
|
self.assertIsInstance(fieldgroups, list)
|
140
|
131
|
for fieldgroup in fieldgroups:
|
141
|
132
|
self.assertIsInstance(fieldgroup, EmFieldGroup)
|
142
|
133
|
|
143
|
|
- # with no fieldgroups fieldgroups() should return an empty list
|
|
134
|
+ # with no fieldgroups, fieldgroups() should return an empty list
|
144
|
135
|
def test_no_fieldgroups(self):
|
145
|
|
- """ Test fielgroups method on an empty EmClass """
|
146
|
|
- test_class = EmClass('testClass')
|
|
136
|
+ """ Test fieldgroups method on an empty EmClass """
|
|
137
|
+ test_class = EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': 'testClassFg3', 'classtype': EmClassType.entity['name']})
|
147
|
138
|
fieldgroups = test_class.fieldgroups()
|
148
|
139
|
self.assertEqual(fieldgroups, [])
|
149
|
140
|
|
150
|
|
-# interface to types
|
|
141
|
+
|
|
142
|
+# Interface to types
|
151
|
143
|
class TestEmClassTypes(ClassesTestCase):
|
152
|
144
|
|
153
|
145
|
@classmethod
|
|
@@ -156,24 +148,23 @@ class TestEmClassTypes(ClassesTestCase):
|
156
|
148
|
|
157
|
149
|
def setUp(self):
|
158
|
150
|
ClassesTestCase.setUpClass()
|
159
|
|
- test_class = EmClass.create('testClass', EmClassType.entity)
|
|
151
|
+ self.test_class = EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': 'testClassType', 'classtype': EmClassType.entity['name']})
|
160
|
152
|
|
161
|
|
- # test if types() return a list of EmType
|
|
153
|
+ # tests if types() returns a list of EmType
|
162
|
154
|
def test_types(self):
|
163
|
|
- """ Test if types method return the right list of EmType """
|
164
|
|
- test_class = EmClass('testClass')
|
165
|
|
- t1 = EmType.create('t1', test_class)
|
166
|
|
- t2 = EmType.create('t2', test_class)
|
167
|
|
-
|
|
155
|
+ """ Tests if types method returns the right list of EmType """
|
|
156
|
+ test_class = EM_TEST_OBJECT.component(self.test_class.uid)
|
|
157
|
+ t1 = EM_TEST_OBJECT.create_component(EmType.__name__, {'name': 'testClassType1', 'class_id': test_class.uid})
|
|
158
|
+ t2 = EM_TEST_OBJECT.create_component(EmType.__name__, {'name': 'testClassType2', 'class_id': test_class.uid})
|
168
|
159
|
types = test_class.types()
|
169
|
160
|
self.assertIsInstance(types, list)
|
170
|
161
|
for t in types:
|
171
|
162
|
self.assertIsInstance(t, EmType)
|
172
|
163
|
|
173
|
|
- # with no type types() should return an empty list
|
|
164
|
+ # with no type, types() should return an empty list
|
174
|
165
|
def test_no_types(self):
|
175
|
166
|
""" Test types method on an EmClass with no associated types """
|
176
|
|
- test_class = EmClass('testClass')
|
|
167
|
+ test_class = EM_TEST_OBJECT.component(self.test_class.uid)
|
177
|
168
|
types = test_class.types()
|
178
|
169
|
self.assertEqual(types, [])
|
179
|
170
|
|
|
@@ -186,16 +177,15 @@ class TestEmClassFields(ClassesTestCase):
|
186
|
177
|
|
187
|
178
|
def setUp(self):
|
188
|
179
|
ClassesTestCase.setUpClass()
|
189
|
|
- test_class = EmClass.create('testClass', EmClassType.entity)
|
|
180
|
+ self.test_class = EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': 'testClassFields', 'classtype': EmClassType.entity['name']})
|
190
|
181
|
|
191
|
|
- # test if fields() return a list of EmField
|
|
182
|
+ # tests if fields() returns a list of EmField
|
192
|
183
|
def test_fields(self):
|
193
|
|
- """ Testing fields method """
|
194
|
|
- test_class = EmClass('testClass')
|
195
|
|
- fg = EmFieldGroup.create('fg', test_class)
|
196
|
|
- f1 = EmField.create('f1', fg, fieldTypes.EmField_char())
|
197
|
|
- f2 = EmField.create('f2', fg, fieldTypes.EmField_char())
|
198
|
|
-
|
|
184
|
+ """ testing fields method """
|
|
185
|
+ test_class = EM_TEST_OBJECT.component(self.test_class.uid)
|
|
186
|
+ fg = EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': 'testClassFieldsFg', 'class_id': test_class.uid})
|
|
187
|
+ f1 = EM_TEST_OBJECT.create_component(EmField.__name__, {'name': 'f1', 'fieldgroup_id': fg.uid, 'fieldtype': 'char'})
|
|
188
|
+ f2 = EM_TEST_OBJECT.create_component(EmField.__name__, {'name': 'f2', 'fieldgroup_id': fg.uid, 'fieldtype': 'char'})
|
199
|
189
|
fields = test_class.fields()
|
200
|
190
|
self.assertIsInstance(fields, list)
|
201
|
191
|
for field in fields:
|
|
@@ -204,11 +194,12 @@ class TestEmClassFields(ClassesTestCase):
|
204
|
194
|
# with no field fields() should return an empty list
|
205
|
195
|
def test_no_fields(self):
|
206
|
196
|
""" Testing fields method on an EmClass with no associated fields """
|
207
|
|
- test_class = EmClass('testClass')
|
|
197
|
+ test_class = EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': 'testClassNoFields', 'classtype': EmClassType.entity['name']})
|
208
|
198
|
fields = test_class.fields()
|
209
|
199
|
self.assertEqual(fields, [])
|
210
|
200
|
|
211
|
|
-# creating an new EmClass should
|
|
201
|
+
|
|
202
|
+# Creating a new EmClass should :
|
212
|
203
|
# - create a table named like the created EmClass
|
213
|
204
|
# - insert a new line in em_classes
|
214
|
205
|
@unittest.skip("Not implemented yet")
|
|
@@ -218,11 +209,13 @@ class TestEmClassLinkType(ClassesTestCase):
|
218
|
209
|
@classmethod
|
219
|
210
|
def setUpClass(cls):
|
220
|
211
|
ClassesTestCase.setUpClass()
|
221
|
|
- testEntity = EmClass.create('testEntity', EmClassType.entity)
|
222
|
|
- testEntry = EmClass.create('testEntry', EmClassType.entry)
|
223
|
|
- keywords = EmType.create('keywords', testEntry)
|
|
212
|
+ testEntity = EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': 'testEntity', 'classtype': EmClassType.entity['name']})
|
|
213
|
+ testEntry = EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': 'testEntry', 'classtype': EmClassType.entry['name']})
|
|
214
|
+ keywords = EM_TEST_OBJECT.create_component(EmType.__name__, {'name': 'keywords', 'class_id': testEntry.uid})
|
224
|
215
|
testEntity.link_type(keywords)
|
225
|
216
|
|
|
217
|
+'''
|
|
218
|
+
|
226
|
219
|
# test if a table 'testEntity_keywords' was created
|
227
|
220
|
# should be able to select on the created table
|
228
|
221
|
def test_table_classes_types(self):
|
|
@@ -245,3 +238,4 @@ class TestEmClassLinkType(ClassesTestCase):
|
245
|
238
|
testEntity = EmClass('testEntity')
|
246
|
239
|
linked_types = testEntity.linked_types()
|
247
|
240
|
self.assertEqual(linked_types[0].name, 'keywords')
|
|
241
|
+'''
|