浏览代码

Bugfixes is some tests

Yann Weber 10 年前
父节点
当前提交
94e8474185
共有 1 个文件被更改,包括 30 次插入15 次删除
  1. 30
    15
      EditorialModel/test/test_fieldgroups.py

+ 30
- 15
EditorialModel/test/test_fieldgroups.py 查看文件

@@ -10,7 +10,10 @@ import unittest
10 10
 from EditorialModel.components import EmComponent, EmComponentNotExistError
11 11
 from EditorialModel.fieldgroups import EmFieldGroup
12 12
 from EditorialModel.classes import EmClass
13
+from EditorialModel.types import EmType
14
+from EditorialModel.fields import EmField
13 15
 from EditorialModel.classtypes import EmClassType
16
+from EditorialModel.fieldtypes import *
14 17
 
15 18
 from Database.sqlsetup import SQLSetup
16 19
 from Database import sqlutils
@@ -82,14 +85,22 @@ class TestInit(FieldGroupTestCase):
82 85
         with self.subTest("Call __init__ with name"):
83 86
             for tfg in self.tfg:
84 87
                 fg = EmFieldGroup(tfg['name'])
85
-                if attr in tfg:
86
-                    self.assertEqual(getattr(fg, attr), tfg[attr], "The propertie '"+attr+"' fetched from Db don't match excepted value")
88
+                for attr in tfg:
89
+                    if attr in ['string', 'help']:
90
+                        v = MlString.load(tfg[attr])
91
+                    else:
92
+                        v = tfg[attr]
93
+                    self.assertEqual(getattr(fg, attr), v, "The propertie '"+attr+"' fetched from Db don't match excepted value")
87 94
 
88 95
         with self.subTest("Call __init__ with id"):
89 96
             for tfg in self.tfg:
90 97
                 fg = EmFieldGroup(tfg['uid'])
91
-                if attr in tfg:
92
-                    self.assertEqual(getattr(fg, attr), tfg[attr], "The propertie '"+attr+"' fetched from Db don't match excepted value")
98
+                for attr in tfg:
99
+                    if attr in ['string', 'help']:
100
+                        v = MlString.load(tfg[attr])
101
+                    else:
102
+                        v = tfg[attr]
103
+                    self.assertEqual(getattr(fg, attr), v, "The propertie '"+attr+"' fetched from Db don't match excepted value")
93 104
 
94 105
         pass
95 106
 
@@ -131,7 +142,7 @@ class TestCreate(FieldGroupTestCase):
131 142
                 else:
132 143
                     cl = EmClass(arg)
133 144
 
134
-                fgname = 'new_fg'+i
145
+                fgname = 'new_fg'+str(i)
135 146
                 fg = EmFieldGroup.create(fgname, arg)
136 147
                 self.assertEqual(fg.name, fgname, "EmFieldGroup.create() dont instanciate name correctly")
137 148
                 self.assertEqual(fg.class_id, cl.uid, "EmFieldGroup.create() dont instanciate class_id correctly")
@@ -139,8 +150,8 @@ class TestCreate(FieldGroupTestCase):
139 150
                 nfg = EmFieldGroup(fgname)
140 151
 
141 152
                 #Checking object property
142
-                for fname in EmFieldGroup._fields:
143
-                    self.assertEqual(nfg.fname, fg.fname, "Msg inconsistency when a created fieldgroup is fecthed from Db (in "+fname+" property)")
153
+                for fname in fg._fields:
154
+                    self.assertEqual(getattr(nfg,fname), getattr(fg,fname), "Msg inconsistency when a created fieldgroup is fecthed from Db (in "+fname+" property)")
144 155
         pass
145 156
 
146 157
     def test_create_badargs(self):
@@ -155,21 +166,25 @@ class TestCreate(FieldGroupTestCase):
155 166
                     }
156 167
             for i,badarg_name in enumerate(badargs):
157 168
                 with self.assertRaises(TypeError, msg="Should raise because trying to give "+badarg_name+" as em_class"):
158
-                    fg = EmFieldGroup('new_fg'+i, badargs[badarg_name])
169
+                    fg = EmFieldGroup.create('new_fg'+i, badargs[badarg_name])
159 170
 
160 171
         with self.subTest("With badarg as first argument"):
161 172
             #Creating a fieldgroup to test duplicate name
162
-            exfg = FieldGroup.create('existingfg', EmClass('entity1'))
173
+            exfg = EmFieldGroup.create('existingfg', EmClass('entity1'))
163 174
 
164
-            badargs = { 'a duplicate name': 'existingfg',
165
-                        'an integer': 42,
166
-                        'a function': print,
167
-                        'an EmClass': EmClass('entry1'),
175
+            badargs = { 'a duplicate name': ('existingfg', ValueError),
176
+                        'an integer': (42, TypeError),
177
+                        'a function': (print, TypeError),
178
+                        'an EmClass': (EmClass('entry1'), TypeError),
168 179
                     }
169 180
             for badarg_name in badargs:
170
-                with self.assertRaises(TypeError, msg="Should raise because trying to give "+badarg_name+" as first argument"):
171
-                    fg = EmFieldGroup(badargs[badarg_name])
181
+                (badarg,expt) = badargs[badarg_name]
182
+                with self.assertRaises(expt, msg="Should raise because trying to give "+badarg_name+" as first argument"):
183
+                    fg = EmFieldGroup.create(badarg, EmClass('entity1'))
172 184
 
185
+#=====================#
186
+# EmFieldgroup.fields #
187
+#=====================#
173 188
 class TestFields(FieldGroupTestCase):
174 189
     
175 190
     def setUp(self):

正在加载...
取消
保存