Skip to content

Commit

Permalink
[ADD] util: unittest
Browse files Browse the repository at this point in the history
Testcases for remove_view and rename_xmlid
  • Loading branch information
kmod-odoo committed Dec 2, 2024
1 parent edfcdc5 commit 23df9e5
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions src/base/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": """
<t t-name="base.test_view_1">
<div>Test View 1 Content</div>
</t>
""",
}
)
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": """
<t t-name="base.test_view_2">
<t t-call="base.test_view_1"/>
<div>Test View 2 Content</div>
</t>
""",
}
)
test_view_3 = self.env["ir.ui.view"].create(
{
"name": "test_view_3",
"type": "qweb",
"key": "base.test_view_3",
"arch": """
<t t-name="base.test_view_3">
<t t-call="base.test_view_1"/>
<t t-call="base.test_view_2"/>
</t>
""",
}
)
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": """
<t t-name="base.test_view_1">
<div>Test View 1 Content</div>
</t>
""",
}
)
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": """
<t t-name="base.test_view_2">
<t t-call="base.test_view_1"/>
<div>Test View 2 Content</div>
</t>
""",
}
)
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)

0 comments on commit 23df9e5

Please sign in to comment.