[IMP] raise assertion error if an o2m command is not one of CREATE, UPDATE or LINK_TO
bzr revid: xmo@openerp.com-20111011083824-4g0ros6f3xgslkq4
This commit is contained in:
parent
4d0a189796
commit
8734ffb6c2
|
@ -4796,6 +4796,9 @@ class BaseModel(object):
|
|||
else:
|
||||
commands.append(o2m_command)
|
||||
|
||||
assert not any(command for command, _, _ in commands if command not in (0, 1, 4)),\
|
||||
"Only CREATE, UPDATE and LINK_TO commands are supported in resolver"
|
||||
|
||||
# extract records to read, by id, in a mapping dict
|
||||
ids_to_read = [id for (command, id, _) in commands if command in (1, 4)]
|
||||
records_by_id = dict(
|
||||
|
|
|
@ -7,8 +7,11 @@ DB = os.environ['OPENERP_DATABASE']
|
|||
|
||||
CREATE = lambda values: (0, False, values)
|
||||
UPDATE = lambda id, values: (1, id, values)
|
||||
DELETE = lambda id: (2, id, False)
|
||||
FORGET = lambda id: (3, id, False)
|
||||
LINK_TO = lambda id: (4, id, False)
|
||||
|
||||
DELETE_ALL = lambda: (5, False, False)
|
||||
REPLACE_WITH = lambda ids: (6, False, ids)
|
||||
|
||||
def setUpModule():
|
||||
openerp.tools.config['addons_path'] = os.environ['OPENERP_ADDONS_PATH']
|
||||
|
@ -137,3 +140,22 @@ class TestO2MSerialization(unittest2.TestCase):
|
|||
{'id': ids[1], 'name': 'bar'},
|
||||
{'id': ids[2], 'name': 'baz'}
|
||||
])
|
||||
|
||||
def test_invalid_commands(self):
|
||||
"Commands with uncertain semantics in this context should be forbidden"
|
||||
|
||||
with self.assertRaises(AssertionError):
|
||||
list(self.partner.resolve_o2m_commands_to_record_dicts(
|
||||
self.cr, UID, 'address', [DELETE(42)], ['name']))
|
||||
|
||||
with self.assertRaises(AssertionError):
|
||||
list(self.partner.resolve_o2m_commands_to_record_dicts(
|
||||
self.cr, UID, 'address', [FORGET(42)], ['name']))
|
||||
|
||||
with self.assertRaises(AssertionError):
|
||||
list(self.partner.resolve_o2m_commands_to_record_dicts(
|
||||
self.cr, UID, 'address', [DELETE_ALL()], ['name']))
|
||||
|
||||
with self.assertRaises(AssertionError):
|
||||
list(self.partner.resolve_o2m_commands_to_record_dicts(
|
||||
self.cr, UID, 'address', [REPLACE_WITH([42])], ['name']))
|
||||
|
|
Loading…
Reference in New Issue