diff --git a/addons/test_website/controllers/main.py b/addons/test_website/controllers/main.py index d10988d9be7..b683eee4c52 100644 --- a/addons/test_website/controllers/main.py +++ b/addons/test_website/controllers/main.py @@ -131,7 +131,7 @@ class WebsiteTest(Home): return 'Basic Controller Content' # Test Redirects - @http.route(['/test_website/country/'], type='http', auth="public", website=True, sitemap=False) + @http.route(['/test_website/country/'], type='http', auth="public", website=True, sitemap=True) def test_model_converter_country(self, country, **kw): return request.render('test_website.test_redirect_view', {'country': country}) diff --git a/addons/test_website/tests/test_controller_args.py b/addons/test_website/tests/test_controller_args.py index 28420b8e0d7..4aa9372bf73 100644 --- a/addons/test_website/tests/test_controller_args.py +++ b/addons/test_website/tests/test_controller_args.py @@ -1,6 +1,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. import odoo.tests from odoo.tools import mute_logger +from unittest.mock import patch @odoo.tests.common.tagged('post_install', '-at_install') @@ -32,9 +33,10 @@ class TestWebsiteControllerArgs(odoo.tests.HttpCase): self.assertEqual(req.status_code, 200) self.assertEqual(req.json(), {'a': 'valueA', 'kw': {'b': 'valueB'}}) - req = self.url_open('/test_website/country/whatever-999999') - self.assertEqual(req.status_code, 404, - "Model converter record does not exist, return a 404.") + with patch.object(self.registry['ir.http'], '_get_error_html', lambda e, code, v: (code, '')): + req = self.url_open('/test_website/country/whatever-999999') + self.assertEqual(req.status_code, 404, + "Model converter record does not exist, return a 404.") @odoo.tests.common.tagged('post_install', '-at_install') @@ -44,3 +46,8 @@ class TestWebsiteControllers(odoo.tests.TransactionCase): website = self.env['website'].browse(1) locs = website.with_user(website.user_id)._enumerate_pages(query_string='test_website_sitemap') self.assertEqual(len(list(locs)), 1, "The same URL should only be shown once") + + def test_02_search_controller(self): + website = self.env['website'].browse(1) + res = website._enumerate_pages(query_string="/test_website/country/elgium") + self.assertIn('/test_website/country/belgium', next(res).get('loc')) diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 1268c46ad78..4c65e76083c 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -1,6 +1,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. import base64 +import fnmatch import hashlib import inspect import json @@ -1160,7 +1161,8 @@ class Website(models.Model): for value in values: domain_part, url = rule.build(value, append_unknown=False) - if not query_string or query_string.lower() in url.lower(): + pattern = query_string and '*%s*' % "*".join(query_string.split('/')) + if not query_string or fnmatch.fnmatch(url.lower(), pattern): page = {'loc': url} if url in url_set: continue diff --git a/addons/website_sale/tests/test_sitemap.py b/addons/website_sale/tests/test_sitemap.py index 2baf167ea3d..b540bdb16eb 100644 --- a/addons/website_sale/tests/test_sitemap.py +++ b/addons/website_sale/tests/test_sitemap.py @@ -22,4 +22,4 @@ class TestSitemap(HttpCase): def test_01_shop_route_sitemap(self): resp = self.url_open('/sitemap.xml') level2_url = '/shop/category/level-0-level-1-level-2-%s' % self.cats[2].id - self.assertTrue(level2_url in resp.text, "Category entry in sitemap should be prefixed by its parent hierarchy.") + self.assertIn(level2_url, resp.text, "Category entry in sitemap should be prefixed by its parent hierarchy.")