Skip to content

Commit

Permalink
use blocking RPC call db.create_database because db.create and db.get…
Browse files Browse the repository at this point in the history
…_progress are missing in Odoo
  • Loading branch information
florentx committed Sep 23, 2014
1 parent 6a8ae24 commit 602e277
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 23 deletions.
7 changes: 6 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ Changelog
1.x (unreleased)
~~~~~~~~~~~~~~~~

* Compatible with Odoo 8.0.

* New attribute ``Client.context`` to set the default context for
all RPC calls.
high-level ``Model`` and ``Record`` methods.

* Use blocking RPC call in ``Client.create_database``. Asynchronous
method is removed in Odoo.

* Remove a duplicate ``Logged in as ...`` line in interactive mode.

Expand Down
25 changes: 13 additions & 12 deletions erppeek.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,18 +616,19 @@ def create_database(self, passwd, database, demo=False, lang='en_US',
By default, `demo` data are not loaded and `lang` is ``en_US``.
Wait for the thread to finish and login if successful.
"""
thread_id = self.db.create(passwd, database, demo, lang, user_password)
progress = 0
try:
while progress < 1:
time.sleep(3)
progress, users = self.db.get_progress(passwd, thread_id)
# [1.0, [{'login': 'admin', 'password': 'admin',
# 'name': 'Administrator'}]]
self.login(users[0]['login'], users[0]['password'],
database=database)
except KeyboardInterrupt:
print({'id': thread_id, 'progress': progress})
if self.major_version in ('5.0', '6.0'):
thread_id = self.db.create(passwd, database, demo, lang, user_password)
progress = 0
try:
while progress < 1:
time.sleep(3)
progress, users = self.db.get_progress(passwd, thread_id)
except KeyboardInterrupt:
return {'id': thread_id, 'progress': progress}
else:
self.db.create_database(passwd, database, demo, lang,
user_password)
return self.login('admin', user_password, database=database)

def execute(self, obj, method, *params, **kwargs):
"""Wrapper around ``object.execute`` RPC method.
Expand Down
37 changes: 27 additions & 10 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,24 +295,18 @@ def obj_exec(self, *args):

def test_create_database(self):
create_database = self.client.create_database
mock.patch('time.sleep').start()
self.client.db.create.return_value = ID1
self.client.db.get_progress.return_value = \
[1, [{'login': 'LL', 'password': 'PP'}]]
self.client.db.list.side_effect = [['db1'], ['db2']]

create_database('abc', 'db1')
create_database('xyz', 'db2', user_password='secret', lang='fr_FR')

self.assertCalls(
call.db.create('abc', 'db1', False, 'en_US', 'admin'),
call.db.get_progress('abc', ID1),
call.db.create_database('abc', 'db1', False, 'en_US', 'admin'),
call.db.list(),
call.common.login('db1', 'LL', 'PP'),
call.db.create('xyz', 'db2', False, 'fr_FR', 'secret'),
call.db.get_progress('xyz', ID1),
call.common.login('db1', 'admin', 'admin'),
call.db.create_database('xyz', 'db2', False, 'fr_FR', 'secret'),
call.db.list(),
call.common.login('db2', 'LL', 'PP'),
call.common.login('db2', 'admin', 'secret'),
)
self.assertOutput('')

Expand Down Expand Up @@ -742,6 +736,29 @@ def _skip(self):
pass
test_execute_kw = test_render_report = _skip

def test_create_database(self):
create_database = self.client.create_database
mock.patch('time.sleep').start()
self.client.db.create.return_value = ID1
self.client.db.get_progress.return_value = \
[1, [{'login': 'admin', 'password': 'PP'}]]
self.client.db.list.side_effect = [['db1'], ['db2']]

create_database('abc', 'db1')
create_database('xyz', 'db2', user_password='secret', lang='fr_FR')

self.assertCalls(
call.db.create('abc', 'db1', False, 'en_US', 'admin'),
call.db.get_progress('abc', ID1),
call.db.list(),
call.common.login('db1', 'admin', 'admin'),
call.db.create('xyz', 'db2', False, 'fr_FR', 'secret'),
call.db.get_progress('xyz', ID1),
call.db.list(),
call.common.login('db2', 'admin', 'secret'),
)
self.assertOutput('')

def _module_upgrade(self, button='upgrade'):
self.service.object.execute.side_effect = [
[7, 0], [42], {'name': 'Upgrade'}, [4, 42, 5],
Expand Down

0 comments on commit 602e277

Please sign in to comment.