mirror of
https://github.com/bringout/oca-technical.git
synced 2026-04-18 10:52:03 +02:00
Initial commit: OCA Technical packages (595 packages)
This commit is contained in:
commit
2cc02aac6e
24950 changed files with 2318079 additions and 0 deletions
|
|
@ -0,0 +1,14 @@
|
|||
# Copyright 2016 Therp BV <http://therp.nl>
|
||||
# Copyright 2021 Camptocamp
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from . import common
|
||||
from . import test_create_indexes
|
||||
from . import test_identifier_adapter
|
||||
from . import test_purge_columns
|
||||
from . import test_purge_data
|
||||
from . import test_purge_fields
|
||||
from . import test_purge_menus
|
||||
from . import test_purge_models
|
||||
from . import test_purge_modules
|
||||
from . import test_purge_properties
|
||||
from . import test_purge_tables
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
# Copyright 2021 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from contextlib import contextmanager
|
||||
|
||||
import odoo
|
||||
from odoo.tests import common
|
||||
from odoo.tests.common import BaseCase, tagged
|
||||
|
||||
ADMIN_USER_ID = common.ADMIN_USER_ID
|
||||
|
||||
|
||||
@contextmanager
|
||||
def environment():
|
||||
"""Return an environment with a new cursor for the current database; the
|
||||
cursor is committed and closed after the context block.
|
||||
"""
|
||||
registry = odoo.registry(common.get_db_name())
|
||||
with registry.cursor() as cr:
|
||||
yield odoo.api.Environment(cr, ADMIN_USER_ID, {})
|
||||
|
||||
|
||||
# Use post_install to get all models loaded more info: odoo/odoo#13458
|
||||
@tagged("post_install", "-at_install")
|
||||
class Common(BaseCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
# Copyright 2021 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo.tests.common import tagged
|
||||
|
||||
from .common import Common, environment
|
||||
|
||||
|
||||
# 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().setUp()
|
||||
with environment() as env:
|
||||
# delete some index and check if our module recreated it
|
||||
env.cr.execute("drop index res_partner_name_index")
|
||||
|
||||
def test_deleted_index(self):
|
||||
with environment() as env:
|
||||
wizard = env["cleanup.create_indexes.wizard"].create({})
|
||||
wizard.purge_all()
|
||||
env.cr.execute(
|
||||
"select indexname from pg_indexes where "
|
||||
"indexname='res_partner_name_index' and tablename='res_partner' "
|
||||
)
|
||||
self.assertEqual(env.cr.rowcount, 1)
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
from odoo.tests import TransactionCase
|
||||
|
||||
from odoo.addons.database_cleanup.identifier_adapter import IdentifierAdapter
|
||||
|
||||
|
||||
class TestIdentifierAdapter(TransactionCase):
|
||||
def test_column_name_with_spaces(self):
|
||||
"""Spaces in column names are preserved except in unquoted identifiers."""
|
||||
self.assertEqual(
|
||||
self.env.cr.mogrify("%s", (IdentifierAdapter("snailmail_cover "),)),
|
||||
b'"snailmail_cover "',
|
||||
)
|
||||
self.assertEqual(
|
||||
self.env.cr.mogrify(
|
||||
"%s", (IdentifierAdapter("snailmail_cover ", quote=False),)
|
||||
),
|
||||
b"snailmail_cover",
|
||||
)
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
# Copyright 2021 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from psycopg2 import ProgrammingError
|
||||
|
||||
from odoo.tests.common import tagged
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
from .common import Common, environment
|
||||
|
||||
|
||||
# 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().setUp()
|
||||
with environment() as env:
|
||||
# create an orphaned column
|
||||
env.cr.execute(
|
||||
"alter table res_partner add column database_cleanup_test int"
|
||||
)
|
||||
|
||||
def test_empty_column(self):
|
||||
with environment() as env:
|
||||
# We need use a model that is not blocked (Avoid use res.users)
|
||||
partner_model = env["ir.model"].search(
|
||||
[("model", "=", "res.partner")], limit=1
|
||||
)
|
||||
wizard = env["cleanup.purge.wizard.column"].create(
|
||||
{
|
||||
"purge_line_ids": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"model_id": partner_model.id,
|
||||
"name": "database_cleanup_test",
|
||||
},
|
||||
)
|
||||
]
|
||||
}
|
||||
)
|
||||
wizard.purge_all()
|
||||
# must be removed by the wizard
|
||||
with self.assertRaises(ProgrammingError):
|
||||
with env.registry.cursor() as cr:
|
||||
with mute_logger("odoo.sql_db"):
|
||||
cr.execute("select database_cleanup_test from res_partner")
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
# Copyright 2021 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo.tests.common import tagged
|
||||
|
||||
from .common import Common, environment
|
||||
|
||||
|
||||
# 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().setUp()
|
||||
with environment() as env:
|
||||
# create a data entry pointing nowhere
|
||||
env.cr.execute("select max(id) + 1 from res_users")
|
||||
env["ir.model.data"].create(
|
||||
{
|
||||
"module": "database_cleanup",
|
||||
"name": "test_no_data_entry",
|
||||
"model": "res.users",
|
||||
"res_id": env.cr.fetchone()[0],
|
||||
}
|
||||
)
|
||||
|
||||
def test_pointing_nowhere(self):
|
||||
with environment() as env:
|
||||
wizard = env["cleanup.purge.wizard.data"].create({})
|
||||
wizard.purge_all()
|
||||
# must be removed by the wizard
|
||||
with self.assertRaises(ValueError):
|
||||
env.ref("database_cleanup.test_no_data_entry")
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
# Copyright 2021 Camptocamp SA
|
||||
# Copyright 2024 360ERP (https://www.360erp.com)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo.tests.common import tagged
|
||||
|
||||
from .common import Common, environment
|
||||
|
||||
|
||||
# Use post_install to get all models loaded more info: odoo/odoo#13458
|
||||
@tagged("post_install", "-at_install")
|
||||
class TestCleanupPurgeFields(Common):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
with environment() as env:
|
||||
|
||||
# create a nonexistent model
|
||||
self.model_name = "x_database.cleanup.test.field.model"
|
||||
self.model_values = {
|
||||
"name": "Database cleanup test field-model",
|
||||
"model": self.model_name,
|
||||
}
|
||||
self.model = env["ir.model"].create(self.model_values)
|
||||
env.cr.execute(
|
||||
"insert into ir_attachment (name, res_model, res_id, type) values "
|
||||
"('test attachment', %s, 42, 'binary')",
|
||||
[self.model_name],
|
||||
)
|
||||
|
||||
# create a nonexistent field
|
||||
self.field_name = "x_database_cleanup_test_field"
|
||||
self.field_values = {
|
||||
"name": self.field_name,
|
||||
"model_id": self.model.id,
|
||||
"field_description": "Database cleanup test field",
|
||||
"ttype": "boolean",
|
||||
}
|
||||
self.field = env["ir.model.fields"].create(self.field_values)
|
||||
|
||||
env.cr.execute(
|
||||
"update ir_model_fields set state = 'base' where id = %s ",
|
||||
[self.field.id],
|
||||
)
|
||||
env.registry.models[self.model_name]._fields.pop(self.field_name)
|
||||
|
||||
def test_empty_field(self):
|
||||
with environment() as env:
|
||||
wizard = env["cleanup.purge.wizard.field"].create({})
|
||||
wizard.purge_all()
|
||||
# must be removed by the wizard
|
||||
self.assertFalse(
|
||||
env["ir.model.fields"].search(
|
||||
[
|
||||
("name", "=", self.field_name),
|
||||
]
|
||||
)
|
||||
)
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
# Copyright 2021 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo.tests.common import tagged
|
||||
|
||||
from .common import Common, environment
|
||||
|
||||
|
||||
# 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().setUp()
|
||||
with environment() as env:
|
||||
# create a new empty menu
|
||||
self.menu = env["ir.ui.menu"].create({"name": "database_cleanup_test"})
|
||||
|
||||
def test_empty_menu(self):
|
||||
with environment() as env:
|
||||
wizard = env["cleanup.purge.wizard.menu"].create(
|
||||
{
|
||||
"purge_line_ids": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"menu_id": self.menu.id,
|
||||
},
|
||||
)
|
||||
]
|
||||
}
|
||||
)
|
||||
wizard.purge_all()
|
||||
self.assertFalse(
|
||||
env["ir.ui.menu"].search(
|
||||
[
|
||||
("name", "=", "database_cleanup_test"),
|
||||
]
|
||||
)
|
||||
)
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
# Copyright 2021 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo.tests.common import tagged
|
||||
|
||||
from .common import Common, environment
|
||||
|
||||
|
||||
# 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().setUp()
|
||||
with environment() as env:
|
||||
# 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 = env["ir.model"].create(self.model_values)
|
||||
env.cr.execute(
|
||||
"insert into ir_attachment (name, res_model, res_id, type) values "
|
||||
"('test attachment', %s, 42, 'binary')",
|
||||
[self.model_name],
|
||||
)
|
||||
env.registry.models.pop(self.model_name)
|
||||
|
||||
def test_empty_model(self):
|
||||
with environment() as env:
|
||||
wizard = env["cleanup.purge.wizard.model"].create({})
|
||||
wizard.purge_all()
|
||||
# must be removed by the wizard
|
||||
self.assertFalse(
|
||||
env["ir.model"].search(
|
||||
[
|
||||
("model", "=", self.model_name),
|
||||
]
|
||||
)
|
||||
)
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
# Copyright 2021 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo.tests.common import tagged
|
||||
|
||||
from .common import Common, environment
|
||||
|
||||
|
||||
# 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().setUp()
|
||||
with environment() as env:
|
||||
# create a nonexistent module
|
||||
self.module = env["ir.module.module"].create(
|
||||
{
|
||||
"name": "database_cleanup_test",
|
||||
"state": "to upgrade",
|
||||
}
|
||||
)
|
||||
|
||||
def test_remove_to_upgrade_module(self):
|
||||
with environment() as env:
|
||||
wizard = env["cleanup.purge.wizard.module"].create({})
|
||||
module_names = wizard.purge_line_ids.filtered(
|
||||
lambda x: not x.purged
|
||||
).mapped("name")
|
||||
self.assertTrue("database_cleanup_test" in module_names)
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
# Copyright 2021 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo.tests.common import tagged
|
||||
|
||||
from .common import Common, environment
|
||||
|
||||
|
||||
# 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().setUp()
|
||||
with environment() as env:
|
||||
# Create one property for tests
|
||||
self.partner_name_field_id = env["ir.model.fields"].search(
|
||||
[("name", "=", "name"), ("model_id.model", "=", "res.partner")], limit=1
|
||||
)
|
||||
|
||||
def test_property_to_not_removed(self):
|
||||
with environment() as env:
|
||||
self.property = env["ir.property"].create(
|
||||
{
|
||||
"fields_id": self.partner_name_field_id.id,
|
||||
"type": "char",
|
||||
"value_text": "My default partner name",
|
||||
"res_id": False,
|
||||
}
|
||||
)
|
||||
wizard = env["cleanup.purge.wizard.property"].create({})
|
||||
wizard.purge_all()
|
||||
self.assertTrue(self.property.exists())
|
||||
|
||||
def test_property_no_value(self):
|
||||
with environment() as env:
|
||||
self.property = env["ir.property"].create(
|
||||
{
|
||||
"fields_id": self.partner_name_field_id.id,
|
||||
"type": "char",
|
||||
"value_text": False,
|
||||
"res_id": False,
|
||||
}
|
||||
)
|
||||
wizard = env["cleanup.purge.wizard.property"].create({})
|
||||
wizard.purge_all()
|
||||
self.assertFalse(self.property.exists())
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
# Copyright 2021 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from psycopg2 import ProgrammingError
|
||||
|
||||
from odoo.tests.common import tagged
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
from .common import Common, environment
|
||||
|
||||
|
||||
# Use post_install to get all models loaded more info: odoo/odoo#13458
|
||||
@tagged("post_install", "-at_install")
|
||||
class TestCleanupPurgeLineTable(Common):
|
||||
def test_empty_table(self):
|
||||
with environment() as env:
|
||||
# create an orphaned table
|
||||
env.cr.execute("create table database_cleanup_test (test int)")
|
||||
wizard = env["cleanup.purge.wizard.table"].create({})
|
||||
wizard.purge_all()
|
||||
with self.assertRaises(ProgrammingError):
|
||||
with env.registry.cursor() as cr:
|
||||
with mute_logger("odoo.sql_db"):
|
||||
cr.execute("select * from database_cleanup_test")
|
||||
Loading…
Add table
Add a link
Reference in a new issue