Skip to content

Commit 3b35cf4

Browse files
committed
[FIX] test_themes: mock RPC calls in standalone configurator tests
The standalone theme configurator test (test_02_theme_default_generate_primary_templates) failed locally because `configurator_apply()` attempts to perform real HTTP requests through `_website_api_rpc()` and `_OLG_api_rpc()`. Standalone tests run without network access by design, so these calls must be mocked to ensure deterministic behavior. This commit patches both RPC methods during the test execution to return minimal, valid fake payloads. IAP itself does not need to be tested here: its behavior and endpoints are already covered indirectly by the configurator_flow web tour test in test_website_modules, which exercises the full configurator flow end-to-end with real network access. runbot-231270 closes #1153 X-original-commit: 9c73a79 Signed-off-by: Quentin Smetz (qsm) <[email protected]>
1 parent a21ef38 commit 3b35cf4

File tree

1 file changed

+40
-23
lines changed

1 file changed

+40
-23
lines changed
Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Part of Odoo. See LICENSE file for full copyright and licensing details.
22

3-
from odoo.addons.website.tools import MockRequest
3+
from unittest.mock import patch
44
from odoo.tests import standalone
55

66

@@ -22,8 +22,22 @@ def test_01_theme_install_generate_primary_templates(env):
2222
env['ir.ui.view'].with_context(_force_unlink=True).search([('key', '=', 'website.configurator_s_cover')]).unlink()
2323
theme_buzzy.button_immediate_install()
2424

25+
2526
@standalone('website_standalone')
2627
def test_02_theme_default_generate_primary_templates(env):
28+
29+
def fake_website_api(self, path, payload):
30+
# Only the configurator custom_resources endpoint is used here
31+
assert path.startswith("/api/website/2/configurator/custom_resources")
32+
return {'images': {}}
33+
34+
def fake_olg_api(self, path, payload):
35+
# Placeholder generator used by configurator
36+
assert path == "/api/olg/1/generate_placeholder"
37+
placeholders = payload.get("placeholders", [])
38+
mapping = {key: key for key in placeholders}
39+
return mapping
40+
2741
# Verify that theme default's configurator templates are created
2842
# on website update.
2943
theme_default = env.ref('base.module_theme_default')
@@ -33,25 +47,28 @@ def test_02_theme_default_generate_primary_templates(env):
3347
theme_default.button_immediate_uninstall()
3448
env['ir.ui.view'].with_context(_force_unlink=True).search([('key', 'like', 'website.configurator_')]).unlink()
3549

36-
if website_module.state == 'installed':
37-
website_module.button_immediate_upgrade()
38-
else:
39-
website_module.button_immediate_install()
40-
41-
template_keys = env['ir.ui.view'].search([('key', 'like', 'website.configurator')]).mapped('key')
42-
manifest = env['ir.module.module'].get_module_info('theme_default')
43-
snippets_per_page = manifest.get('configurator_snippets')
44-
for page in snippets_per_page:
45-
for snippet in snippets_per_page[page]:
46-
template_key = f'website.configurator_{page}_{snippet}'
47-
assert template_key in template_keys, f"{template_key} should exist"
48-
49-
env['website'].with_context(website_id=1).configurator_apply(
50-
selected_features=[1, 2, 3, 4],
51-
industry_id=2836,
52-
industry_name='private university',
53-
selected_palette='default-15',
54-
theme_name='theme_bewise',
55-
website_purpose='get_leads',
56-
website_type='business',
57-
)
50+
with patch("odoo.addons.website.models.website.Website._website_api_rpc", autospec=True, side_effect=fake_website_api), \
51+
patch("odoo.addons.website.models.website.Website._OLG_api_rpc", autospec=True, side_effect=fake_olg_api):
52+
53+
if website_module.state == 'installed':
54+
website_module.button_immediate_upgrade()
55+
else:
56+
website_module.button_immediate_install()
57+
58+
template_keys = env['ir.ui.view'].search([('key', 'like', 'website.configurator')]).mapped('key')
59+
manifest = env['ir.module.module'].get_module_info('theme_default')
60+
snippets_per_page = manifest.get('configurator_snippets')
61+
for page in snippets_per_page:
62+
for snippet in snippets_per_page[page]:
63+
template_key = f'website.configurator_{page}_{snippet}'
64+
assert template_key in template_keys, f"{template_key} should exist"
65+
66+
env['website'].with_context(website_id=1).configurator_apply(
67+
selected_features=[1, 2, 3, 4],
68+
industry_id=2836,
69+
industry_name='private university',
70+
selected_palette='default-15',
71+
theme_name='theme_bewise',
72+
website_purpose='get_leads',
73+
website_type='business',
74+
)

0 commit comments

Comments
 (0)