43 lines
1.9 KiB
Python
43 lines
1.9 KiB
Python
from odoo.exceptions import UserError
|
|
from odoo.tests.common import TransactionCase, tagged
|
|
|
|
|
|
@tagged('post_install', '-at_install')
|
|
class TestSafetyGuard(TransactionCase):
|
|
"""Verify the safety guard blocks Enterprise uninstall when migration hasn't run."""
|
|
|
|
def test_uninstall_not_blocked_when_migration_completed(self):
|
|
"""If the per-module migration flag is set, uninstall is allowed.
|
|
|
|
Skip if account_accountant isn't installed -- otherwise the guard's
|
|
`if not installed: continue` short-circuit would make this test pass
|
|
vacuously without exercising the flag-check branch.
|
|
"""
|
|
Module = self.env['ir.module.module'].sudo()
|
|
if not Module.search_count([
|
|
('name', '=', 'account_accountant'),
|
|
('state', '=', 'installed'),
|
|
]):
|
|
self.skipTest("account_accountant not installed in this DB")
|
|
self.env['ir.config_parameter'].sudo().set_param(
|
|
'fusion_accounting.migration.account_accountant.completed', 'True'
|
|
)
|
|
guard = Module._fusion_check_uninstall_guard(['account_accountant'])
|
|
self.assertTrue(guard, "Guard should pass when migration flag is set")
|
|
|
|
def test_uninstall_blocked_when_migration_pending(self):
|
|
"""If account_accountant is installed and migration not run, raise."""
|
|
self.env['ir.config_parameter'].sudo().set_param(
|
|
'fusion_accounting.migration.account_accountant.completed', 'False'
|
|
)
|
|
Module = self.env['ir.module.module'].sudo()
|
|
installed = Module.search_count([
|
|
('name', '=', 'account_accountant'),
|
|
('state', '=', 'installed'),
|
|
])
|
|
if not installed:
|
|
self.skipTest("account_accountant not installed in this DB")
|
|
with self.assertRaises(UserError) as ctx:
|
|
Module._fusion_check_uninstall_guard(['account_accountant'])
|
|
self.assertIn('migration', str(ctx.exception).lower())
|