ソースを参照

Réimplémentation du test TestEmClassCreation

Driky 9年前
コミット
ac6f791508
1個のファイルの変更29行の追加39行の削除
  1. 29
    39
      EditorialModel/test/test_classes.py

+ 29
- 39
EditorialModel/test/test_classes.py ファイルの表示

3
 """
3
 """
4
 
4
 
5
 import os
5
 import os
6
+import logging
6
 
7
 
7
 from unittest import TestCase
8
 from unittest import TestCase
8
 import unittest
9
 import unittest
15
 from EditorialModel.types import EmType
16
 from EditorialModel.types import EmType
16
 from EditorialModel.fields import EmField
17
 from EditorialModel.fields import EmField
17
 import EditorialModel.fieldtypes  as fieldTypes
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
 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Lodel.settings")
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
 ## run once for this module
30
 ## run once for this module
26
 # define the Database for this module (an sqlite database)
31
 # define the Database for this module (an sqlite database)
27
 def setUpModule():
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
 class ClassesTestCase(TestCase):
38
 class ClassesTestCase(TestCase):
31
 
39
 
32
     # run before every instanciation of the class
40
     # run before every instanciation of the class
33
     @classmethod
41
     @classmethod
34
     def setUpClass(cls):
42
     def setUpClass(cls):
35
-        sqlsetup.init_db()
43
+        pass
44
+        #sqlsetup.init_db()
36
 
45
 
37
     # run before every function of the class
46
     # run before every function of the class
38
     def setUp(self):
47
     def setUp(self):
45
 class TestEmClassCreation(ClassesTestCase):
54
 class TestEmClassCreation(ClassesTestCase):
46
 
55
 
47
     # create a new EmClass, then test on it
56
     # create a new EmClass, then test on it
48
-    @classmethod
49
-    def setUpClass(cls):
57
+    def test_create(self):
50
         ClassesTestCase.setUpClass()
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
 # Testing class deletion (and associated table drop)
77
 # Testing class deletion (and associated table drop)
88
 class TestEmClassDeletion(ClassesTestCase):
78
 class TestEmClassDeletion(ClassesTestCase):

読み込み中…
キャンセル
保存