Skip to content

Commit

Permalink
review the list of RPC methods exposed by Odoo
Browse files Browse the repository at this point in the history
  • Loading branch information
florentx committed Sep 23, 2014
1 parent 8edcdac commit 6a8ae24
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
48 changes: 25 additions & 23 deletions erppeek.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,27 @@ def _dict_to_list(self, rowdict):

# Published object methods
_methods = {
'db': ['create', 'drop', 'dump', 'restore', 'rename',
'get_progress', 'list', 'list_lang',
'db': ['create_database', 'duplicate_database', 'db_exist',
'drop', 'dump', 'restore', 'rename', 'list', 'list_lang',
'change_admin_password', 'server_version', 'migrate_databases'],
'common': ['about', 'login', 'timezone_get', 'get_server_environment',
'login_message', 'check_connectivity'],
'object': ['execute', 'exec_workflow'],
'report': ['report', 'report_get'],
'wizard': ['execute', 'create'],
'common': ['about', 'login', 'timezone_get',
'authenticate', 'version', 'set_loglevel'],
'object': ['execute', 'execute_kw', 'exec_workflow'],
'report': ['render_report', 'report', 'report_get'],
}
_methods_6_1 = {
'db': ['create_database', 'db_exist'],
'common': ['get_stats', 'list_http_services', 'version',
'authenticate', 'get_os_time', 'get_sqlcount'],
'object': ['execute_kw'],
'report': ['render_report'],
# New 6.1: (db) create_database db_exist,
# (common) authenticate version set_loglevel
# (object) execute_kw, (report) render_report
# New 7.0: (db) duplicate_database

_obsolete_methods = {
'db': ['create', 'get_progress'], # < 8.0
'common': ['check_connectivity', 'get_available_updates', 'get_os_time',
'get_migration_scripts', 'get_server_environment',
'get_sqlcount', 'get_stats',
'list_http_services', 'login_message'], # < 8.0
'wizard': ['execute', 'create'], # < 7.0
}
# Hidden methods:
# - common: get_available_updates, get_migration_scripts, set_loglevel
_cause_message = ("\nThe above exception was the direct cause "
"of the following exception:\n\n")

Expand Down Expand Up @@ -405,23 +408,22 @@ def __init__(self, server, db=None, user=None, password=None,
appname = os.path.basename(__file__).rstrip('co')
server = start_odoo_services(server, appname=appname)
self._server = server
major_version = None
float_version = 999

def get_proxy(name):
if major_version in ('5.0', None) or name == 'wizard':
methods = _methods[name]
else:
# Only for Odoo and OpenERP >= 6
methods = _methods[name] + _methods_6_1[name]
methods = list(_methods[name]) if (name in _methods) else []
if float_version < 8.0:
methods += _obsolete_methods.get(name) or ()
return Service(server, name, methods, verbose=verbose)
self.server_version = ver = get_proxy('db').server_version()
self.major_version = major_version = '.'.join(ver.split('.', 2)[:2])
self.major_version = re.match('\d+\.?\d*', ver).group()
float_version = float(self.major_version)
# Create the XML-RPC proxies
self.db = get_proxy('db')
self.common = get_proxy('common')
self._object = get_proxy('object')
self._report = get_proxy('report')
self._wizard = get_proxy('wizard') if major_version < '7.0' else None
self._wizard = get_proxy('wizard') if float_version < 7.0 else None
self.reset()
self.context = None
if db:
Expand Down
13 changes: 7 additions & 6 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@ def test_service_openerp_client(self, server_version='8.0'):
else:
self.assertIsInstance(client._wizard, erppeek.Service)

self.assertIn('/xmlrpc/db', str(client.db.create))
if server_version == '5.0':
self.assertIn('/xmlrpc/db', str(client.db.create_database))
self.assertIn('/xmlrpc/db', str(client.db.db_exist))
if server_version == '8.0':
self.assertRaises(AttributeError, getattr,
client.db, 'create_database')
client.db, 'create')
self.assertRaises(AttributeError, getattr,
client.db, 'db_exist')
client.db, 'get_progress')
else:
self.assertIn('/xmlrpc/db', str(client.db.create_database))
self.assertIn('/xmlrpc/db', str(client.db.db_exist))
self.assertIn('/xmlrpc/db', str(client.db.create))
self.assertIn('/xmlrpc/db', str(client.db.get_progress))

self.assertCalls(ANY, ANY, ANY)
self.assertOutput('')
Expand Down

0 comments on commit 6a8ae24

Please sign in to comment.