From 9f2cfb2cdf83ef294c8d1e5328577d588ba31485 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 25 Apr 2023 09:02:37 +0000 Subject: [PATCH] [IMP] test_module_operations: make uninstall step more graceful MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - process modules to uninstall individually in order to better handle their state at that point - uninstall (and reinstall) modules in provided order, rather than whatever postgres feels like (or a sort which might not match what we want), mostly useful when uninstalling modules in bulk - warn if a module is either missing or already uninstalled, rather than silently do nothing closes odoo/odoo#120261 X-original-commit: 034b317a908d1aea6dc6d992c489b30ffff8f1ce Signed-off-by: Xavier Morel (xmo) Signed-off-by: Xavier Dollé (xdo) --- odoo/tests/test_module_operations.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/odoo/tests/test_module_operations.py b/odoo/tests/test_module_operations.py index df3c7c64b36..8e60ba4fabb 100755 --- a/odoo/tests/test_module_operations.py +++ b/odoo/tests/test_module_operations.py @@ -157,15 +157,20 @@ def test_cycle(args): def test_uninstall(args): """ Tries to uninstall/reinstall one ore more modules""" - domain = [('name', 'in', args.uninstall.split(',')), ('state', '=', 'installed')] - with odoo.registry(args.database).cursor() as cr: - env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {}) - modules = env['ir.module.module'].search(domain) - modules_todo = [(module.id, module.name) for module in modules] + for module_name in args.uninstall.split(','): + with odoo.registry(args.database).cursor() as cr: + env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {}) + module = env['ir.module.module'].search([('name', '=', module_name)]) + module_id, module_state = module.id, module.state - for module_id, module_name in modules_todo: - uninstall(args.database, module_id, module_name) - if args.reinstall and module_name not in INSTALL_BLACKLIST: + if module_state == 'installed': + uninstall(args.database, module_id, module_name) + if args.reinstall and module_name not in INSTALL_BLACKLIST: + install(args.database, module_id, module_name) + elif module_state: + _logger.warning("Module %r is not installed", module_name) + else: + _logger.warning("Module %r does not exist", module_name) def test_standalone(args):