Add setup methods to activate_modules

This commit is contained in:
Cédric Krier
2024-09-10 18:01:29 +02:00
parent 529fa7bb0e
commit d83bcc784c
3 changed files with 20 additions and 3 deletions
+1
View File
@@ -1,3 +1,4 @@
* Add setup methods to activate_modules
* Add method to the backend to estimate number of rows
* Add setup indexes method to ModelSQL
* Support getting many sequences at once
+3 -1
View File
@@ -184,9 +184,11 @@ doctest helpers
Tools
-----
.. function:: activate_modules(modules)
.. function:: activate_modules(modules, \*setup)
Activate a list of ``modules`` for scenario based on proteus doctests.
The following arguments are functions sequentially called at the end of the
activation with the proteus configuration as ``config`` keyword argument.
.. function:: set_user(user, config)
+16 -2
View File
@@ -2,6 +2,7 @@
# this repository contains the full copyright notices and license terms.
import unittest
from functools import partial
from proteus import Model, Wizard
from proteus import config as pconfig
@@ -11,10 +12,20 @@ from .test_tryton import backup_db_cache, drop_create, restore_db_cache
__all__ = ['activate_modules', 'set_user']
def activate_modules(modules):
def _func_name(func):
if isinstance(func, partial):
return f'{func.func.__qualname__}(*{func.args}, **{func.keywords})'
else:
assert not hasattr(func, '__self__')
return func.__qualname__
def activate_modules(modules, *setup):
if isinstance(modules, str):
modules = [modules]
cache_name = '-'.join(modules)
cache_name = '-'.join(sorted(modules))
if setup_name := '|'.join(_func_name(f) for f in setup):
cache_name += f'--{setup_name}'
if restore_db_cache(cache_name):
return _get_config()
drop_create()
@@ -28,6 +39,9 @@ def activate_modules(modules):
Module.click(records, 'activate')
Wizard('ir.module.activate_upgrade').execute('upgrade')
for func in setup:
func(config=cfg)
backup_db_cache(cache_name)
return cfg