From 306238d561c33f0e1fc056864f77df29ddb9f816 Mon Sep 17 00:00:00 2001 From: Luiz Menezes Date: Sun, 8 Jul 2018 23:06:22 -0300 Subject: [PATCH] Test aiohttp usage with query strings on the URL --- tests/integration/test_aiohttp.py | 17 +++++++++++++++++ vcr/stubs/aiohttp_stubs/__init__.py | 3 +-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/integration/test_aiohttp.py b/tests/integration/test_aiohttp.py index db61984..6cc28c3 100644 --- a/tests/integration/test_aiohttp.py +++ b/tests/integration/test_aiohttp.py @@ -137,3 +137,20 @@ def test_params_same_url_distinct_params(tmpdir, scheme): response, cassette_response_text = get(url, output='text', params=other_params) assert 'No match for the request' in cassette_response_text assert response.status == 599 + + +def test_params_on_url(tmpdir, scheme): + url = scheme + '://httpbin.org/get?a=1&b=foo' + headers = {'Content-Type': 'application/json'} + + with vcr.use_cassette(str(tmpdir.join('get.yaml'))) as cassette: + _, response_json = get(url, output='json', headers=headers) + request = cassette.requests[0] + assert request.url == url + + with vcr.use_cassette(str(tmpdir.join('get.yaml'))) as cassette: + _, cassette_response_json = get(url, output='json', headers=headers) + request = cassette.requests[0] + assert request.url == url + assert cassette_response_json == response_json + assert cassette.play_count == 1 diff --git a/vcr/stubs/aiohttp_stubs/__init__.py b/vcr/stubs/aiohttp_stubs/__init__.py index 0d7806a..f57cb63 100644 --- a/vcr/stubs/aiohttp_stubs/__init__.py +++ b/vcr/stubs/aiohttp_stubs/__init__.py @@ -52,12 +52,11 @@ def vcr_request(cassette, real_request): data = kwargs.get('data') params = kwargs.get('params') + request_url = URL(url) if params: for k, v in params.items(): params[k] = str(v) request_url = URL(url).with_query(params) - else: - request_url = URL(url) vcr_request = Request(method, str(request_url), data, headers)