[MIG] database_cleanup: Migration to 15.0

pull/2547/head
Maksym Yankin 2023-02-09 13:23:34 +02:00
parent 665573a7d7
commit dbcd7bddd1
10 changed files with 54 additions and 43 deletions

View File

@ -17,7 +17,7 @@ Database cleanup
:target: https://github.com/OCA/server-tools/tree/14.0/database_cleanup :target: https://github.com/OCA/server-tools/tree/14.0/database_cleanup
:alt: OCA/server-tools :alt: OCA/server-tools
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |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 :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/149/14.0 :target: https://runbot.odoo-community.org/runbot/149/14.0

View File

@ -6,16 +6,18 @@ from odoo.tests import TransactionCase
class Common(TransactionCase): class Common(TransactionCase):
def setUp(self): @classmethod
super(Common, self).setUp() def setUpClass(cls):
super().setUpClass()
# this reloads our registry, and we don't want to run tests twice # 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 # we also need the original registry for further tests, so save a
# reference to it # reference to it
self.original_registry = Registry.registries[self.env.cr.dbname] cls.original_registry = Registry.registries[cls.env.cr.dbname]
def tearDown(self): @classmethod
super(Common, self).tearDown() def tearDownClass(cls):
super().tearDownClass()
# Force rollback to avoid unstable test database # Force rollback to avoid unstable test database
self.env.cr.rollback() cls.env.cr.rollback()
# reset afterwards # reset afterwards
Registry.registries[self.env.cr.dbname] = self.original_registry Registry.registries[cls.env.cr.dbname] = cls.original_registry

View File

@ -9,10 +9,11 @@ from .common import Common
# Use post_install to get all models loaded more info: odoo/odoo#13458 # Use post_install to get all models loaded more info: odoo/odoo#13458
@tagged("post_install", "-at_install") @tagged("post_install", "-at_install")
class TestCreateIndexesLine(Common): class TestCreateIndexesLine(Common):
def setUp(self): @classmethod
super(TestCreateIndexesLine, self).setUp() def setUpClass(cls):
super().setUpClass()
# delete some index and check if our module recreated it # 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): def test_deleted_index(self):
wizard = self.env["cleanup.create_indexes.wizard"].create({}) wizard = self.env["cleanup.create_indexes.wizard"].create({})

View File

@ -11,10 +11,11 @@ from .common import Common
# Use post_install to get all models loaded more info: odoo/odoo#13458 # Use post_install to get all models loaded more info: odoo/odoo#13458
@tagged("post_install", "-at_install") @tagged("post_install", "-at_install")
class TestCleanupPurgeLineColumn(Common): class TestCleanupPurgeLineColumn(Common):
def setUp(self): @classmethod
super(TestCleanupPurgeLineColumn, self).setUp() def setUpClass(cls):
super().setUpClass()
# create an orphaned column # create an orphaned column
self.env.cr.execute( cls.env.cr.execute(
"alter table res_partner add column database_cleanup_test int" "alter table res_partner add column database_cleanup_test int"
) )

View File

@ -9,16 +9,17 @@ from .common import Common
# Use post_install to get all models loaded more info: odoo/odoo#13458 # Use post_install to get all models loaded more info: odoo/odoo#13458
@tagged("post_install", "-at_install") @tagged("post_install", "-at_install")
class TestCleanupPurgeLineData(Common): class TestCleanupPurgeLineData(Common):
def setUp(self): @classmethod
super(TestCleanupPurgeLineData, self).setUp() def setUpClass(cls):
super().setUpClass()
# create a data entry pointing nowhere # create a data entry pointing nowhere
self.env.cr.execute("select max(id) + 1 from res_users") cls.env.cr.execute("select max(id) + 1 from res_users")
self.env["ir.model.data"].create( cls.env["ir.model.data"].create(
{ {
"module": "database_cleanup", "module": "database_cleanup",
"name": "test_no_data_entry", "name": "test_no_data_entry",
"model": "res.users", "model": "res.users",
"res_id": self.env.cr.fetchone()[0], "res_id": cls.env.cr.fetchone()[0],
} }
) )

View File

@ -9,10 +9,11 @@ from .common import Common
# Use post_install to get all models loaded more info: odoo/odoo#13458 # Use post_install to get all models loaded more info: odoo/odoo#13458
@tagged("post_install", "-at_install") @tagged("post_install", "-at_install")
class TestCleanupPurgeLineMenu(Common): class TestCleanupPurgeLineMenu(Common):
def setUp(self): @classmethod
super(TestCleanupPurgeLineMenu, self).setUp() def setUpClass(cls):
super().setUpClass()
# create a new empty menu # 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): def test_empty_menu(self):
wizard = self.env["cleanup.purge.wizard.menu"].create( wizard = self.env["cleanup.purge.wizard.menu"].create(

View File

@ -9,27 +9,29 @@ from .common import Common
# Use post_install to get all models loaded more info: odoo/odoo#13458 # Use post_install to get all models loaded more info: odoo/odoo#13458
@tagged("post_install", "-at_install") @tagged("post_install", "-at_install")
class TestCleanupPurgeLineColumn(Common): class TestCleanupPurgeLineColumn(Common):
def setUp(self): @classmethod
super(TestCleanupPurgeLineColumn, self).setUp() def setUpClass(cls):
super().setUpClass()
# create a nonexistent model # create a nonexistent model
self.model_name = "x_database.cleanup.test.model" cls.model_name = "x_database.cleanup.test.model"
self.model_values = { cls.model_values = {
"name": "Database cleanup test model", "name": "Database cleanup test model",
"model": self.model_name, "model": cls.model_name,
} }
self.model = self.env["ir.model"].create(self.model_values) cls.model = cls.env["ir.model"].create(cls.model_values)
self.env.cr.execute( cls.env.cr.execute(
"insert into ir_attachment (name, res_model, res_id, type) values " "insert into ir_attachment (name, res_model, res_id, type) values "
"('test attachment', %s, 42, 'binary')", "('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""" """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. # 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): def test_empty_model(self):
wizard = self.env["cleanup.purge.wizard.model"].create({}) wizard = self.env["cleanup.purge.wizard.model"].create({})

View File

@ -9,10 +9,11 @@ from .common import Common
# Use post_install to get all models loaded more info: odoo/odoo#13458 # Use post_install to get all models loaded more info: odoo/odoo#13458
@tagged("post_install", "-at_install") @tagged("post_install", "-at_install")
class TestCleanupPurgeLineModule(Common): class TestCleanupPurgeLineModule(Common):
def setUp(self): @classmethod
super(TestCleanupPurgeLineModule, self).setUp() def setUpClass(cls):
super().setUpClass()
# create a nonexistent module # create a nonexistent module
self.module = self.env["ir.module.module"].create( cls.module = cls.env["ir.module.module"].create(
{ {
"name": "database_cleanup_test", "name": "database_cleanup_test",
"state": "to upgrade", "state": "to upgrade",

View File

@ -9,10 +9,11 @@ from .common import Common
# Use post_install to get all models loaded more info: odoo/odoo#13458 # Use post_install to get all models loaded more info: odoo/odoo#13458
@tagged("post_install", "-at_install") @tagged("post_install", "-at_install")
class TestCleanupPurgeLineProperty(Common): class TestCleanupPurgeLineProperty(Common):
def setUp(self): @classmethod
super(TestCleanupPurgeLineProperty, self).setUp() def setUpClass(cls):
super().setUpClass()
# Create one property for tests # 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 [("name", "=", "name"), ("model_id.model", "=", "res.partner")], limit=1
) )

View File

@ -11,10 +11,11 @@ from .common import Common
# Use post_install to get all models loaded more info: odoo/odoo#13458 # Use post_install to get all models loaded more info: odoo/odoo#13458
@tagged("post_install", "-at_install") @tagged("post_install", "-at_install")
class TestCleanupPurgeLineTable(Common): class TestCleanupPurgeLineTable(Common):
def setUp(self): @classmethod
super(TestCleanupPurgeLineTable, self).setUp() def setUpClass(cls):
super().setUpClass()
# create an orphaned table # 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): def test_empty_table(self):
wizard = self.env["cleanup.purge.wizard.table"].create({}) wizard = self.env["cleanup.purge.wizard.table"].create({})