diff --git a/erppeek.py b/erppeek.py index 50ec695..d67478a 100644 --- a/erppeek.py +++ b/erppeek.py @@ -572,13 +572,13 @@ def login(self, user, password=None, database=None): """ if database: try: - dbs = self.db.list() + is_database_exist = self.db.db_exist(database) except Fault: pass # AccessDenied: simply ignore this check else: - if database not in dbs: - raise Error("Database '%s' does not exist: %s" % - (database, dbs)) + if not is_database_exist: + raise Error("Database '%s' does not exist" % + (database)) if not self._db: self._db = database # Used for logging, copied from odoo.sql_db.db_connect diff --git a/tests/_common.py b/tests/_common.py index 7200c3a..ebd0aa6 100644 --- a/tests/_common.py +++ b/tests/_common.py @@ -89,7 +89,18 @@ def assertCalls(self, *expected_args): if expected[:4] == 'call': expected = expected[4:].lstrip('.') assert expected[-2:] != '()' - expected = type_call((expected,)) + if '(' in expected: + import re + import ast + g = re.search('\((.*?)\)', expected) + if g.groups(): + if g.groups()[0]: + params = ast.literal_eval( g.groups()[0] + ',') + expected = type_call((expected.split('(')[0],params)) + else: + expected = type_call((expected,)) + else: + expected = type_call((expected,)) elif not (expected is mock.ANY or isinstance(expected, type_call)): rpcmethod = expected[0] if len(expected) > 1 and expected[1] == sentinel.AUTH: diff --git a/tests/test_client.py b/tests/test_client.py index 810da69..c978b45 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -147,7 +147,7 @@ class TestCreateClient(XmlRpcTestCase): call(ANY, 'object', ANY, verbose=ANY), call(ANY, 'report', ANY, verbose=ANY), call(ANY, 'wizard', ANY, verbose=ANY), - 'db.list', + "call.db.db_exist('database')" ) def test_create(self): @@ -155,7 +155,7 @@ def test_create(self): self.service.common.login.return_value = 1 client = erppeek.Client('http://127.0.0.1:8069', 'newdb', 'usr', 'pss') - expected_calls = self.startup_calls + ( + expected_calls = self.startup_calls[:-1] + ("call.db.db_exist('newdb')", ('common.login', 'newdb', 'usr', 'pss'),) self.assertIsInstance(client, erppeek.Client) self.assertCalls(*expected_calls) @@ -349,10 +349,10 @@ def test_create_database(self): self.assertCalls( call.db.create_database('abc', 'db1', False, 'en_US', 'admin'), - call.db.list(), + call.db.db_exist('db1'), call.common.login('db1', 'admin', 'admin'), call.db.create_database('xyz', 'db2', False, 'fr_FR', 'secret'), - call.db.list(), + call.db.db_exist('db2'), call.common.login('db2', 'admin', 'secret'), ) self.assertOutput('') @@ -370,7 +370,7 @@ def test_create_database(self): self.assertCalls( call.db.create_database('xyz', 'db2', False, 'fr_FR', 'secret', 'other_login', 'CA'), - call.db.list(), + call.db.db_exist('db2'), call.common.login('db2', 'other_login', 'secret'), ) self.assertOutput('') @@ -826,11 +826,11 @@ def test_create_database(self): self.assertCalls( call.db.create('abc', 'db1', False, 'en_US', 'admin'), call.db.get_progress('abc', ID1), - call.db.list(), + call.db.db_exist('db1'), 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.db.db_exist('db2'), call.common.login('db2', 'admin', 'secret'), ) self.assertOutput('') diff --git a/tests/test_interact.py b/tests/test_interact.py index 4d7a798..e8aa1cd 100644 --- a/tests/test_interact.py +++ b/tests/test_interact.py @@ -18,7 +18,7 @@ class TestInteract(XmlRpcTestCase): call(ANY, 'object', ANY, verbose=ANY), call(ANY, 'report', ANY, verbose=ANY), call(ANY, 'wizard', ANY, verbose=ANY), - 'db.list', + "call.db.db_exist('database')" ) def setUp(self):