[FIX] test_website: remove base_url from assertions

Since Werkzeug 2.1.0, the Response.autocorrect_location_header is
disabled by default.

As it's RFC compliant and supported by browsers, the base_url is simply
removed from the assertions.

Part-of: odoo/odoo#112298
This commit is contained in:
Christophe Monniez
2023-02-10 14:37:30 +01:00
parent 25ab0c269f
commit 442c776cb6
4 changed files with 14 additions and 9 deletions
+3 -2
View File
@@ -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)
+3 -1
View File
@@ -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)
+6 -5
View File
@@ -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')
@@ -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)