Files
odoo_source/addons/website/tests/test_theme.py
T
Romain Derie fa7399c4e6 [FIX] theme_*: enable footer/header template correctly
Some theme are enabling an header template. When doing so, they also disable
the default header template.
But this is not enough, as the user could have changed that template and it is
not the default one anymore.

Then, updating that theme (UX, CLI, Migration) will raise a traceback.

Step to reproduce:
  - Create a website and install theme avantgarde
  - Enter edit mode and select Magazine header template
  At that point, update the theme, either:
  - Through the UI, on theme switch screen, click on Update
  - Through CLI, just run a `-u theme_avantgarde`
-> A traceback will be raised about an xpath error, as both the magazine header
   template and the hamburger header template are active at the same time. Only
   one template is supposed to be activated.

The issue also impact migration, as migrated website can't be accessed due to
the xpath error on rendering.

Theme being impacted (at least): Avantgarde, Graphene & Nano

Note that when installing one of those themes for the first time on a website,
the error won't occur as `_reset_default_config()` will be called through
`_theme_remove()`.

Note that this fix will ensure the correct template is set (and all others are
disabled), but the scss variable won't be correctly set (as it would be if that
template change was done through the right panel).
This is not that much of a problem (considering what it solves), any later
change from the user through the right panel will solve that mismatch.

Fixes https://github.com/odoo/upgrade/pull/3048
task-2593407
opw-2680866
opw-2685951
opw-2685124
opw-2679040

X-original-commit: f18cd32a936829d8a059db0d259189503ee5317f
Part-of: odoo/odoo#81953
2021-12-28 11:47:04 +00:00

41 lines
1.6 KiB
Python

# coding: utf-8
from odoo.tests import common
class TestTheme(common.TransactionCase):
def test_theme_remove_working(self):
""" This test ensure theme can be removed.
Theme removal is also the first step during theme installation.
"""
theme_common_module = self.env['ir.module.module'].search([('name', '=', 'theme_default')])
website = self.env['website'].get_current_website()
website.theme_id = theme_common_module.id
self.env['ir.module.module']._theme_remove(website)
def test_02_disable_view(self):
"""This test ensure only one template header can be active at a time."""
website_id = self.env['website'].browse(1)
ThemeUtils = self.env['theme.utils'].with_context(website_id=website_id.id)
ThemeUtils._reset_default_config()
def _get_header_template_key():
return self.env['ir.ui.view'].search([
('key', 'in', ThemeUtils._header_templates),
('website_id', '=', website_id.id),
]).key
self.assertEqual(_get_header_template_key(), 'website.template_header_default',
"Only the default template should be active.")
key = 'website.template_header_magazine'
ThemeUtils.enable_view(key)
self.assertEqual(_get_header_template_key(), key,
"Only one template can be active at a time.")
key = 'website.template_header_hamburger'
ThemeUtils.enable_view(key)
self.assertEqual(_get_header_template_key(), key,
"Ensuring it works also for non default template.")