-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathtest_execute.py
106 lines (91 loc) · 3.19 KB
/
test_execute.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# -*- coding: UTF-8 -*-
try:
import unittest2 as unittest
except:
import unittest
import numbers
import time
from args import ARGS
import oerplib
class TestExecute(unittest.TestCase):
def setUp(self):
self.oerp = oerplib.OERP(
ARGS.server, protocol=ARGS.protocol, port=ARGS.port,
version=ARGS.version)
self.user = self.oerp.login(ARGS.user, ARGS.passwd, ARGS.database)
# ------
# Search
# ------
def test_execute_search_with_good_args(self):
# Check the result returned
result = self.oerp.execute('res.users', 'search', [])
self.assertIsInstance(result, list)
self.assertIn(self.user.id, result)
result = self.oerp.execute('res.users', 'search',
[('id', '=', self.user.id)])
self.assertIn(self.user.id, result)
self.assertEqual(result[0], self.user.id)
def test_execute_search_without_args(self):
# Handle exception (execute a 'search' without args)
self.assertRaises(
oerplib.error.RPCError,
self.oerp.execute,
'res.users',
'search')
def test_execute_search_with_wrong_args(self):
# Handle exception (execute a 'search' with wrong args)
self.assertRaises(
oerplib.error.RPCError,
self.oerp.execute,
'res.users',
'search',
False) # Wrong arg
def test_execute_search_with_wrong_model(self):
# Handle exception (execute a 'search' with a wrong model)
self.assertRaises(
oerplib.error.RPCError,
self.oerp.execute,
'wrong.model', # Wrong model
'search',
[])
def test_execute_search_with_wrong_method(self):
# Handle exception (execute a 'search' with a wrong method)
self.assertRaises(
oerplib.error.RPCError,
self.oerp.execute,
'res.users',
'wrong_method', # Wrong method
[])
# ------
# Create
# ------
def test_execute_create_with_good_args(self):
login = "%s_%s" % ("foobar", time.time())
# Check the result returned
result = self.oerp.execute(
'res.users', 'create',
{'name': login,
'login': login})
self.assertIsInstance(result, numbers.Number)
# Handle exception (create another user with the same login)
self.assertRaises(
oerplib.error.RPCError,
self.oerp.execute,
'res.users', 'create',
{'name': login, 'login': login})
def test_execute_create_without_args(self):
# Handle exception (execute a 'create' without args)
self.assertRaises(
oerplib.error.RPCError,
self.oerp.execute,
'res.users',
'create')
def test_execute_create_with_wrong_args(self):
# Handle exception (execute a 'create' with wrong args)
self.assertRaises(
oerplib.error.RPCError,
self.oerp.execute,
'res.users',
'create',
False) # Wrong arg
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: