Skip to content

Commit

Permalink
[ADD] util.remove_view: unittest
Browse files Browse the repository at this point in the history
Testcases for handling t-call of the removed view
  • Loading branch information
kmod-odoo committed Oct 14, 2024
1 parent eb1b7ed commit 6afb5a5
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/base/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1580,3 +1580,65 @@ 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)

0 comments on commit 6afb5a5

Please sign in to comment.