1
0
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:
Matt Thomson
2014-09-06 16:57:12 +01:00
parent 7a5795a547
commit 3c410b5f9d
2 changed files with 12 additions and 1 deletions

View File

@@ -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[3].uri == 'http://httpbin.org/get'
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']

View File

@@ -28,7 +28,7 @@ def get_header_items(message):
def get_headers(response):
for key in response.msg.keys():
for key in set(response.msg.keys()):
if six.PY3:
yield key, response.msg.get_all(key)
else: