|
@@ -3,6 +3,7 @@
|
3
|
3
|
"""
|
4
|
4
|
|
5
|
5
|
import os
|
|
6
|
+import logging
|
6
|
7
|
|
7
|
8
|
from unittest import TestCase
|
8
|
9
|
import unittest
|
|
@@ -15,24 +16,32 @@ from EditorialModel.fieldgroups import EmFieldGroup
|
15
|
16
|
from EditorialModel.types import EmType
|
16
|
17
|
from EditorialModel.fields import EmField
|
17
|
18
|
import EditorialModel.fieldtypes as fieldTypes
|
|
19
|
+from EditorialModel.model import Model
|
|
20
|
+from EditorialModel.backend.json_backend import EmBackendJson
|
18
|
21
|
|
19
|
|
-from Database import sqlutils, sqlsetup
|
20
|
|
-import sqlalchemy as sqla
|
|
22
|
+#from Database import sqlutils, sqlsetup
|
|
23
|
+#import sqlalchemy as sqla
|
21
|
24
|
|
22
|
25
|
|
23
|
26
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Lodel.settings")
|
|
27
|
+EM_TEST = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'me.json')
|
|
28
|
+EM_TEST_OBJECT = None
|
24
|
29
|
|
25
|
30
|
## run once for this module
|
26
|
31
|
# define the Database for this module (an sqlite database)
|
27
|
32
|
def setUpModule():
|
28
|
|
- settings.LODEL2SQLWRAPPER['db']['default'] = {'ENGINE':'sqlite', 'NAME':'/tmp/testdb.sqlite'}
|
|
33
|
+ global EM_TEST_OBJECT
|
|
34
|
+ EM_TEST_OBJECT = Model(EmBackendJson(EM_TEST))
|
|
35
|
+ logging.basicConfig(level=logging.CRITICAL)
|
|
36
|
+ #settings.LODEL2SQLWRAPPER['db']['default'] = {'ENGINE':'sqlite', 'NAME':'/tmp/testdb.sqlite'}
|
29
|
37
|
|
30
|
38
|
class ClassesTestCase(TestCase):
|
31
|
39
|
|
32
|
40
|
# run before every instanciation of the class
|
33
|
41
|
@classmethod
|
34
|
42
|
def setUpClass(cls):
|
35
|
|
- sqlsetup.init_db()
|
|
43
|
+ pass
|
|
44
|
+ #sqlsetup.init_db()
|
36
|
45
|
|
37
|
46
|
# run before every function of the class
|
38
|
47
|
def setUp(self):
|
|
@@ -45,44 +54,25 @@ class ClassesTestCase(TestCase):
|
45
|
54
|
class TestEmClassCreation(ClassesTestCase):
|
46
|
55
|
|
47
|
56
|
# create a new EmClass, then test on it
|
48
|
|
- @classmethod
|
49
|
|
- def setUpClass(cls):
|
|
57
|
+ def test_create(self):
|
50
|
58
|
ClassesTestCase.setUpClass()
|
51
|
|
- EmClass.create('testClass', EmClassType.entity)
|
|
59
|
+ testClass = EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': 'testclass1', 'classtype': EmClassType.entity['name']})
|
52
|
60
|
|
53
|
|
- # test if a table 'testClass' was created
|
54
|
|
- # should be able to select on the created table
|
55
|
|
- def test_table_em_classes(self):
|
56
|
|
- """ Testing ability of EmClass to crate its associated table """
|
57
|
|
- conn = sqlutils.get_engine().connect()
|
58
|
|
- a = sqlutils.meta(conn)
|
59
|
|
- try:
|
60
|
|
- newtable = sqla.Table('testClass', sqlutils.meta(conn))
|
61
|
|
- req = sqla.sql.select([newtable])
|
62
|
|
- res = conn.execute(req)
|
63
|
|
- res = res.fetchall()
|
64
|
|
- conn.close()
|
65
|
|
- except:
|
66
|
|
- self.fail("unable to select table testClass")
|
67
|
|
- self.assertEqual(res, [])
|
|
61
|
+ #We check the uid
|
|
62
|
+ self.assertEqual(testClass.uid, 18)
|
|
63
|
+
|
|
64
|
+ # We check that the class has been added in the right list in the model object
|
|
65
|
+ class_components_records = EM_TEST_OBJECT.components(EmClass)
|
|
66
|
+ self.assertIn(testClass, class_components_records)
|
|
67
|
+
|
|
68
|
+ # the name should be the one given
|
|
69
|
+ testClass = EM_TEST_OBJECT.component(testClass.uid)
|
|
70
|
+ self.assertEqual(testClass.name, 'testclass1')
|
|
71
|
+
|
|
72
|
+ # the classtype should have the name of the EmClassType
|
|
73
|
+ testClass = EM_TEST_OBJECT.component(testClass.uid)
|
|
74
|
+ self.assertEqual(testClass.classtype, EmClassType.entity['name'])
|
68
|
75
|
|
69
|
|
- # the uid should be 1
|
70
|
|
- def test_uid(self):
|
71
|
|
- """ testing uid """
|
72
|
|
- cl = EmClass('testClass')
|
73
|
|
- self.assertEqual(cl.uid, 1)
|
74
|
|
-
|
75
|
|
- # the name should be the one given
|
76
|
|
- def test_classname(self):
|
77
|
|
- """ Testing name consistency on instanciation """
|
78
|
|
- cl = EmClass('testClass')
|
79
|
|
- self.assertEqual(cl.name, 'testClass')
|
80
|
|
-
|
81
|
|
- # the classtype should have the name of the EmClassType
|
82
|
|
- def test_classtype(self):
|
83
|
|
- """ Testing classtype consistency """
|
84
|
|
- cl = EmClass('testClass')
|
85
|
|
- self.assertEqual(cl.classtype, EmClassType.entity['name'])
|
86
|
76
|
|
87
|
77
|
# Testing class deletion (and associated table drop)
|
88
|
78
|
class TestEmClassDeletion(ClassesTestCase):
|