Projet

Général

Profil

0001-misc-use-legacy-urls-to-call-up-to-date-urls-65024.patch

Emmanuel Cazenave, 09 mai 2022 17:34

Télécharger (2,14 ko)

Voir les différences:

Subject: [PATCH] misc: use legacy urls to call up to date urls (#65024)

 combo/utils/requests_wrapper.py | 8 ++++++++
 tests/settings.py               | 2 ++
 tests/test_requests.py          | 7 +++++++
 3 files changed, 17 insertions(+)
combo/utils/requests_wrapper.py
59 59
        # don't use persistent cookies
60 60
        self.cookies.clear()
61 61

  
62
        # search in legacy urls
63
        legacy_urls_mapping = getattr(settings, 'LEGACY_URLS_MAPPING', None)
64
        if legacy_urls_mapping:
65
            splitted_url = urllib.parse.urlparse(url)
66
            hostname = splitted_url.netloc
67
            if hostname in legacy_urls_mapping:
68
                url = splitted_url._replace(netloc=legacy_urls_mapping[hostname]).geturl()
69

  
62 70
        if remote_service == 'auto':
63 71
            remote_service = get_known_service_for_url(url)
64 72
            if remote_service:
tests/settings.py
107 107
        },
108 108
    ]
109 109
}
110

  
111
LEGACY_URLS_MAPPING = {'old.org': 'new.org'}
tests/test_requests.py
150 150

  
151 151
        # check with unicode url
152 152
        assert requests.get('http://cache.example.org/éléphant').content == b'hello second world'
153

  
154

  
155
def test_requests_to_legacy_urls():
156
    with mock.patch('combo.utils.requests_wrapper.RequestsSession.request') as requests_get:
157
        requests_get.return_value = mock.Mock(content=b'hello world', status_code=200)
158
        assert requests.get('http://old.org/').content == b'hello world'
159
        assert requests_get.call_args.args[1] == 'http://new.org/'
153
-