diff options
| author | Christophe Simonis <chs@odoo.com> | 2019-10-09 02:08:17 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2019-10-09 02:08:17 +0200 |
| commit | d74b4518052066446e2a1975a91ce53c745ca75a (patch) | |
| tree | c08180f88a512d15e37fbec628931f02b3825f65 /addons/website_theme_install/tests | |
| parent | ec162dd0cb5622ab6e56db1a63dab5f531a96f4a (diff) | |
| parent | f4105eb9c7010f8693e5d2fd20c0bd9d9cc2e483 (diff) | |
[MERGE] forward port branch 13.0 up to f4105eb9c70
Diffstat (limited to 'addons/website_theme_install/tests')
| -rw-r--r-- | addons/website_theme_install/tests/test_views.py | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/addons/website_theme_install/tests/test_views.py b/addons/website_theme_install/tests/test_views.py index a81fd1da4e8..743482ec289 100644 --- a/addons/website_theme_install/tests/test_views.py +++ b/addons/website_theme_install/tests/test_views.py @@ -1,7 +1,57 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo.tests import HttpCase +from odoo.tests import HttpCase, tagged, TransactionCase + + +@tagged('post_install', '-at_install') +class TestViews(TransactionCase): + def test_inherit_specific(self): + View = self.env['ir.ui.view'] + Website = self.env['website'] + + website_1 = Website.create({'name': 'Website 1'}) + + # 1. Simulate COW structure + main_view = View.create({ + 'name': 'Test Main View', + 'type': 'qweb', + 'arch': '<body>Arch is not relevant for this test</body>', + 'key': '_test.main_view', + }).with_context(load_all_views=True) + # Trigger COW + main_view.with_context(website_id=website_1.id).arch = '<body>specific</body>' + + # 2. Simulate a theme install with a child view of `main_view` + test_theme_module = self.env['ir.module.module'].create({'name': 'test_theme'}) + self.env['ir.model.data'].create({ + 'module': 'base', + 'name': 'module_test_theme_module', + 'model': 'ir.module.module', + 'res_id': test_theme_module.id, + }) + theme_view = self.env['theme.ir.ui.view'].with_context(install_filename='/testviews').create({ + 'name': 'Test Child View', + 'mode': 'extension', + 'inherit_id': 'ir.ui.view,%s' % main_view.id, + 'arch': '<xpath expr="//body" position="replace"><span>C</span></xpath>', + 'key': 'test_theme.test_child_view', + }) + self.env['ir.model.data'].create({ + 'module': 'test_theme', + 'name': 'products', + 'model': 'theme.ir.ui.view', + 'res_id': theme_view.id, + }) + test_theme_module.with_context(load_all_views=True)._theme_load(website_1) + + # 3. Ensure everything went correctly + main_views = View.search([('key', '=', '_test.main_view')]) + self.assertEqual(len(main_views), 2, "View should have been COWd when writing on its arch in a website context") + specific_main_view = main_views.filtered(lambda v: v.website_id == website_1) + specific_main_view_children = specific_main_view.inherit_children_ids + self.assertEqual(specific_main_view_children.name, 'Test Child View', "Ensure theme.ir.ui.view has been loaded as an ir.ui.view into the website..") + self.assertEqual(specific_main_view_children.website_id, website_1, "..and the website is the correct one.") class Crawler(HttpCase): |
