|
@@ -5,8 +5,10 @@
|
5
|
5
|
import os
|
6
|
6
|
|
7
|
7
|
from unittest import TestCase
|
|
8
|
+import unittest
|
8
|
9
|
|
9
|
10
|
from django.conf import settings
|
|
11
|
+from EditorialModel.components import EmComponentNotExistError
|
10
|
12
|
from EditorialModel.classes import EmClass
|
11
|
13
|
from EditorialModel.classtypes import EmClassType
|
12
|
14
|
from EditorialModel.fieldgroups import EmFieldGroup
|
|
@@ -80,6 +82,47 @@ class TestEmClassCreation(ClassesTestCase):
|
80
|
82
|
cl = EmClass('testClass')
|
81
|
83
|
self.assertEqual(cl.classtype, EmClassType.entity['name'])
|
82
|
84
|
|
|
85
|
+# Testing class deletion (and associated table drop)
|
|
86
|
+class TestEmClassDeletion(ClassesTestCase):
|
|
87
|
+
|
|
88
|
+ def setUp(self):
|
|
89
|
+ self.names = ['testClass1', 'testClass2', 'testClass3']
|
|
90
|
+ EmClass.create(self.names[0], EmClassType.entity)
|
|
91
|
+ EmClass.create(self.names[1], EmClassType.entry)
|
|
92
|
+ EmClass.create(self.names[2], EmClassType.person)
|
|
93
|
+ pass
|
|
94
|
+
|
|
95
|
+ # test if the table is deleted after a call to delete
|
|
96
|
+ def test_table_delete(self):
|
|
97
|
+ dbe = sqlutils.getEngine()
|
|
98
|
+ for i,class_name in enumerate(self.names):
|
|
99
|
+ cur_class = EmClass(class_name)
|
|
100
|
+ self.assertTrue(cur_class.delete(), "delete method didn't return True but the class has no fieldgroups")
|
|
101
|
+ meta = sqlutils.meta(dbe)
|
|
102
|
+ table_list = meta.tables.keys()
|
|
103
|
+ for deleted_name in self.names[:i+1]:
|
|
104
|
+ self.assertNotIn(deleted_name, table_list, "Table still exist but the class was deleted")
|
|
105
|
+ for not_deleted_name in self.names[i+1:]:
|
|
106
|
+ self.assertIn(not_deleted_name, table_list, "Table don't exist but the class was NOT deleted")
|
|
107
|
+ with self.assertRaises(EmComponentNotExistError,msg="This EmClass should be deleted"):
|
|
108
|
+ EmClass(class_name)
|
|
109
|
+ pass
|
|
110
|
+
|
|
111
|
+ # test if delete refuse to delete if a class had fieldgroups
|
|
112
|
+ def test_table_refuse_delete(self):
|
|
113
|
+ test_class = EmClass(self.names[0])
|
|
114
|
+ fieldgroup = EmFieldGroup.create('fooFieldGroup', test_class)
|
|
115
|
+ self.assertFalse(test_class.delete(), "delete method returns True but the class has fieldgroup")
|
|
116
|
+ dbe = sqlutils.getEngine()
|
|
117
|
+ meta = sqlutils.meta(dbe)
|
|
118
|
+ self.assertIn(self.names[0], meta.tables, "Table has been deleted but the class has fieldgroup")
|
|
119
|
+ try:
|
|
120
|
+ EmClass(self.names[0])
|
|
121
|
+ except EmComponentNotExistError:
|
|
122
|
+ self.fail("The class has been deleted but it has fieldgroups")
|
|
123
|
+ pass
|
|
124
|
+
|
|
125
|
+
|
83
|
126
|
# interface to fieldGroups
|
84
|
127
|
class TestEmClassFieldgroups(ClassesTestCase):
|
85
|
128
|
|
|
@@ -168,6 +211,7 @@ class TestEmClassFields(ClassesTestCase):
|
168
|
211
|
# creating an new EmClass should
|
169
|
212
|
# - create a table named like the created EmClass
|
170
|
213
|
# - insert a new line in em_classes
|
|
214
|
+@unittest.skip("Not implemented yet")
|
171
|
215
|
class TestEmClassLinkType(ClassesTestCase):
|
172
|
216
|
|
173
|
217
|
# create a new EmClass, then test on it
|