| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
import numbers |
| 4 |
import time |
| 5 |
|
| 6 |
import odoorpc |
| 7 |
from odoorpc.tests import LoginTestCase |
| 8 |
|
| 9 |
|
| 10 |
class TestExecuteKw(LoginTestCase): |
| 11 |
|
| 12 |
# ------ |
| 13 |
# Search |
| 14 |
# ------ |
| 15 |
def test_execute_kw_search_with_good_args(self): |
| 16 |
# Check the result returned |
| 17 |
result = self.odoo.execute_kw('res.users', 'search', [[]], {}) |
| 18 |
self.assertIsInstance(result, list) |
| 19 |
self.assertIn(self.user.id, result) |
| 20 |
result = self.odoo.execute_kw( |
| 21 |
'res.users', |
| 22 |
'search', |
| 23 |
[[('id', '=', self.user.id)]], |
| 24 |
{'order': 'name'}, |
| 25 |
) |
| 26 |
self.assertIn(self.user.id, result) |
| 27 |
self.assertEqual(result[0], self.user.id) |
| 28 |
|
| 29 |
def test_execute_kw_search_without_args(self): |
| 30 |
# Handle exception (execute a 'search' without args) |
| 31 |
self.assertRaises( |
| 32 |
odoorpc.error.RPCError, self.odoo.execute_kw, 'res.users', 'search' |
| 33 |
) |
| 34 |
|
| 35 |
def test_execute_kw_search_with_wrong_args(self): |
| 36 |
# Handle exception (execute a 'search' with wrong args) |
| 37 |
self.assertRaises( |
| 38 |
odoorpc.error.RPCError, |
| 39 |
self.odoo.execute_kw, |
| 40 |
'res.users', |
| 41 |
'search', |
| 42 |
False, |
| 43 |
False, |
| 44 |
) # Wrong args |
| 45 |
|
| 46 |
def test_execute_kw_search_with_wrong_model(self): |
| 47 |
# Handle exception (execute a 'search' with a wrong model) |
| 48 |
self.assertRaises( |
| 49 |
odoorpc.error.RPCError, |
| 50 |
self.odoo.execute_kw, |
| 51 |
'wrong.model', # Wrong model |
| 52 |
'search', |
| 53 |
[[]], |
| 54 |
{}, |
| 55 |
) |
| 56 |
|
| 57 |
def test_execute_kw_search_with_wrong_method(self): |
| 58 |
# Handle exception (execute a 'search' with a wrong method) |
| 59 |
self.assertRaises( |
| 60 |
odoorpc.error.RPCError, |
| 61 |
self.odoo.execute_kw, |
| 62 |
'res.users', |
| 63 |
'wrong_method', # Wrong method |
| 64 |
[[]], |
| 65 |
{}, |
| 66 |
) |
| 67 |
|
| 68 |
# ------ |
| 69 |
# Create |
| 70 |
# ------ |
| 71 |
def test_execute_kw_create_with_good_args(self): |
| 72 |
login = "{}_{}".format("foobar", time.time()) |
| 73 |
# Check the result returned |
| 74 |
result = self.odoo.execute_kw( |
| 75 |
'res.users', 'create', [{'name': login, 'login': login}] |
| 76 |
) |
| 77 |
self.assertIsInstance(result, numbers.Number) |
| 78 |
# Handle exception (create another user with the same login) |
| 79 |
self.assertRaises( |
| 80 |
odoorpc.error.RPCError, |
| 81 |
self.odoo.execute_kw, |
| 82 |
'res.users', |
| 83 |
'create', |
| 84 |
[{'name': login, 'login': login}], |
| 85 |
) |
| 86 |
|
| 87 |
def test_execute_kw_create_without_args(self): |
| 88 |
# Handle exception (execute a 'create' without args) |
| 89 |
self.assertRaises( |
| 90 |
odoorpc.error.RPCError, self.odoo.execute_kw, 'res.users', 'create' |
| 91 |
) |
| 92 |
|
| 93 |
def test_execute_kw_create_with_wrong_args(self): |
| 94 |
# Handle exception (execute a 'create' with wrong args) |
| 95 |
self.assertRaises( |
| 96 |
odoorpc.error.RPCError, |
| 97 |
self.odoo.execute_kw, |
| 98 |
'res.users', |
| 99 |
'create', |
| 100 |
True, |
| 101 |
True, |
| 102 |
) # Wrong args |