]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
Don't write header values multiple times.
authorMatt Thomson <mattjohnthomson@gmail.com>
Sat, 6 Sep 2014 15:57:12 +0000 (16:57 +0100)
committerMatt Thomson <mattjohnthomson@gmail.com>
Sat, 6 Sep 2014 15:57:12 +0000 (16:57 +0100)
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.

tests/integration/test_request.py
vcr/stubs/compat.py

index 0e016747432e58d981d567114c9aa7aa119944df..cbb62425fbf9cec3510b59b54a7741e5e0d07523 100644 (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']
index 6b65ca08efd0526d8b233f188c25f7366d824f60..13f30a006992cac9aa63ae26afb0ddaa514d81f8 100644 (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: