Skip to content

Commit

Permalink
Merge pull request #99 from WohthaN/master
Browse files Browse the repository at this point in the history
  • Loading branch information
florentx committed Nov 21, 2018
2 parents b775c84 + 045ca85 commit ba7da4a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Expand Up @@ -9,6 +9,9 @@ Changelog

* New method ``Client.clone_database`` based on ``Client.db.duplicate_database``.

* Optional ``login`` and ``country_code`` arguments for
``Client.create_database`` in Odoo 9+.

* Use the ``context`` for the ``search`` methods.

* More robust Python 2 detection logic.
Expand Down
19 changes: 14 additions & 5 deletions erppeek.py
Expand Up @@ -656,14 +656,20 @@ def login(self, user, password=None, database=None):
return global_vars

def create_database(self, passwd, database, demo=False, lang='en_US',
user_password='admin'):
user_password='admin', login='admin', country_code=None):
"""Create a new database.
The superadmin `passwd` and the `database` name are mandatory.
By default, `demo` data are not loaded and `lang` is ``en_US``.
By default, `demo` data are not loaded, `lang` is ``en_US``
and no country is set into the database.
Login if successful.
"""
if self.major_version in ('5.0', '6.0'):
float_version = float(self.major_version)
customize = (login != 'admin' or country_code)
if customize and float_version < 9.0:
raise Error("Custom 'login' and 'country_code' are not supported")

if float_version < 6.1:
thread_id = self.db.create(passwd, database, demo, lang,
user_password)
progress = 0
Expand All @@ -673,10 +679,13 @@ def create_database(self, passwd, database, demo=False, lang='en_US',
progress, users = self.db.get_progress(passwd, thread_id)
except KeyboardInterrupt:
return {'id': thread_id, 'progress': progress}
else:
elif not customize:
self.db.create_database(passwd, database, demo, lang,
user_password)
return self.login('admin', user_password, database=database)
else:
self.db.create_database(passwd, database, demo, lang,
user_password, login, country_code)
return self.login(login, user_password, database=database)

def clone_database(self, passwd, db_name):
"""Clone the current database.
Expand Down
18 changes: 18 additions & 0 deletions tests/test_client.py
Expand Up @@ -327,6 +327,24 @@ def test_create_database(self):
)
self.assertOutput('')

if float(self.server_version) < 9.0:
self.assertRaises(erppeek.Error, create_database, 'xyz', 'db2', user_password='secret', lang='fr_FR', login='other_login', country_code='CA')
self.assertRaises(erppeek.Error, create_database, 'xyz', 'db2', login='other_login')
self.assertRaises(erppeek.Error, create_database, 'xyz', 'db2', country_code='CA')
self.assertOutput('')
return

# Odoo 9
self.client.db.list.side_effect = [['db2']]
create_database('xyz', 'db2', user_password='secret', lang='fr_FR', login='other_login', country_code='CA')

self.assertCalls(
call.db.create_database('xyz', 'db2', False, 'fr_FR', 'secret', 'other_login', 'CA'),
call.db.list(),
call.common.login('db2', 'other_login', 'secret'),
)
self.assertOutput('')

def test_search(self):
search = self.client.search
self.service.object.execute.side_effect = self.obj_exec
Expand Down

0 comments on commit ba7da4a

Please sign in to comment.