Files
tryton/trytond/tests/tools.py
T

42 lines
1.1 KiB
Python
Raw Normal View History

2016-08-25 22:39:15 +02:00
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
2017-08-02 19:37:32 +02:00
from proteus import config as pconfig, Model, Wizard
2016-08-25 22:39:15 +02:00
from .test_tryton import restore_db_cache, backup_db_cache, drop_create
2017-08-02 19:37:32 +02:00
__all__ = ['activate_modules', 'set_user']
2016-08-25 22:39:15 +02:00
def activate_modules(modules):
2016-08-25 22:39:15 +02:00
if isinstance(modules, basestring):
modules = [modules]
cache_name = '-'.join(modules)
if restore_db_cache(cache_name):
return _get_config()
drop_create()
cfg = _get_config()
Module = Model.get('ir.module')
records = Module.find([
2016-08-25 22:39:15 +02:00
('name', 'in', modules),
])
assert len(records) == len(modules)
Module.click(records, 'activate')
Wizard('ir.module.activate_upgrade').execute('upgrade')
2016-08-25 22:39:15 +02:00
backup_db_cache(cache_name)
return cfg
def _get_config():
2017-08-02 19:37:32 +02:00
cfg = pconfig.set_trytond()
2016-08-25 22:39:15 +02:00
cfg.pool.test = True
return cfg
2017-08-02 19:37:32 +02:00
def set_user(user, config=None):
if not config:
config = pconfig.get_config()
User = Model.get('res.user', config=config)
config.user = int(user)
config._context = User.get_preferences(True, {})