Skip to content

- use db_exist service method to check database #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions erppeek.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion tests/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ 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):
self.service.db.list.return_value = ['newdb']
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)
Expand Down Expand Up @@ -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('')
Expand All @@ -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('')
Expand Down Expand Up @@ -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('')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down