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

improve socket mocking to hopefully pass both new python3.4 socket connection stuff and requests tests

This commit is contained in:
Kevin McCarthy
2014-04-23 19:30:43 -10:00
parent bd2d2cea72
commit bc5199c893
3 changed files with 36 additions and 4 deletions

View File

@@ -14,11 +14,11 @@ matrix:
- env: WITH_LIB="boto"
exclude:
- env: WITH_LIB="boto"
python: 3.4
python: 3.3
python:
- 2.6
- 2.7
- 3.4
- 3.3
- pypy
install:
- pip install PyYAML pytest --use-mirrors

View File

@@ -18,7 +18,7 @@ to do is delete your existing cassette files, and run your tests again.
All of the mocked responses will be updated with the new API.
## Compatibility Notes
VCR.py supports Python 2.6 and 2.7, 3.3, and [pypy](http://pypy.org).
VCR.py supports Python 2.6 and 2.7, 3.4, and [pypy](http://pypy.org).
The following http libraries are supported:
@@ -281,6 +281,7 @@ Also, in order for the boto tests to run, you will need an AWS key. Refer to th
## Changelog
* 1.0.0 (in development) - Bump supported Python3 version to 3.4, fix some bugs with Boto support (thanks @marusich), fix error with URL field capitalization in README (thanks @simon-weber)
* 0.7.0: VCR.py now supports Python 3! (thanks @asundg) Also I refactored the stub connections quite a bit to add support for the putrequest and putheader calls. This version also adds support for httplib2 (thanks @nilp0inter). I have added a couple tests for bobo since it is an http client in its own right. Finally, this version includes a fix for a bug where requests wasn't being patched properly (thanks @msabramo).
* 0.6.0: Store response headers as a list since a HTTP response can have the same header twice (happens with set-cookie sometimes). This has the added benefit of preserving the order of headers. Thanks @smallcode for the bug report leading to this change. I have made an effort to ensure backwards compatibility with the old cassettes' header storage mechanism, but if you want to upgrade to the new header storage, you should delete your cassettes and re-record them. Also this release adds better error messages (thanks @msabramo) and adds support for using VCR as a decorator (thanks @smallcode for the motivation)
* 0.5.0: Change the `response_of` method to `responses_of` since cassettes can now contain more than one response for a request. Since this changes the API, I'm bumping the version. Also includes 2 bugfixes: a better error message when attempting to overwrite a cassette file, and a fix for a bug with requests sessions (thanks @msabramo)

View File

@@ -16,6 +16,27 @@ from vcr.request import Request
from vcr.errors import CannotOverwriteExistingCassetteException
from . import compat
class VCRFakeSocket(object):
"""
A socket that doesn't do anything!
Used when playing back casssettes, when there
is no actual open socket.
"""
def close(self):
pass
def settimeout(self, *args, **kwargs):
pass
def fileno(self):
"""
This is kinda crappy. requests will watch
this descriptor and make sure it's not closed.
Return file descriptor 0 since that's stdin.
"""
return 0 # wonder how bad this is....
def parse_headers_backwards_compat(header_dict):
"""
@@ -220,6 +241,17 @@ class VCRConnection:
return self.real_connection.connect(*args, **kwargs)
@property
def sock(self):
if self.real_connection.sock:
return self.real_connection.sock
return VCRFakeSocket()
@sock.setter
def sock(self, value):
if self.real_connection.sock:
self.real_connection.sock = value
def __init__(self, *args, **kwargs):
# need to temporarily reset here because the real connection
# inherits from the thing that we are mocking out. Take out
@@ -228,7 +260,6 @@ class VCRConnection:
reset()
self.real_connection = self._baseclass(*args, **kwargs)
install(self.cassette)
self.sock = self.real_connection.sock
class VCRHTTPConnection(VCRConnection):