1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2026-07-08 00:20:48 +02:00

Added tests + bugfix on LeType __init__ method

This commit is contained in:
Yann 2015-11-26 14:43:05 +01:00
commit 0349007243
3 changed files with 33 additions and 5 deletions

View file

@ -380,5 +380,3 @@ class _LeCrud(object):
def _field_is_relational(field):
return field.startswith('superior.') or field.startswith('subordinate')

View file

@ -11,7 +11,7 @@
# @note LeObject will be generated by leapi.lefactory.LeFactory
import leapi
from leapi.lecrud import _LeCrud
from leapi.lecrud import _LeCrud, LeApiDataCheckError
from leapi.leclass import _LeClass
from leapi.leobject import LeObjectError
@ -35,7 +35,9 @@ class _LeType(_LeClass):
if self._leclass is None:
raise NotImplementedError("Abstract class")
self.lodel_id = lodel_id
self.lodel_id, err = self._uid_fieldtype['lodel_id'].check_data_value(lodel_id)
if isinstance(err, Exception):
raise err
if 'type_id' in kwargs:
if self.__class__._type_id != int(kwargs['type_id']):
@ -45,10 +47,18 @@ class _LeType(_LeClass):
raise RuntimeError("Trying to instanciate a %s with a clas_id that is not correct"%self.__class__.__name__)
## Populate the object from the datas received in kwargs
err_l = list()
for name, value in kwargs.items():
if name not in self._fields:
raise AttributeError("No such field '%s' for %s"%(name, self.__class__.__name__))
setattr(self, name, value)
cvalue, err = self.fieldtypes()[name].check_data_value(value)
if isinstance(err, Exception):
err_l.append(err)
else:
setattr(self, name, value)
if len(err_l) > 0:
raise LeApiDataCheckError("Invalid arguments given to constructor", err_l)
@classmethod
def fieldlist(cls):

View file

@ -182,6 +182,26 @@ class LeCrudTestCase(TestCase):
assert not dsmock.called
pass
@patch('leapi.datasources.dummy.DummyDatasource.update')
def test_update(self, dsmock):
from dyncode import Publication, Numero, LeObject
args_l = [
(
Numero,
{'lodel_id':'1'},
{'titre': 'foobar'},
[('lodel_id', '=', 1)],
[]
),
]
for ccls, initarg, qdatas, efilters, erelfilters in args_l:
obji = ccls(**initarg)
obji.update(qdatas)
dsmock.assert_called_once_with(ccls, efilters, erelfilters, qdatas)
## @todo test invalid get
@patch('leapi.datasources.dummy.DummyDatasource.select')
def test_get(self, dsmock):