From 0d4c9eccf57d302d6ab549867a4412e5848710bc Mon Sep 17 00:00:00 2001 From: Goran Stefkovski Date: Thu, 21 Jun 2018 16:17:49 +1000 Subject: [PATCH 1/3] simplified logic so that either params or url is used, if params are specified - they will overwrite any get params on the url --- vcr/stubs/aiohttp_stubs/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vcr/stubs/aiohttp_stubs/__init__.py b/vcr/stubs/aiohttp_stubs/__init__.py index 4f2c111..0d7806a 100644 --- a/vcr/stubs/aiohttp_stubs/__init__.py +++ b/vcr/stubs/aiohttp_stubs/__init__.py @@ -51,11 +51,14 @@ def vcr_request(cassette, real_request): headers = self._prepare_headers(headers) data = kwargs.get('data') params = kwargs.get('params') + if params: for k, v in params.items(): params[k] = str(v) + request_url = URL(url).with_query(params) + else: + request_url = URL(url) - request_url = URL(url).with_query(params) vcr_request = Request(method, str(request_url), data, headers) if cassette.can_play_response_for(vcr_request): From dbddaa0e448cb39c3c44ee2e201a54151959716e Mon Sep 17 00:00:00 2001 From: Goran Stefkovski Date: Thu, 21 Jun 2018 16:01:01 +1000 Subject: [PATCH 2/3] Shallow copy of query as mutable MultiDict From 306238d561c33f0e1fc056864f77df29ddb9f816 Mon Sep 17 00:00:00 2001 From: Luiz Menezes Date: Sun, 8 Jul 2018 23:06:22 -0300 Subject: [PATCH 3/3] 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)