Browse Source

Bufix on LeObject.update + test

Yann Weber 8 years ago
parent
commit
4e504f759e
2 changed files with 22 additions and 4 deletions
  1. 4
    4
      lodel/leapi/leobject.py
  2. 18
    0
      tests/leapi/test_leobject.py

+ 4
- 4
lodel/leapi/leobject.py View File

268
     
268
     
269
     ##@brief Read only access to all datas
269
     ##@brief Read only access to all datas
270
     #@return a dict representing datas of current instance
270
     #@return a dict representing datas of current instance
271
-    def datas(self):
272
-        return [self.data(fname) for fname in self.fieldnames(True)]
271
+    def datas(self, internal = False):
272
+        return {fname:self.data(fname) for fname in self.fieldnames(internal)}
273
         
273
         
274
     
274
     
275
     ##@brief Datas setter
275
     ##@brief Datas setter
485
     ## @brief Update an instance of LeObject
485
     ## @brief Update an instance of LeObject
486
     #
486
     #
487
     #@param datas : list of new datas 
487
     #@param datas : list of new datas 
488
-    def update(self, datas):
488
+    def update(self, datas = None):
489
         datas = self.datas(internal=False) if datas is None else datas
489
         datas = self.datas(internal=False) if datas is None else datas
490
         uids = self._uid
490
         uids = self._uid
491
         query_filter = list()
491
         query_filter = list()
493
             query_filter.append((uid, '=', self.data(uid)))
493
             query_filter.append((uid, '=', self.data(uid)))
494
         
494
         
495
         try:
495
         try:
496
-            query = LeUpdateQuery(cls, query_filter)
496
+            query = LeUpdateQuery(self.__class__, query_filter)
497
         except Exception as err:
497
         except Exception as err:
498
             raise err
498
             raise err
499
             
499
             

+ 18
- 0
tests/leapi/test_leobject.py View File

171
             dyncode.Person.delete_bundle(['lodel_id > 1'])
171
             dyncode.Person.delete_bundle(['lodel_id > 1'])
172
             mock_execute.assert_called_once_with()
172
             mock_execute.assert_called_once_with()
173
 
173
 
174
+    def test_update_instance(self):
175
+        """ Checking that LeObject update method calls LeUpdateQuery
176
+            correctly """
177
+        with patch.object(
178
+            LeUpdateQuery, '__init__', return_value = None) as mock_init:
179
+            with patch.object(
180
+                LeObject, 'datas', return_value = {
181
+                    'lodel_id': 1, 'firstname': 'foo', 'lastname': 'bar',
182
+                    'fullname': 'Foo Bar', 'alias': None }) as mock_datas:
183
+            
184
+                inst = dyncode.Person(
185
+                    lodel_id = 1, firstname = "foo", lastname = "bar")
186
+                try:
187
+                   inst.update()
188
+                except AttributeError:
189
+                    pass
190
+                mock_init.assert_called_once_with(
191
+                    dyncode.Person, [('lodel_id', '=', 1)])

Loading…
Cancel
Save