misc: use legacy urls to call up to date urls (#64344)
This commit is contained in:
parent
e629fccaec
commit
1ca5e77bd5
|
@ -23,8 +23,18 @@ def translate_from_publik_url(url):
|
|||
if not url:
|
||||
return ''
|
||||
source_url = urllib.parse.urlparse(url)
|
||||
|
||||
if source_url.scheme != 'publik':
|
||||
return url
|
||||
# search in legacy urls
|
||||
legacy_urls_mapping = getattr(settings, 'LEGACY_URLS_MAPPING', None)
|
||||
if not legacy_urls_mapping:
|
||||
return url
|
||||
splitted_url = urllib.parse.urlparse(url)
|
||||
hostname = splitted_url.netloc
|
||||
if hostname not in legacy_urls_mapping:
|
||||
return url
|
||||
return splitted_url._replace(netloc=legacy_urls_mapping[hostname]).geturl()
|
||||
|
||||
known_services = getattr(settings, 'KNOWN_SERVICES', None)
|
||||
if not known_services:
|
||||
return url
|
||||
|
|
|
@ -29,6 +29,8 @@ KNOWN_SERVICES = {
|
|||
},
|
||||
}
|
||||
|
||||
LEGACY_URLS_MAPPING = {'old.org': 'new.org'}
|
||||
|
||||
EXCEPTIONS_SOURCES = {}
|
||||
|
||||
SITE_BASE_URL = 'https://example.com'
|
||||
|
|
|
@ -145,3 +145,10 @@ def test_requests_cache():
|
|||
|
||||
# check with unicode url
|
||||
assert requests.get('http://cache.example.org/éléphant').content == b'hello second world'
|
||||
|
||||
|
||||
def test_requests_to_legacy_urls():
|
||||
with mock.patch('chrono.utils.requests_wrapper.RequestsSession.request') as requests_get:
|
||||
requests_get.return_value = mock.Mock(content=b'hello world', status_code=200)
|
||||
assert requests.get('http://old.org/').content == b'hello world'
|
||||
assert requests_get.call_args.args[1] == 'http://new.org/'
|
||||
|
|
Loading…
Reference in New Issue