Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/integration/test_urllib3.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ def test_status_code(httpbin_both, tmpdir, verify_pool_mgr):
assert status_code == verify_pool_mgr.request("GET", url).status


def test_url(httpbin_both, tmpdir, verify_pool_mgr):
"""Ensure that we can read the URL"""
url = httpbin_both.url
with vcr.use_cassette(str(tmpdir.join("url.yaml"))):
url = verify_pool_mgr.request("GET", url).geturl()

with vcr.use_cassette(str(tmpdir.join("url.yaml"))):
assert url == verify_pool_mgr.request("GET", url).geturl()


def test_headers(tmpdir, httpbin_both, verify_pool_mgr):
"""Ensure that we can read the headers back"""
url = httpbin_both.url
Expand Down
8 changes: 5 additions & 3 deletions vcr/stubs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ class VCRHTTPResponse(HTTPResponse):
Stub response class that gets returned instead of a HTTPResponse
"""

def __init__(self, recorded_response):
def __init__(self, recorded_response, request_url=None):
self.fp = None
if request_url:
self.url = request_url
self.recorded_response = recorded_response
self.reason = recorded_response["status"]["message"]
self.status = self.code = recorded_response["status"]["code"]
Expand Down Expand Up @@ -271,7 +273,7 @@ def getresponse(self, _=False, **kwargs):
if self.cassette.can_play_response_for(self._vcr_request):
log.info(f"Playing response for {self._vcr_request} from cassette")
response = self.cassette.play_response(self._vcr_request)
return VCRHTTPResponse(response)
return VCRHTTPResponse(response, self._vcr_request.uri)
else:
if self.cassette.write_protected and self.cassette.filter_request(self._vcr_request):
raise CannotOverwriteExistingCassetteException(
Expand Down Expand Up @@ -306,7 +308,7 @@ def getresponse(self, _=False, **kwargs):
"body": {"string": response_data},
}
self.cassette.append(self._vcr_request, response)
return VCRHTTPResponse(response)
return VCRHTTPResponse(response, self._vcr_request.uri)

def set_debuglevel(self, *args, **kwargs):
self.real_connection.set_debuglevel(*args, **kwargs)
Expand Down