Browse Source

[#54] Code cleaning

Roland Haroutiounian 9 years ago
parent
commit
ebf07e197f
1 changed files with 26 additions and 28 deletions
  1. 26
    28
      EditorialModel/test/test_classes.py

+ 26
- 28
EditorialModel/test/test_classes.py View File

@@ -8,19 +8,16 @@ import logging
8 8
 from unittest import TestCase
9 9
 import unittest
10 10
 
11
-from django.conf import settings
12 11
 from EditorialModel.classes import EmClass
13 12
 from EditorialModel.classtypes import EmClassType
14 13
 from EditorialModel.fieldgroups import EmFieldGroup
15 14
 from EditorialModel.types import EmType
16 15
 from EditorialModel.fields import EmField
17
-import EditorialModel.fieldtypes  as fieldTypes
16
+#import EditorialModel.fieldtypes as fieldTypes
18 17
 from EditorialModel.model import Model
19 18
 from EditorialModel.backend.json_backend import EmBackendJson
20
-from EditorialModel.migrationhandler.django import DjangoMigrationHandler
21
-#from Database import sqlutils, sqlsetup
22
-#import sqlalchemy as sqla
23
-
19
+#from EditorialModel.migrationhandler.django import DjangoMigrationHandler
20
+from EditorialModel.migrationhandler.dummy import DummyMigrationHandler
24 21
 
25 22
 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Lodel.settings")
26 23
 EM_TEST = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'me.json')
@@ -30,7 +27,8 @@ EM_TEST_OBJECT = None
30 27
 # define the Database for this module (an sqlite database)
31 28
 def setUpModule():
32 29
     global EM_TEST_OBJECT
33
-    EM_TEST_OBJECT = Model(EmBackendJson(EM_TEST), migration_handler=DjangoMigrationHandler('LodelTestInstance'))
30
+    #EM_TEST_OBJECT = Model(EmBackendJson(EM_TEST), migration_handler=DjandoMigrationHandler('LodelTestInstance'))
31
+    EM_TEST_OBJECT = Model(EmBackendJson(EM_TEST), migration_handler=DummyMigrationHandler())
34 32
     logging.basicConfig(level=logging.CRITICAL)
35 33
 
36 34
 class ClassesTestCase(TestCase):
@@ -54,22 +52,22 @@ class TestEmClassCreation(ClassesTestCase):
54 52
     # create a new EmClass, then test on it
55 53
     def test_create(self):
56 54
         ClassesTestCase.setUpClass()
57
-        testClass = EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': 'testclass1', 'classtype': EmClassType.entity['name']})
55
+        test_class = EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': 'testclass1', 'classtype': EmClassType.entity['name']})
58 56
 
59 57
         #We check the uid
60
-        self.assertEqual(testClass.uid, 22)
58
+        self.assertEqual(test_class.uid, 22)
61 59
 
62 60
         # We check that the class has been added in the right list in the model object
63 61
         class_components_records = EM_TEST_OBJECT.components(EmClass)
64
-        self.assertIn(testClass, class_components_records)
62
+        self.assertIn(test_class, class_components_records)
65 63
 
66 64
         # the name should be the one given
67
-        testClass = EM_TEST_OBJECT.component(testClass.uid)
68
-        self.assertEqual(testClass.name, 'testclass1')
65
+        test_class = EM_TEST_OBJECT.component(test_class.uid)
66
+        self.assertEqual(test_class.name, 'testclass1')
69 67
 
70 68
         # the classtype should have the name of the EmClassType
71
-        testClass = EM_TEST_OBJECT.component(testClass.uid)
72
-        self.assertEqual(testClass.classtype, EmClassType.entity['name'])
69
+        test_class = EM_TEST_OBJECT.component(test_class.uid)
70
+        self.assertEqual(test_class.classtype, EmClassType.entity['name'])
73 71
 
74 72
 
75 73
 # Testing class deletion (and associated table drop)
@@ -85,7 +83,7 @@ class TestEmClassDeletion(ClassesTestCase):
85 83
     # tests if the table is deleted after a call to delete
86 84
     def test_table_delete(self):
87 85
         """ Test associated table deletion on EmClass deletion """
88
-        for i, class_object in enumerate(self.emclasses):
86
+        for _, class_object in enumerate(self.emclasses):
89 87
             self.assertTrue(EM_TEST_OBJECT.delete_component(class_object.uid), "delete method didn't return True but the class has no fieldgroups")
90 88
 
91 89
         # TODO check : "table still exists but the class was deleted"
@@ -95,7 +93,7 @@ class TestEmClassDeletion(ClassesTestCase):
95 93
     # tests if delete refuse to delete if a class had fieldgroups
96 94
     def test_table_refuse_delete(self):
97 95
         """ Test delete on an EmClass that has fieldgroup """
98
-        test_class = EM_TEST_OBJECT.create_component(EmClass.__name__,{'name': 'testfgclass1', 'classtype': EmClassType.entity['name']})
96
+        test_class = EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': 'testfgclass1', 'classtype': EmClassType.entity['name']})
99 97
         fieldgroup = EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': 'testsubfg1', 'class_id': test_class.uid})
100 98
         self.assertFalse(EM_TEST_OBJECT.delete_component(test_class.uid), "delete method returns True but the class has fieldgroup(s)")
101 99
 
@@ -122,8 +120,8 @@ class TestEmClassFieldgrousp(ClassesTestCase):
122 120
     def test_fieldgroups(self):
123 121
         """ Tests if fieldgroups method returns the right list of EmFieldGroup """
124 122
         test_class = EM_TEST_OBJECT.component(self.test_class.uid)
125
-        fg1 = EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': 'testClassFg1', 'class_id': test_class.uid})
126
-        fg2 = EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': 'testClassFg2', 'class_id': test_class.uid})
123
+        EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': 'testClassFg1', 'class_id': test_class.uid})
124
+        EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': 'testClassFg2', 'class_id': test_class.uid})
127 125
 
128 126
         fieldgroups = test_class.fieldgroups()
129 127
         self.assertIsInstance(fieldgroups, list)
@@ -153,8 +151,8 @@ class TestEmClassTypes(ClassesTestCase):
153 151
     def test_types(self):
154 152
         """ Tests if types method returns the right list of EmType """
155 153
         test_class = EM_TEST_OBJECT.component(self.test_class.uid)
156
-        t1 = EM_TEST_OBJECT.create_component(EmType.__name__, {'name': 'testClassType1', 'class_id': test_class.uid})
157
-        t2 = EM_TEST_OBJECT.create_component(EmType.__name__, {'name': 'testClassType2', 'class_id': test_class.uid})
154
+        EM_TEST_OBJECT.create_component(EmType.__name__, {'name': 'testClassType1', 'class_id': test_class.uid})
155
+        EM_TEST_OBJECT.create_component(EmType.__name__, {'name': 'testClassType2', 'class_id': test_class.uid})
158 156
         types = test_class.types()
159 157
         self.assertIsInstance(types, list)
160 158
         for t in types:
@@ -183,8 +181,8 @@ class TestEmClassFields(ClassesTestCase):
183 181
         """ testing fields method """
184 182
         test_class = EM_TEST_OBJECT.component(self.test_class.uid)
185 183
         fg = EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': 'testClassFieldsFg', 'class_id': test_class.uid})
186
-        f1 = EM_TEST_OBJECT.create_component(EmField.__name__, {'name': 'f1', 'fieldgroup_id': fg.uid, 'fieldtype': 'char'})
187
-        f2 = EM_TEST_OBJECT.create_component(EmField.__name__, {'name': 'f2', 'fieldgroup_id': fg.uid, 'fieldtype': 'char'})
184
+        EM_TEST_OBJECT.create_component(EmField.__name__, {'name': 'f1', 'fieldgroup_id': fg.uid, 'fieldtype': 'char'})
185
+        EM_TEST_OBJECT.create_component(EmField.__name__, {'name': 'f2', 'fieldgroup_id': fg.uid, 'fieldtype': 'char'})
188 186
         fields = test_class.fields()
189 187
         self.assertIsInstance(fields, list)
190 188
         for field in fields:
@@ -208,12 +206,12 @@ class TestEmClassLinkType(ClassesTestCase):
208 206
     @classmethod
209 207
     def setUpClass(cls):
210 208
         ClassesTestCase.setUpClass()
211
-        testEntity = EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': 'testEntity', 'classtype': EmClassType.entity['name']})
212
-        testEntry = EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': 'testEntry', 'classtype': EmClassType.entry['name']})
213
-        keywords = EM_TEST_OBJECT.create_component(EmType.__name__, {'name': 'keywords', 'class_id': testEntry.uid})
214
-        testEntity.link_type(keywords)
209
+        test_entity = EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': 'testEntity', 'classtype': EmClassType.entity['name']})
210
+        test_entry = EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': 'testEntry', 'classtype': EmClassType.entry['name']})
211
+        keywords = EM_TEST_OBJECT.create_component(EmType.__name__, {'name': 'keywords', 'class_id': test_entry.uid})
212
+        test_entity.link_type(keywords)
215 213
 
216
-'''
214
+    '''
217 215
 
218 216
     # test if a table 'testEntity_keywords' was created
219 217
     # should be able to select on the created table
@@ -237,4 +235,4 @@ class TestEmClassLinkType(ClassesTestCase):
237 235
         testEntity = EmClass('testEntity')
238 236
         linked_types = testEntity.linked_types()
239 237
         self.assertEqual(linked_types[0].name, 'keywords')
240
-'''
238
+    '''

Loading…
Cancel
Save