11import contextlib
22
33import pytest
4+ import vcr # noqa: E402
5+
6+
7+ multidict = pytest .importorskip ("multidict" )
48asyncio = pytest .importorskip ("asyncio" )
59aiohttp = pytest .importorskip ("aiohttp" )
610
7- import vcr # noqa: E402
811from .aiohttp_utils import aiohttp_app , aiohttp_request # noqa: E402
912
1013
@@ -97,7 +100,9 @@ def test_stream(tmpdir, scheme):
97100 url = scheme + '://httpbin.org/get'
98101
99102 with vcr .use_cassette (str (tmpdir .join ('stream.yaml' ))):
100- resp , body = get (url , output = 'raw' ) # Do not use stream here, as the stream is exhausted by vcr
103+ resp , body = get (
104+ url , output = 'raw'
105+ ) # Do not use stream here, as the stream is exhausted by vcr
101106
102107 with vcr .use_cassette (str (tmpdir .join ('stream.yaml' ))) as cassette :
103108 cassette_resp , cassette_body = get (url , output = 'stream' )
@@ -123,10 +128,16 @@ def test_params(tmpdir, scheme):
123128 params = {'a' : 1 , 'b' : False , 'c' : 'c' }
124129
125130 with vcr .use_cassette (str (tmpdir .join ('get.yaml' ))) as cassette :
126- _ , response_json = get (url , output = 'json' , params = params , headers = headers )
131+ _ , response_json = get (url ,
132+ output = 'json' ,
133+ params = params ,
134+ headers = headers )
127135
128136 with vcr .use_cassette (str (tmpdir .join ('get.yaml' ))) as cassette :
129- _ , cassette_response_json = get (url , output = 'json' , params = params , headers = headers )
137+ _ , cassette_response_json = get (url ,
138+ output = 'json' ,
139+ params = params ,
140+ headers = headers )
130141 assert cassette_response_json == response_json
131142 assert cassette .play_count == 1
132143
@@ -137,16 +148,24 @@ def test_params_same_url_distinct_params(tmpdir, scheme):
137148 params = {'a' : 1 , 'b' : False , 'c' : 'c' }
138149
139150 with vcr .use_cassette (str (tmpdir .join ('get.yaml' ))) as cassette :
140- _ , response_json = get (url , output = 'json' , params = params , headers = headers )
151+ _ , response_json = get (url ,
152+ output = 'json' ,
153+ params = params ,
154+ headers = headers )
141155
142156 with vcr .use_cassette (str (tmpdir .join ('get.yaml' ))) as cassette :
143- _ , cassette_response_json = get (url , output = 'json' , params = params , headers = headers )
157+ _ , cassette_response_json = get (url ,
158+ output = 'json' ,
159+ params = params ,
160+ headers = headers )
144161 assert cassette_response_json == response_json
145162 assert cassette .play_count == 1
146163
147164 other_params = {'other' : 'params' }
148165 with vcr .use_cassette (str (tmpdir .join ('get.yaml' ))) as cassette :
149- response , cassette_response_text = get (url , output = 'text' , params = other_params )
166+ response , cassette_response_text = get (url ,
167+ output = 'text' ,
168+ params = other_params )
150169 assert 'No match for the request' in cassette_response_text
151170 assert response .status == 599
152171
@@ -164,6 +183,17 @@ def test_params_on_url(tmpdir, scheme):
164183 _ , cassette_response_json = get (url , output = 'json' , headers = headers )
165184 request = cassette .requests [0 ]
166185 assert request .url == url
186+
187+
188+ def test_repeated_params (tmpdir , scheme ):
189+ url = scheme + '://httpbin.org/get'
190+ params = [('a' , '1' ), ('c' , 'c' ), ('a' , '2' )]
191+
192+ with vcr .use_cassette (str (tmpdir .join ('get.yaml' ))) as cassette :
193+ _ , response_json = get (url , as_text = False , params = params )
194+
195+ with vcr .use_cassette (str (tmpdir .join ('get.yaml' ))) as cassette :
196+ _ , cassette_response_json = get (url , as_text = False , params = params )
167197 assert cassette_response_json == response_json
168198 assert cassette .play_count == 1
169199
@@ -214,3 +244,17 @@ def test_aiohttp_test_client_json(aiohttp_client, tmpdir):
214244 response_json = loop .run_until_complete (response .json ())
215245 assert response_json is None
216246 assert cassette .play_count == 1
247+
248+
249+ def test_repeated_params_multidict (tmpdir , scheme ):
250+ url = scheme + '://httpbin.org/get'
251+ params_list = [('a' , 1 ), ('c' , 'c' ), ('a' , '2' )]
252+ params = multidict .MultiDict (params_list )
253+
254+ with vcr .use_cassette (str (tmpdir .join ('get.yaml' ))) as cassette :
255+ _ , response_json = get (url , as_text = False , params = params )
256+
257+ with vcr .use_cassette (str (tmpdir .join ('get.yaml' ))) as cassette :
258+ _ , cassette_response_json = get (url , as_text = False , params = params )
259+ assert cassette_response_json == response_json
260+ assert cassette .play_count == 1
0 commit comments