diff --git a/database_cleanup/README.rst b/database_cleanup/README.rst index a07c075a7..8f54fc7f7 100644 --- a/database_cleanup/README.rst +++ b/database_cleanup/README.rst @@ -17,7 +17,7 @@ Database cleanup :target: https://github.com/OCA/server-tools/tree/14.0/database_cleanup :alt: OCA/server-tools .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/server-tools-14-0/server-tools-14-0-database_cleanup + :target: https://translation.odoo-community.org/projects/server-tools-15-0/server-tools-15-0-database_cleanup :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png :target: https://runbot.odoo-community.org/runbot/149/14.0 diff --git a/database_cleanup/tests/common.py b/database_cleanup/tests/common.py index 6449365d4..4779bdec6 100644 --- a/database_cleanup/tests/common.py +++ b/database_cleanup/tests/common.py @@ -6,16 +6,18 @@ from odoo.tests import TransactionCase class Common(TransactionCase): - def setUp(self): - super(Common, self).setUp() + @classmethod + def setUpClass(cls): + super().setUpClass() # 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 - self.original_registry = Registry.registries[self.env.cr.dbname] + cls.original_registry = Registry.registries[cls.env.cr.dbname] - def tearDown(self): - super(Common, self).tearDown() + @classmethod + def tearDownClass(cls): + super().tearDownClass() # Force rollback to avoid unstable test database - self.env.cr.rollback() + cls.env.cr.rollback() # reset afterwards - Registry.registries[self.env.cr.dbname] = self.original_registry + Registry.registries[cls.env.cr.dbname] = cls.original_registry diff --git a/database_cleanup/tests/test_create_indexes.py b/database_cleanup/tests/test_create_indexes.py index 70f0403f5..f92196056 100644 --- a/database_cleanup/tests/test_create_indexes.py +++ b/database_cleanup/tests/test_create_indexes.py @@ -9,10 +9,11 @@ from .common import Common # Use post_install to get all models loaded more info: odoo/odoo#13458 @tagged("post_install", "-at_install") class TestCreateIndexesLine(Common): - def setUp(self): - super(TestCreateIndexesLine, self).setUp() + @classmethod + def setUpClass(cls): + super().setUpClass() # delete some index and check if our module recreated it - self.env.cr.execute("drop index res_partner_name_index") + cls.env.cr.execute("drop index res_partner_name_index") def test_deleted_index(self): wizard = self.env["cleanup.create_indexes.wizard"].create({}) diff --git a/database_cleanup/tests/test_purge_columns.py b/database_cleanup/tests/test_purge_columns.py index 31dba2dcb..331bf54ce 100644 --- a/database_cleanup/tests/test_purge_columns.py +++ b/database_cleanup/tests/test_purge_columns.py @@ -11,10 +11,11 @@ from .common import Common # Use post_install to get all models loaded more info: odoo/odoo#13458 @tagged("post_install", "-at_install") class TestCleanupPurgeLineColumn(Common): - def setUp(self): - super(TestCleanupPurgeLineColumn, self).setUp() + @classmethod + def setUpClass(cls): + super().setUpClass() # create an orphaned column - self.env.cr.execute( + cls.env.cr.execute( "alter table res_partner add column database_cleanup_test int" ) diff --git a/database_cleanup/tests/test_purge_data.py b/database_cleanup/tests/test_purge_data.py index b1f3f054c..1abce0e47 100644 --- a/database_cleanup/tests/test_purge_data.py +++ b/database_cleanup/tests/test_purge_data.py @@ -9,16 +9,17 @@ from .common import Common # Use post_install to get all models loaded more info: odoo/odoo#13458 @tagged("post_install", "-at_install") class TestCleanupPurgeLineData(Common): - def setUp(self): - super(TestCleanupPurgeLineData, self).setUp() + @classmethod + def setUpClass(cls): + super().setUpClass() # create a data entry pointing nowhere - self.env.cr.execute("select max(id) + 1 from res_users") - self.env["ir.model.data"].create( + cls.env.cr.execute("select max(id) + 1 from res_users") + cls.env["ir.model.data"].create( { "module": "database_cleanup", "name": "test_no_data_entry", "model": "res.users", - "res_id": self.env.cr.fetchone()[0], + "res_id": cls.env.cr.fetchone()[0], } ) diff --git a/database_cleanup/tests/test_purge_menus.py b/database_cleanup/tests/test_purge_menus.py index 65112b807..f3718bc36 100644 --- a/database_cleanup/tests/test_purge_menus.py +++ b/database_cleanup/tests/test_purge_menus.py @@ -9,10 +9,11 @@ from .common import Common # Use post_install to get all models loaded more info: odoo/odoo#13458 @tagged("post_install", "-at_install") class TestCleanupPurgeLineMenu(Common): - def setUp(self): - super(TestCleanupPurgeLineMenu, self).setUp() + @classmethod + def setUpClass(cls): + super().setUpClass() # create a new empty menu - self.menu = self.env["ir.ui.menu"].create({"name": "database_cleanup_test"}) + cls.menu = cls.env["ir.ui.menu"].create({"name": "database_cleanup_test"}) def test_empty_menu(self): wizard = self.env["cleanup.purge.wizard.menu"].create( diff --git a/database_cleanup/tests/test_purge_models.py b/database_cleanup/tests/test_purge_models.py index 996066769..25457b4d5 100644 --- a/database_cleanup/tests/test_purge_models.py +++ b/database_cleanup/tests/test_purge_models.py @@ -9,27 +9,29 @@ from .common import Common # Use post_install to get all models loaded more info: odoo/odoo#13458 @tagged("post_install", "-at_install") class TestCleanupPurgeLineColumn(Common): - def setUp(self): - super(TestCleanupPurgeLineColumn, self).setUp() + @classmethod + def setUpClass(cls): + super().setUpClass() # create a nonexistent model - self.model_name = "x_database.cleanup.test.model" - self.model_values = { + cls.model_name = "x_database.cleanup.test.model" + cls.model_values = { "name": "Database cleanup test model", - "model": self.model_name, + "model": cls.model_name, } - self.model = self.env["ir.model"].create(self.model_values) - self.env.cr.execute( + cls.model = cls.env["ir.model"].create(cls.model_values) + cls.env.cr.execute( "insert into ir_attachment (name, res_model, res_id, type) values " "('test attachment', %s, 42, 'binary')", - [self.model_name], + [cls.model_name], ) - self.env.registry.models.pop(self.model_name) + cls.env.registry.models.pop(cls.model_name) - def tearDown(self): + @classmethod + def tearDownClass(cls): """We recreate the model to avoid registry Exception at loading""" - super(TestCleanupPurgeLineColumn, self).tearDown() + super().tearDownClass() # FIXME: issue origin is not clear but it must be addressed. - self.model = self.env["ir.model"].create(self.model_values) + cls.model = cls.env["ir.model"].create(cls.model_values) def test_empty_model(self): wizard = self.env["cleanup.purge.wizard.model"].create({}) diff --git a/database_cleanup/tests/test_purge_modules.py b/database_cleanup/tests/test_purge_modules.py index c361f7c61..36ddc1531 100644 --- a/database_cleanup/tests/test_purge_modules.py +++ b/database_cleanup/tests/test_purge_modules.py @@ -9,10 +9,11 @@ from .common import Common # Use post_install to get all models loaded more info: odoo/odoo#13458 @tagged("post_install", "-at_install") class TestCleanupPurgeLineModule(Common): - def setUp(self): - super(TestCleanupPurgeLineModule, self).setUp() + @classmethod + def setUpClass(cls): + super().setUpClass() # create a nonexistent module - self.module = self.env["ir.module.module"].create( + cls.module = cls.env["ir.module.module"].create( { "name": "database_cleanup_test", "state": "to upgrade", diff --git a/database_cleanup/tests/test_purge_properties.py b/database_cleanup/tests/test_purge_properties.py index 6cde440cc..23094bd9f 100644 --- a/database_cleanup/tests/test_purge_properties.py +++ b/database_cleanup/tests/test_purge_properties.py @@ -9,10 +9,11 @@ from .common import Common # Use post_install to get all models loaded more info: odoo/odoo#13458 @tagged("post_install", "-at_install") class TestCleanupPurgeLineProperty(Common): - def setUp(self): - super(TestCleanupPurgeLineProperty, self).setUp() + @classmethod + def setUpClass(cls): + super().setUpClass() # Create one property for tests - self.partner_name_field_id = self.env["ir.model.fields"].search( + cls.partner_name_field_id = cls.env["ir.model.fields"].search( [("name", "=", "name"), ("model_id.model", "=", "res.partner")], limit=1 ) diff --git a/database_cleanup/tests/test_purge_tables.py b/database_cleanup/tests/test_purge_tables.py index 7b1119d04..4b1552c58 100644 --- a/database_cleanup/tests/test_purge_tables.py +++ b/database_cleanup/tests/test_purge_tables.py @@ -11,10 +11,11 @@ from .common import Common # Use post_install to get all models loaded more info: odoo/odoo#13458 @tagged("post_install", "-at_install") class TestCleanupPurgeLineTable(Common): - def setUp(self): - super(TestCleanupPurgeLineTable, self).setUp() + @classmethod + def setUpClass(cls): + super().setUpClass() # create an orphaned table - self.env.cr.execute("create table database_cleanup_test (test int)") + cls.env.cr.execute("create table database_cleanup_test (test int)") def test_empty_table(self): wizard = self.env["cleanup.purge.wizard.table"].create({})