Debian Codegraph @

odoorpc/tests/test_execute.py

raw
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 TestExecute(LoginTestCase):
11
12 # ------
13 # Search
14 # ------
15 def test_execute_search_with_good_args(self):
16 # Check the result returned
17 result = self.odoo.execute('res.users', 'search', [])
18 self.assertIsInstance(result, list)
19 self.assertIn(self.user.id, result)
20 result = self.odoo.execute(
21 'res.users', 'search', [('id', '=', self.user.id)]
22 )
23 self.assertIn(self.user.id, result)
24 self.assertEqual(result[0], self.user.id)
25
26 def test_execute_search_without_args(self):
27 # Handle exception (execute a 'search' without args)
28 self.assertRaises(
29 odoorpc.error.RPCError, self.odoo.execute, 'res.users', 'search'
30 )
31
32 def test_execute_search_with_wrong_args(self):
33 # Handle exception (execute a 'search' with wrong args)
34 self.assertRaises(
35 odoorpc.error.RPCError,
36 self.odoo.execute,
37 'res.users',
38 'search',
39 False,
40 ) # Wrong arg
41
42 def test_execute_search_with_wrong_model(self):
43 # Handle exception (execute a 'search' with a wrong model)
44 self.assertRaises(
45 odoorpc.error.RPCError,
46 self.odoo.execute,
47 'wrong.model', # Wrong model
48 'search',
49 [],
50 )
51
52 def test_execute_search_with_wrong_method(self):
53 # Handle exception (execute a 'search' with a wrong method)
54 self.assertRaises(
55 odoorpc.error.RPCError,
56 self.odoo.execute,
57 'res.users',
58 'wrong_method', # Wrong method
59 [],
60 )
61
62 # ------
63 # Create
64 # ------
65 def test_execute_create_with_good_args(self):
66 login = "{}_{}".format("foobar", time.time())
67 # Check the result returned
68 result = self.odoo.execute(
69 'res.users', 'create', {'name': login, 'login': login}
70 )
71 self.assertIsInstance(result, numbers.Number)
72 # Handle exception (create another user with the same login)
73 self.assertRaises(
74 odoorpc.error.RPCError,
75 self.odoo.execute,
76 'res.users',
77 'create',
78 {'name': login, 'login': login},
79 )
80
81 def test_execute_create_without_args(self):
82 # Handle exception (execute a 'create' without args)
83 self.assertRaises(
84 odoorpc.error.RPCError, self.odoo.execute, 'res.users', 'create'
85 )
86
87 def test_execute_create_with_wrong_args(self):
88 # Handle exception (execute a 'create' with wrong args)
89 self.assertRaises(
90 odoorpc.error.RPCError,
91 self.odoo.execute,
92 'res.users',
93 'create',
94 False,
95 ) # Wrong arg