Browse Source

[Tests on EmFieldgroup] Added the creation process tests for this class

Roland Haroutiounian 9 years ago
parent
commit
e4038f4f3a
1 changed files with 37 additions and 39 deletions
  1. 37
    39
      EditorialModel/test/test_fieldgroups.py

+ 37
- 39
EditorialModel/test/test_fieldgroups.py View File

@@ -117,7 +117,6 @@ class TestInit(FieldGroupTestCase):
117 117
                     v = tfg[attr]
118 118
                     self.assertEqual(getattr(fieldgroup, attr), v, "The '"+attr+"' property fetched from backend doesn't match the excepted value")
119 119
 
120
-
121 120
     def test_init_badargs(self):
122 121
         """ Tests that EmFieldGroup init fails when bad arguments are given"""
123 122
         baduid = self.tfgs[2]['uid'] + 4096
@@ -131,63 +130,62 @@ class TestInit(FieldGroupTestCase):
131 130
             fieldgroup = EM_TEST_OBJECT.component(['hello', 'world'])
132 131
 
133 132
 
134
-'''
135 133
 #=====================#
136 134
 # EmFieldgroup.create #
137 135
 #=====================#
138 136
 class TestCreate(FieldGroupTestCase):
139 137
 
140 138
     def test_create(self):
141
-        """ Does create actually create a fieldgroup ? """
142
-
143
-        params = {  'EmClass entity instance': EmClass('entity1'),
144
-                    'EmClass entry instance': EmClass('entry1'),
145
-                    'EmClass person instance': EmClass('person1'),
146
-                }
139
+        """Does create actually create a fieldgroup ?"""
140
+        params = {
141
+            'EmClass entity instance': EM_TEST_OBJECT.component(1),
142
+            'EmClass entry instance': EM_TEST_OBJECT.component(2)
143
+        }
147 144
 
148
-        for i,param_name in enumerate(params):
145
+        for i, param_name in enumerate(params):
149 146
             arg = params[param_name]
150 147
             if isinstance(arg, EmClass):
151 148
                 cl = arg
152 149
             else:
153
-                cl = EmClass(arg)
150
+                cl = EM_TEST_OBJECT.component(arg)
154 151
 
155
-            fgname = 'new_fg'+str(i)
156
-            fg = EmFieldGroup.create(fgname, arg)
157
-            self.assertEqual(fg.name, fgname, "EmFieldGroup.create() dont instanciate name correctly")
158
-            self.assertEqual(fg.class_id, cl.uid, "EmFieldGroup.create() dont instanciate class_id correctly")
152
+            fieldgroup_name = 'new_fg'+str(i)
153
+            fieldgroup = EM_TEST_OBJECT.create_component(EmFieldGroup.__name__,{'name': fieldgroup_name, 'class_id': arg.uid})
154
+            self.assertEqual(fieldgroup.name, fieldgroup_name, "Model.create_component() doesn't instanciate name correctly")
155
+            self.assertEqual(fieldgroup.class_id, cl.uid, "Model.create_component() doesn't instanciate class_id correctly")
159 156
 
160
-            nfg = EmFieldGroup(fgname)
157
+            nfg = EM_TEST_OBJECT.component(fieldgroup.uid)
161 158
 
162
-            #Checking object property
163
-            for fname in fg._fields:
164
-                self.assertEqual(getattr(nfg,fname), getattr(fg,fname), "Msg inconsistency when a created fieldgroup is fecthed from Db (in "+fname+" property)")
165
-        pass
159
+            # Checking object property
160
+            for fname in fieldgroup.__dict__:
161
+                self.assertEqual(getattr(nfg, fname), getattr(fieldgroup, fname), "Msg inconsistency when a created fieldgroup is fetched from the backend (in " + fname + " property)")
166 162
 
167 163
     def test_create_badargs(self):
168 164
         """ Does create fails when badargs given ? """
165
+        badargs = {
166
+            'EmClass type (not an instance)': EmClass,
167
+            'Non Existing id': 9000,
168
+            'Another component instance': EM_TEST_OBJECT.create_component(EmType.__name__,{'name': 'fooType', 'class_id': EM_TEST_OBJECT.component(1).uid}),
169
+            'A function': print
170
+        }
171
+
172
+        for i, badarg_name in enumerate(badargs):
173
+            with self.assertRaises(TypeError, msg="Should raise because trying to give " + badarg_name + " an em_class object as value"):
174
+                fieldgroup = EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': 'new_fg' + i, 'class_id': badargs[badarg_name].uid})
169 175
 
170
-        badargs = { 'EmClass type (not an instance)': EmClass,
171
-                    'Non Existing name': 'fooClassThatDontExist',
172
-                    'Non Existing Id': 4042, #Hope that it didnt exist ;)
173
-                    'Another component instance': EmType.create('fooType', EmClass('entity1')),
174
-                    'A function': print
175
-                }
176
-        for i,badarg_name in enumerate(badargs):
177
-            with self.assertRaises(TypeError, msg="Should raise because trying to give "+badarg_name+" as em_class"):
178
-                fg = EmFieldGroup.create('new_fg'+i, badargs[badarg_name])
179
-
180
-        #Creating a fieldgroup to test duplicate name
181
-        exfg = EmFieldGroup.create('existingfg', EmClass('entity1'))
182
-
183
-        badargs = { 'an integer': (42, TypeError),
184
-                    'a function': (print, TypeError),
185
-                    'an EmClass': (EmClass('entry1'), TypeError),
186
-                }
176
+        # Creating a fieldgroup to test duplicate name
177
+        exfg = EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': 'existingfg', 'class_id': EM_TEST_OBJECT.component(1).uid})
178
+        badargs = {
179
+            'an integer': (42, AttributeError),
180
+            'a function': (print, AttributeError),
181
+            'an EmClass': (EM_TEST_OBJECT.component(2), AttributeError)
182
+        }
187 183
         for badarg_name in badargs:
188
-            (badarg,expt) = badargs[badarg_name]
189
-            with self.assertRaises(expt, msg="Should raise because trying to give "+badarg_name+" as first argument"):
190
-                fg = EmFieldGroup.create(badarg, EmClass('entity1'))
184
+            (badarg, expt) = badargs[badarg_name]
185
+            with self.assertRaises(expt, msg="Should raise because trying to give " + badarg_name + " as first argument"):
186
+                fieldgroup = EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': badarg, 'class_id': EM_TEST_OBJECT.component(1).uid})
187
+
188
+'''
191 189
 
192 190
 #=====================#
193 191
 # EmFieldgroup.fields #

Loading…
Cancel
Save