diff --git a/tests/integration/test_urllib3.py b/tests/integration/test_urllib3.py index d159ddb6..34ad5255 100644 --- a/tests/integration/test_urllib3.py +++ b/tests/integration/test_urllib3.py @@ -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 diff --git a/vcr/stubs/__init__.py b/vcr/stubs/__init__.py index 2c3b8b5d..a219f36a 100644 --- a/vcr/stubs/__init__.py +++ b/vcr/stubs/__init__.py @@ -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"] @@ -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( @@ -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)