def test_call_kw(self): """kwargs is not modified by the execution of the call""" partner = self.env['res.partner'].create({'name': 'MyPartner1'}) args = (partner.ids, ['name']) kwargs = {'context': {'test': True}} api.call_kw(self.env['res.partner'], 'read', args, kwargs) self.assertEqual(kwargs, {'context': {'test': True}})
def test_message_post_return(self): test_channel = self.env['mail.channel'].create({ 'name': 'Test', }) # Use call_kw as shortcut to simulate a RPC call. messageId = call_kw(self.env['mail.channel'], 'message_post', [test_channel.id], {'body': 'test'}) self.assertTrue(isinstance(messageId, int))
def test_message_post_return(self): """ Ensures calling message_post through RPC always return an ID. """ test_record = self.env['mail.test.simple'].browse(self.test_record.ids) # Use call_kw as shortcut to simulate a RPC call. message_id = call_kw(self.env['mail.test.simple'], 'message_post', [test_record.id], {'body': 'test'}) self.assertTrue(isinstance(message_id, int))
def json_api(self, model, method, args, kwargs, sudo=None): _logger.info('model %s call %s with %s, %s, %s', model, method, args, kwargs, sudo) odoo_model = request.env[model] if sudo: odoo_model = odoo_model.sudo(sudo) if method not in ['read2', 'search_read2']: return api.call_kw(odoo_model, method, args, kwargs) ret = { 'read2': Model.read, 'search_read2': Model.search_read, 'create2': Model.create }[method](odoo_model, *args, **kwargs) return ret
def json_api(self, model, method,args, kw): return api.call_kw(request.env[model],method,args,kw)
def _call_kw(self, model, method, args, kwargs): check_method_name(method) return call_kw(request.env[model], method, args, kwargs)