[IMP] website, test_website, website_sale: allow to find partial url

Until now, if you search for /shop/Desk for a new link, you will not
have any result.
Now we search that it match *shop*desk* so /shop/custom-desk-12 will
match.

closes odoo/odoo#114357

X-original-commit: 84a407e744b7bacab43a0213ab52002a49c5d623
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
Signed-off-by: Jérémy Kersten <jke@odoo.com>
This commit is contained in:
Jeremy Kersten
2023-03-07 02:00:03 +01:00
committed by Romain Derie
parent 08776c1d39
commit 2f992e6cd1
4 changed files with 15 additions and 6 deletions
+1 -1
View File
@@ -131,7 +131,7 @@ class WebsiteTest(Home):
return 'Basic Controller Content'
# Test Redirects
@http.route(['/test_website/country/<model("res.country"):country>'], type='http', auth="public", website=True, sitemap=False)
@http.route(['/test_website/country/<model("res.country"):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})
@@ -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'))
+3 -1
View File
@@ -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
+1 -1
View File
@@ -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.")