From 23df9e58afea1e731c4d172914ed9571dba7bb17 Mon Sep 17 00:00:00 2001 From: kmod-odoo Date: Wed, 14 Aug 2024 10:08:22 +0000 Subject: [PATCH] [ADD] util: unittest Testcases for remove_view and rename_xmlid --- src/base/tests/test_util.py | 98 +++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/src/base/tests/test_util.py b/src/base/tests/test_util.py index 1e94a168..f0cc046e 100644 --- a/src/base/tests/test_util.py +++ b/src/base/tests/test_util.py @@ -1584,3 +1584,101 @@ def test_m2m_no_conflict(self): util.replace_record_references_batch(cr, mapping, "res.groups") util.invalidate(u2) self.assertEqual(u2.groups_id.ids, [g3.id]) + + +class TestRemoveView(UnitTestCase): + def test_remove_view(self): + test_view_1 = self.env["ir.ui.view"].create( + { + "name": "test_view_1", + "type": "qweb", + "key": "base.test_view_1", + "arch": """ + +
Test View 1 Content
+
+ """, + } + ) + self.env["ir.model.data"].create( + {"name": "test_view_1", "module": "base", "model": "ir.ui.view", "res_id": test_view_1.id} + ) + test_view_2 = self.env["ir.ui.view"].create( + { + "name": "test_view_2", + "type": "qweb", + "key": "base.test_view_2", + "arch": """ + + +
Test View 2 Content
+
+ """, + } + ) + test_view_3 = self.env["ir.ui.view"].create( + { + "name": "test_view_3", + "type": "qweb", + "key": "base.test_view_3", + "arch": """ + + + + + """, + } + ) + self.env["ir.model.data"].create( + {"name": "test_view_3", "module": "base", "model": "ir.ui.view", "res_id": test_view_3.id} + ) + + # call by xml_id + util.remove_view(self.env.cr, xml_id="base.test_view_1") + util.invalidate(test_view_2) + util.invalidate(test_view_3) + self.assertFalse(test_view_1.exists()) + self.assertNotIn('t-call="base.test_view_1"', test_view_2.arch_db) + self.assertNotIn('t-call="base.test_view_1"', test_view_3.arch_db) + + # call by view_id + util.remove_view(self.env.cr, view_id=test_view_2.id) + util.invalidate(test_view_3) + self.assertFalse(test_view_2.exists()) + self.assertNotIn('t-call="base.test_view_2"', test_view_3.arch_db) + + +class TestRenameXMLID(UnitTestCase): + def test_rename_xmlid(self): + test_view_1 = self.env["ir.ui.view"].create( + { + "name": "test_view_1", + "type": "qweb", + "key": "base.test_view_1", + "arch": """ + +
Test View 1 Content
+
+ """, + } + ) + self.env["ir.model.data"].create( + {"name": "test_view_1", "module": "base", "model": "ir.ui.view", "res_id": test_view_1.id} + ) + test_view_2 = self.env["ir.ui.view"].create( + { + "name": "test_view_2", + "type": "qweb", + "key": "base.test_view_2", + "arch": """ + + +
Test View 2 Content
+
+ """, + } + ) + util.rename_xmlid(self.env.cr, "base.test_view_1", "base.rename_view") + util.invalidate(test_view_2) + self.assertIn('t-call="base.rename_view"', test_view_2.arch_db) + self.assertIn('t-name="base.rename_view"', test_view_1.arch_db)