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,8 +268,8 @@ raised when trying to import Datasource"
268 268
     
269 269
     ##@brief Read only access to all datas
270 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 275
     ##@brief Datas setter
@@ -485,7 +485,7 @@ raised when trying to import Datasource"
485 485
     ## @brief Update an instance of LeObject
486 486
     #
487 487
     #@param datas : list of new datas 
488
-    def update(self, datas):
488
+    def update(self, datas = None):
489 489
         datas = self.datas(internal=False) if datas is None else datas
490 490
         uids = self._uid
491 491
         query_filter = list()
@@ -493,7 +493,7 @@ raised when trying to import Datasource"
493 493
             query_filter.append((uid, '=', self.data(uid)))
494 494
         
495 495
         try:
496
-            query = LeUpdateQuery(cls, query_filter)
496
+            query = LeUpdateQuery(self.__class__, query_filter)
497 497
         except Exception as err:
498 498
             raise err
499 499
             

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

@@ -171,3 +171,21 @@ class LeObjectQueryMockTestCase(unittest.TestCase):
171 171
             dyncode.Person.delete_bundle(['lodel_id > 1'])
172 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