Files
design-themes/test_themes/tests/test_theme_upgrade.py
T
qsm-odoo 9eecd12db1 [IMP] *: remove useless utf-8 declaration
Part-of: odoo/design-themes#919
Related: odoo/odoo#180736
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
2024-09-21 16:34:53 +00:00

60 lines
2.4 KiB
Python

from odoo.addons.website.tools import MockRequest
from odoo.tests import standalone
@standalone('theme_upgrade', 'website_standalone')
def test_01_theme_upgrade_post_copy(env):
""" This test ensures the theme `_post_copy()` method is only called when a
theme is installed for the first time on a website and not when the theme is
updated on that website.
"""
# 1. Setup
website = env['website'].search([], limit=1)
Website = env['website'].with_context(website_id=website.id)
# Get rid of as many website as we can, any website will drastically slows
# down the test as when updating Theme Nano, it will update Theme Common
# which is applied on every site having a theme. It will then update all
# those websites.
Website.get_test_themes_websites().unlink()
for w in Website.search([('theme_id', '!=', False), ('id', '!=', website.id)]):
try:
w.unlink()
except Exception:
pass
ofs_specific_view = Website.viewref('website.option_footer_scrolltop')
fls_specific_view = Website.viewref('portal.footer_language_selector')
theme_nano_module = env.ref('base.module_theme_nano')
def _simulate_user_manual_change():
# Change some website options that will be changed by Theme Nano
ofs_specific_view.active = False
fls_specific_view.active = True
# 2. Simulate some website option change made by the user
_simulate_user_manual_change()
# 3. Simulate user choosing a new theme for his website
with MockRequest(env, website=website):
theme_nano_module.with_context(website_id=website.id).button_choose_theme()
assert Website.viewref('website.option_footer_scrolltop').active is True, \
"Theme Nano custo should be applied"
assert Website.viewref('portal.footer_language_selector').active is False, \
"Theme Nano custo should be applied (2)"
# 4. Simulate some website option change made by the user, again
_simulate_user_manual_change()
# 5. Upgrade Theme Nano
theme_nano_module.button_immediate_upgrade()
env.reset() # clear the set of environments
env = env() # get an environment that refers to the new registry
assert Website.viewref('website.option_footer_scrolltop').active is False, \
"Theme Nano custo should NOT be applied"
assert Website.viewref('portal.footer_language_selector').active is True, \
"Theme Nano custo should NOT be applied (2)"