From ebfa84d8e387ee9a0ebcf70a190f19391386aa62 Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Thu, 1 Dec 2022 14:17:47 +0000 Subject: [PATCH] [FIX] test_website: add test for duplicate sitemap URL fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See previous commit, it fixes duplicate URLs from sitemap. It appears when there is a custom defined sitemap method on a route defined with multiple endpoints. There will be as many duplicates as there is endpoint. closes odoo/odoo#108670 X-original-commit: 9ca24c3020d98dcd6e9266ae76adb13afbf1bd40 Signed-off-by: Romain Derie (rde) Signed-off-by: Jérémy Kersten --- addons/test_website/controllers/main.py | 12 ++++++++++++ addons/test_website/tests/test_controller_args.py | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/addons/test_website/controllers/main.py b/addons/test_website/controllers/main.py index 22981a4a658..d10988d9be7 100644 --- a/addons/test_website/controllers/main.py +++ b/addons/test_website/controllers/main.py @@ -142,3 +142,15 @@ class WebsiteTest(Home): @http.route(['/test_website/test_redirect_view_qs'], type='http', auth="public", website=True, sitemap=False) def test_redirect_view_qs(self, **kw): return request.render('test_website.test_redirect_view_qs') + + # Test Sitemap + def sitemap_test(env, rule, qs): + if not qs or qs.lower() in '/test_website_sitemap': + yield {'loc': '/test_website_sitemap'} + + @http.route([ + '/test_website_sitemap', + '/test_website_sitemap/something/', + ], type='http', auth='public', website=True, sitemap=sitemap_test) + def test_sitemap(self, rec=None, **kwargs): + return request.make_response('Sitemap Testing Page') diff --git a/addons/test_website/tests/test_controller_args.py b/addons/test_website/tests/test_controller_args.py index 51056839374..28420b8e0d7 100644 --- a/addons/test_website/tests/test_controller_args.py +++ b/addons/test_website/tests/test_controller_args.py @@ -35,3 +35,12 @@ class TestWebsiteControllerArgs(odoo.tests.HttpCase): 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') +class TestWebsiteControllers(odoo.tests.TransactionCase): + + def test_01_sitemap(self): + 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")