From 602e277b295ecbef0f1a275f39e9fbd3ef484add Mon Sep 17 00:00:00 2001 From: Florent Xicluna Date: Tue, 23 Sep 2014 15:44:24 +0200 Subject: [PATCH] use blocking RPC call db.create_database because db.create and db.get_progress are missing in Odoo --- CHANGES.rst | 7 ++++++- erppeek.py | 25 +++++++++++++------------ tests/test_client.py | 37 +++++++++++++++++++++++++++---------- 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 150843d..a0b082c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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. diff --git a/erppeek.py b/erppeek.py index 27ec4f3..a1d10d5 100644 --- a/erppeek.py +++ b/erppeek.py @@ -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. diff --git a/tests/test_client.py b/tests/test_client.py index 2fda47a..76648e2 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -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('') @@ -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],