11import contextlib
22
33import pytest
4- asyncio = pytest .importorskip ("asyncio" )
5- aiohttp = pytest .importorskip ("aiohttp" )
6-
74import vcr # noqa: E402
5+
86from .aiohttp_utils import aiohttp_app , aiohttp_request # noqa: E402
97
8+ multidict = pytest .importorskip ("multidict" )
9+ asyncio = pytest .importorskip ("asyncio" )
10+ aiohttp = pytest .importorskip ("aiohttp" )
11+
1012
1113def run_in_loop (fn ):
1214 with contextlib .closing (asyncio .new_event_loop ()) as loop :
@@ -97,7 +99,9 @@ def test_stream(tmpdir, scheme):
9799 url = scheme + '://httpbin.org/get'
98100
99101 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
102+ resp , body = get (
103+ url , output = 'raw'
104+ ) # Do not use stream here, as the stream is exhausted by vcr
101105
102106 with vcr .use_cassette (str (tmpdir .join ('stream.yaml' ))) as cassette :
103107 cassette_resp , cassette_body = get (url , output = 'stream' )
@@ -123,10 +127,16 @@ def test_params(tmpdir, scheme):
123127 params = {'a' : 1 , 'b' : False , 'c' : 'c' }
124128
125129 with vcr .use_cassette (str (tmpdir .join ('get.yaml' ))) as cassette :
126- _ , response_json = get (url , output = 'json' , params = params , headers = headers )
130+ _ , response_json = get (url ,
131+ output = 'json' ,
132+ params = params ,
133+ headers = headers )
127134
128135 with vcr .use_cassette (str (tmpdir .join ('get.yaml' ))) as cassette :
129- _ , cassette_response_json = get (url , output = 'json' , params = params , headers = headers )
136+ _ , cassette_response_json = get (url ,
137+ output = 'json' ,
138+ params = params ,
139+ headers = headers )
130140 assert cassette_response_json == response_json
131141 assert cassette .play_count == 1
132142
@@ -137,16 +147,24 @@ def test_params_same_url_distinct_params(tmpdir, scheme):
137147 params = {'a' : 1 , 'b' : False , 'c' : 'c' }
138148
139149 with vcr .use_cassette (str (tmpdir .join ('get.yaml' ))) as cassette :
140- _ , response_json = get (url , output = 'json' , params = params , headers = headers )
150+ _ , response_json = get (url ,
151+ output = 'json' ,
152+ params = params ,
153+ headers = headers )
141154
142155 with vcr .use_cassette (str (tmpdir .join ('get.yaml' ))) as cassette :
143- _ , cassette_response_json = get (url , output = 'json' , params = params , headers = headers )
156+ _ , cassette_response_json = get (url ,
157+ output = 'json' ,
158+ params = params ,
159+ headers = headers )
144160 assert cassette_response_json == response_json
145161 assert cassette .play_count == 1
146162
147163 other_params = {'other' : 'params' }
148164 with vcr .use_cassette (str (tmpdir .join ('get.yaml' ))) as cassette :
149- response , cassette_response_text = get (url , output = 'text' , params = other_params )
165+ response , cassette_response_text = get (url ,
166+ output = 'text' ,
167+ params = other_params )
150168 assert 'No match for the request' in cassette_response_text
151169 assert response .status == 599
152170
@@ -164,6 +182,17 @@ def test_params_on_url(tmpdir, scheme):
164182 _ , cassette_response_json = get (url , output = 'json' , headers = headers )
165183 request = cassette .requests [0 ]
166184 assert request .url == url
185+
186+
187+ def test_repeated_params (tmpdir , scheme ):
188+ url = scheme + '://httpbin.org/get'
189+ params = [('a' , '1' ), ('c' , 'c' ), ('a' , '2' )]
190+
191+ with vcr .use_cassette (str (tmpdir .join ('get.yaml' ))) as cassette :
192+ _ , response_json = get (url , as_text = False , params = params )
193+
194+ with vcr .use_cassette (str (tmpdir .join ('get.yaml' ))) as cassette :
195+ _ , cassette_response_json = get (url , as_text = False , params = params )
167196 assert cassette_response_json == response_json
168197 assert cassette .play_count == 1
169198
@@ -214,3 +243,17 @@ def test_aiohttp_test_client_json(aiohttp_client, tmpdir):
214243 response_json = loop .run_until_complete (response .json ())
215244 assert response_json is None
216245 assert cassette .play_count == 1
246+
247+
248+ def test_repeated_params_multidict (tmpdir , scheme ):
249+ url = scheme + '://httpbin.org/get'
250+ params_list = [('a' , 1 ), ('c' , 'c' ), ('a' , '2' )]
251+ params = multidict .MultiDict (params_list )
252+
253+ with vcr .use_cassette (str (tmpdir .join ('get.yaml' ))) as cassette :
254+ _ , response_json = get (url , as_text = False , params = params )
255+
256+ with vcr .use_cassette (str (tmpdir .join ('get.yaml' ))) as cassette :
257+ _ , cassette_response_json = get (url , as_text = False , params = params )
258+ assert cassette_response_json == response_json
259+ assert cassette .play_count == 1
0 commit comments