From 030326f97704a59d93aea655c5f62af66a5aea91 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Tue, 2 Aug 2016 12:55:43 +0200 Subject: [PATCH] [FIX] purge uninstalled uninstallable modules instead of deleting [FIX] database_cleanup reloads the registry which has weird side effects during testing. Take care database_cleanup's tests don't mess up the following tests --- database_cleanup/models/purge_modules.py | 4 +++- database_cleanup/tests/test_database_cleanup.py | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/database_cleanup/models/purge_modules.py b/database_cleanup/models/purge_modules.py index 9664d1a21..4804e64ee 100644 --- a/database_cleanup/models/purge_modules.py +++ b/database_cleanup/models/purge_modules.py @@ -69,7 +69,9 @@ class CleanupPurgeWizardModule(models.TransientModel): if get_module_path(module.name): continue if module.state == 'uninstalled': - module.unlink() + self.env['cleanup.purge.line.module'].create({ + 'name': module.name, + }).purge() continue res.append((0, 0, {'name': module.name})) diff --git a/database_cleanup/tests/test_database_cleanup.py b/database_cleanup/tests/test_database_cleanup.py index f04609f1c..060c9174e 100644 --- a/database_cleanup/tests/test_database_cleanup.py +++ b/database_cleanup/tests/test_database_cleanup.py @@ -2,6 +2,7 @@ # © 2016 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from psycopg2 import ProgrammingError +from openerp.modules.registry import RegistryManager from openerp.tools import config from openerp.tests.common import TransactionCase @@ -57,6 +58,9 @@ class TestDatabaseCleanup(TransactionCase): }) purge_modules = self.env['cleanup.purge.wizard.module'].create({}) # this reloads our registry, and we don't want to run tests twice + # we also need the original registry for further tests, so save a + # reference to it + original_registry = RegistryManager.registries[self.env.cr.dbname] config.options['test_enable'] = False purge_modules.purge_all() config.options['test_enable'] = True @@ -64,6 +68,8 @@ class TestDatabaseCleanup(TransactionCase): self.assertFalse(self.env['ir.module.module'].search([ ('name', '=', 'database_cleanup_test'), ])) + # reset afterwards + RegistryManager.registries[self.env.cr.dbname] = original_registry # create an orphaned table self.env.cr.execute('create table database_cleanup_test (test int)')