server-tools/database_cleanup/tests/test_purge_models.py

41 lines
1.4 KiB
Python

# Copyright 2021 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from .common import Common
class TestCleanupPurgeLineColumn(Common):
def setUp(self):
super(TestCleanupPurgeLineColumn, self).setUp()
# create a nonexistent model
self.model_name = "x_database.cleanup.test.model"
self.model_values = {
"name": "Database cleanup test model",
"model": self.model_name,
}
self.model = self.env["ir.model"].create(self.model_values)
self.env.cr.execute(
"insert into ir_attachment (name, res_model, res_id, type) values "
"('test attachment', %s, 42, 'binary')",
[self.model_name],
)
self.env.registry.models.pop(self.model_name)
def tearDown(self):
""" We recreate the model to avoid registry Exception at loading """
super(TestCleanupPurgeLineColumn, self).tearDown()
# FIXME: issue origin is not clear but it must be addressed.
self.model = self.env["ir.model"].create(self.model_values)
def test_empty_model(self):
wizard = self.env["cleanup.purge.wizard.model"].create({})
wizard.purge_all()
# must be removed by the wizard
self.assertFalse(
self.env["ir.model"].search(
[
("model", "=", self.model_name),
]
)
)