diff --git a/addons/test_website/tests/test_redirect.py b/addons/test_website/tests/test_redirect.py index 39840f9184d..1fd67e59ffa 100644 --- a/addons/test_website/tests/test_redirect.py +++ b/addons/test_website/tests/test_redirect.py @@ -7,6 +7,7 @@ from odoo.tools import mute_logger from odoo.addons.http_routing.models.ir_http import slug from unittest.mock import patch +from urllib.parse import urlparse @tagged('-at_install', 'post_install') @@ -81,7 +82,7 @@ class TestRedirect(HttpCase): # published resp = self.url_open(f"/test_website/200/name-{rec_published.id}", allow_redirects=False) self.assertEqual(resp.status_code, 308) - self.assertEqual(resp.headers.get('Location'), f"{self.base_url()}/test_website/308/name-{rec_published.id}") + self.assertEqual(urlparse(resp.headers.get('Location', '')).path, f"/test_website/308/name-{rec_published.id}") resp = self.url_open(f"/test_website/308/name-{rec_published.id}", allow_redirects=False) self.assertEqual(resp.status_code, 200) @@ -92,7 +93,7 @@ class TestRedirect(HttpCase): resp = self.url_open(f"/test_website/308/xx-{rec_published.id}", allow_redirects=False) self.assertEqual(resp.status_code, 301) - self.assertEqual(resp.headers.get('Location'), f"{self.base_url()}/test_website/308/name-{rec_published.id}") + self.assertEqual(urlparse(resp.headers.get('Location'), '').path, f"/test_website/308/name-{rec_published.id}") resp = self.url_open(f"/test_website/200/xx-{rec_published.id}", allow_redirects=True) self.assertEqual(resp.status_code, 200) diff --git a/addons/website/tests/test_attachment.py b/addons/website/tests/test_attachment.py index 17359eb71c7..90d6844fa73 100644 --- a/addons/website/tests/test_attachment.py +++ b/addons/website/tests/test_attachment.py @@ -1,3 +1,5 @@ +from urllib.parse import urlparse + import odoo.tests from odoo.tests.common import HOST from odoo.tools import config @@ -45,7 +47,7 @@ class TestWebsiteAttachment(odoo.tests.HttpCase): req = self.opener.get(base + '/web/image/test.an_image_redirect_301', allow_redirects=False) self.assertEqual(req.status_code, 301) - self.assertEqual(req.headers['Location'], base + '/web/image/test.an_image_url') + self.assertEqual(urlparse(req.headers.get('Location', '')).path, '/web/image/test.an_image_url') req = self.opener.get(base + '/web/image/test.an_image_redirect_301', allow_redirects=True) self.assertEqual(req.status_code, 200) diff --git a/addons/website/tests/test_lang_url.py b/addons/website/tests/test_lang_url.py index f655880fe99..b4a49b1db20 100644 --- a/addons/website/tests/test_lang_url.py +++ b/addons/website/tests/test_lang_url.py @@ -3,11 +3,11 @@ import json import lxml.html -import odoo +from urllib.parse import urlparse + from odoo.addons.http_routing.models.ir_http import url_lang from odoo.addons.website.tools import MockRequest from odoo.tests import HttpCase, tagged -from odoo.tests.common import HOST @tagged('-at_install', 'post_install') @@ -119,14 +119,15 @@ class TestControllerRedirect(TestLangUrl): """ def assertUrlRedirect(url, expected_url, msg="", code=301): - if expected_url.startswith('/'): - expected_url = "http://%s:%s%s" % (HOST, odoo.tools.config['http_port'], expected_url) if not msg: msg = 'Url <%s> differ from <%s>.' % (url, expected_url) r = self.url_open(url, head=True) self.assertEqual(r.status_code, code) - self.assertEqual(r.headers.get('Location'), expected_url, msg) + parsed_location = urlparse(r.headers.get('Location', '')) + parsed_expected_url = urlparse(expected_url) + self.assertEqual(parsed_location.path, parsed_expected_url.path, msg) + self.assertEqual(parsed_location.query, parsed_expected_url.query, msg) self.authenticate('admin', 'admin') diff --git a/addons/website_links/tests/test_controller.py b/addons/website_links/tests/test_controller.py index 2e055cea56f..169ebe3b528 100644 --- a/addons/website_links/tests/test_controller.py +++ b/addons/website_links/tests/test_controller.py @@ -1,4 +1,5 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. +from urllib.parse import urlparse from odoo.tests import tagged from odoo.tests.common import HttpCase @@ -38,7 +39,7 @@ class TestWebsiteLinksRussian(HttpCase): res = self.url_open(f'/r/r/{self.link.code}', allow_redirects=False) res.raise_for_status() self.assertEqual(res.status_code, 301, "Should be a lang alias redirection") - self.assertEqual(res.headers.get('Location'), f'{self.base_url()}/ru/r/{self.link.code}', + self.assertEqual(urlparse(res.headers.get('Location'), '').path, f'/ru/r/{self.link.code}', "Should be redirected to /ru as r is an alias for ru (russian)") res = self.url_open(res.headers['Location'], allow_redirects=False)