1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-09 01:03:24 +00:00

aiohttp headers are case insensitive (#461)

* aiohttp headers are case insensitive

* flakes
This commit is contained in:
Laurent Mazuel
2019-07-30 16:17:54 -07:00
committed by Josh Peak
parent 9d37210fc8
commit e3b7116564
2 changed files with 15 additions and 2 deletions

View File

@@ -59,12 +59,24 @@ def test_headers(tmpdir, scheme, auth):
request = cassette.requests[0] request = cassette.requests[0]
assert "AUTHORIZATION" in request.headers assert "AUTHORIZATION" in request.headers
cassette_response, _ = get(url, auth=auth) cassette_response, _ = get(url, auth=auth)
assert cassette_response.headers == response.headers assert dict(cassette_response.headers) == dict(response.headers)
assert cassette.play_count == 1 assert cassette.play_count == 1
assert 'istr' not in cassette.data[0] assert 'istr' not in cassette.data[0]
assert 'yarl.URL' not in cassette.data[0] assert 'yarl.URL' not in cassette.data[0]
def test_case_insensitive_headers(tmpdir, scheme):
url = scheme + '://httpbin.org'
with vcr.use_cassette(str(tmpdir.join('whatever.yaml'))):
_, _ = get(url)
with vcr.use_cassette(str(tmpdir.join('whatever.yaml'))) as cassette:
cassette_response, _ = get(url)
assert "Content-Type" in cassette_response.headers
assert "content-type" in cassette_response.headers
assert cassette.play_count == 1
def test_text(tmpdir, scheme): def test_text(tmpdir, scheme):
url = scheme + '://httpbin.org' url = scheme + '://httpbin.org'
with vcr.use_cassette(str(tmpdir.join('text.yaml'))): with vcr.use_cassette(str(tmpdir.join('text.yaml'))):

View File

@@ -7,6 +7,7 @@ import logging
import json import json
from aiohttp import ClientResponse, streams from aiohttp import ClientResponse, streams
from multidict import CIMultiDict, CIMultiDictProxy
from yarl import URL from yarl import URL
from vcr.request import Request from vcr.request import Request
@@ -61,7 +62,7 @@ def build_response(vcr_request, vcr_response, history):
response.status = vcr_response['status']['code'] response.status = vcr_response['status']['code']
response._body = vcr_response['body'].get('string', b'') response._body = vcr_response['body'].get('string', b'')
response.reason = vcr_response['status']['message'] response.reason = vcr_response['status']['message']
response._headers = vcr_response['headers'] response._headers = CIMultiDictProxy(CIMultiDict(vcr_response['headers']))
response._history = tuple(history) response._history = tuple(history)
response.close() response.close()