mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-08 16:53:23 +00:00
Don't write header values multiple times.
On Python 3, response.msg.keys() contains the same value multiple times if there are multiple headers with the same value. Work around this by converting to a set before iterating over it.
This commit is contained in:
@@ -9,3 +9,14 @@ def test_recorded_request_uri_with_redirected_request(tmpdir):
|
|||||||
assert cass.requests[0].uri == 'http://httpbin.org/redirect/3'
|
assert cass.requests[0].uri == 'http://httpbin.org/redirect/3'
|
||||||
assert cass.requests[3].uri == 'http://httpbin.org/get'
|
assert cass.requests[3].uri == 'http://httpbin.org/get'
|
||||||
assert len(cass) == 4
|
assert len(cass) == 4
|
||||||
|
|
||||||
|
|
||||||
|
def test_records_multiple_header_values(tmpdir, httpserver):
|
||||||
|
httpserver.serve_content('Hello!', headers=[('foo', 'bar'), ('foo', 'baz')])
|
||||||
|
|
||||||
|
with vcr.use_cassette(str(tmpdir.join('test.yml'))) as cass:
|
||||||
|
assert len(cass) == 0
|
||||||
|
|
||||||
|
urlopen(httpserver.url)
|
||||||
|
assert len(cass) == 1
|
||||||
|
assert cass.responses[0]['headers']['foo'] == ['bar', 'baz']
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ def get_header_items(message):
|
|||||||
|
|
||||||
|
|
||||||
def get_headers(response):
|
def get_headers(response):
|
||||||
for key in response.msg.keys():
|
for key in set(response.msg.keys()):
|
||||||
if six.PY3:
|
if six.PY3:
|
||||||
yield key, response.msg.get_all(key)
|
yield key, response.msg.get_all(key)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user