summaryrefslogtreecommitdiff
path: root/addons/test_website
diff options
context:
space:
mode:
authorRomain Derie <rde@odoo.com>2019-02-20 19:05:28 +0000
committerRomain Derie <rde@odoo.com>2019-03-05 11:04:52 +0000
commit5a81d88837c30365c9f06843715dfc9cbb2397f3 (patch)
tree2c241c4e5062558a6cf22d93e746156782a7fdc7 /addons/test_website
parentdfb5e3791f21b911f0d738caa4bb75eee4664bc5 (diff)
[FIX] website: delete cow view on module update
Before this commit, when a view was removed during a module update (eg: the record was deleted from the file), its COW views would not be deleted. This could lead to unwanted behaviors including tracebacks(1). This commit is somehow related/an extension of b5fe23055d that handle COW view write during module update and 2e32cc5aa3 that remove COW views during module uninstall. task-1931683 Note: Some existing tests had to be run post install (1) A view doing a t-call is COW'd, then that view and its t-called view are removed. If the cow view is not removed, the t-call will crash (see tests in this commit for detailed case). closes odoo/odoo#31295 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
Diffstat (limited to 'addons/test_website')
-rw-r--r--addons/test_website/data/test_website_data.xml8
-rw-r--r--addons/test_website/tests/__init__.py1
-rw-r--r--addons/test_website/tests/test_views_during_module_operation.py72
3 files changed, 81 insertions, 0 deletions
diff --git a/addons/test_website/data/test_website_data.xml b/addons/test_website/data/test_website_data.xml
index df827d542a3..0d829aaab84 100644
--- a/addons/test_website/data/test_website_data.xml
+++ b/addons/test_website/data/test_website_data.xml
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
+
+ <!-- RECORDS FOR RESET VIEWS TESTS -->
<record id="test_view" model="ir.ui.view">
<field name="name">Test View</field>
<field name="type">qweb</field>
@@ -50,5 +52,11 @@
<p>placeholder</p>
</xpath>
</template>
+
+ <!-- RECORDS FOR MODULE OPERATION TESTS -->
+ <template id="update_module_base_view">
+ <div>I am a base view</div>
+ </template>
+
</data>
</odoo>
diff --git a/addons/test_website/tests/__init__.py b/addons/test_website/tests/__init__.py
index 4c32d5f1959..57d8fcd0c25 100644
--- a/addons/test_website/tests/__init__.py
+++ b/addons/test_website/tests/__init__.py
@@ -2,3 +2,4 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import test_reset_views
+from . import test_views_during_module_operation
diff --git a/addons/test_website/tests/test_views_during_module_operation.py b/addons/test_website/tests/test_views_during_module_operation.py
new file mode 100644
index 00000000000..fceb71b5dc4
--- /dev/null
+++ b/addons/test_website/tests/test_views_during_module_operation.py
@@ -0,0 +1,72 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo.tests import TransactionCase, tagged
+
+
+@tagged('-at_install', 'post_install')
+class TestViewsDuringModuleOperation(TransactionCase):
+ def test_01_cow_views_unlink_on_module_update(self):
+ """ Ensure COW views are correctly removed during module update.
+ Not removing the view could lead to traceback:
+ - Having a view A
+ - Having a view B that inherits from a view C
+ - View B t-call view A
+ - COW view B
+ - Delete view A and B from module datas and update it
+ - Rendering view C will crash since it will render child view B that
+ t-call unexisting view A
+ """
+
+ View = self.env['ir.ui.view']
+ Imd = self.env['ir.model.data']
+
+ update_module_base_view = self.env.ref('test_website.update_module_base_view')
+ update_module_view_to_be_t_called = View.create({
+ 'name': 'View to be t-called',
+ 'type': 'qweb',
+ 'arch': '<div>I will be t-called</div>',
+ 'key': 'test_website.update_module_view_to_be_t_called',
+ })
+ update_module_child_view = View.create({
+ 'name': 'Child View',
+ 'mode': 'extension',
+ 'inherit_id': update_module_base_view.id,
+ 'arch': '''
+ <div position="inside">
+ <t t-call="test_website.update_module_view_to_be_t_called"/>
+ </div>
+ ''',
+ 'key': 'test_website.update_module_child_view',
+ })
+
+ # Create IMD so when updating the module the views will be removed (not found in file)
+ Imd.create({
+ 'module': 'test_website',
+ 'name': 'update_module_view_to_be_t_called',
+ 'model': 'ir.ui.view',
+ 'res_id': update_module_view_to_be_t_called.id,
+ })
+ Imd.create({
+ 'module': 'test_website',
+ 'name': 'update_module_child_view',
+ 'model': 'ir.ui.view',
+ 'res_id': update_module_child_view.id,
+ })
+
+ # Trigger COW on child view
+ update_module_child_view.with_context(website_id=1).write({'name': 'Child View (W1)'})
+
+ # Ensure views are correctly setup
+ self.assertEquals(View.search_count([('type', '=', 'qweb'), ('key', '=', update_module_child_view.key)]), 2)
+ self.assertTrue(self.env.ref(update_module_view_to_be_t_called.key))
+ self.assertTrue(self.env.ref(update_module_base_view.key))
+
+ # Uninstall module
+ test_website_module = self.env['ir.module.module'].search([('name', '=', 'test_website')])
+ test_website_module.button_immediate_upgrade()
+
+ # Ensure generic views got removed
+ self.assertFalse(self.env.ref('test_website.update_module_view_to_be_t_called', raise_if_not_found=False))
+ # Ensure specific COW views got removed
+ self.assertEquals(View.search_count([('type', '=', 'qweb'), ('key', '=', 'test_website.update_module_child_view')]), 0)