mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 17:15:35 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0c1f1e2479 | ||
|
|
8d90dba16c | ||
|
|
3072c56ed2 |
18
README.md
18
README.md
@@ -423,14 +423,18 @@ API in version 1.0.x
|
|||||||
|
|
||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
* 1.0.1: Fix a bug with the new ignore requests feature and the once
|
||||||
|
record mode
|
||||||
* 1.0.0: _BACKWARDS INCOMPATIBLE_: Please see the 'upgrade' section in the
|
* 1.0.0: _BACKWARDS INCOMPATIBLE_: Please see the 'upgrade' section in the
|
||||||
README. Add support for filtering sensitive data from requests, matching
|
README. Take a look at the matcher section as well, you might want to
|
||||||
query strings after the order changes and improving the built-in matchers,
|
update your `match_on` settings. Add support for filtering sensitive
|
||||||
(thanks to @mshytikov), support for ignoring requests to certain hosts,
|
data from requests, matching query strings after the order changes and
|
||||||
bump supported Python3 version to 3.4, fix some bugs with Boto support
|
improving the built-in matchers, (thanks to @mshytikov), support for
|
||||||
(thanks @marusich), fix error with URL field capitalization in README
|
ignoring requests to certain hosts, bump supported Python3 version to
|
||||||
(thanks @simon-weber), added some log messages to help with debugging,
|
3.4, fix some bugs with Boto support (thanks @marusich), fix error with
|
||||||
added `all_played` property on cassette (thanks @mshytikov)
|
URL field capitalization in README (thanks @simon-weber), added some log
|
||||||
|
messages to help with debugging, added `all_played` property on cassette
|
||||||
|
(thanks @mshytikov)
|
||||||
* 0.7.0: VCR.py now supports Python 3! (thanks @asundg) Also I refactored
|
* 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
|
the stub connections quite a bit to add support for the putrequest and
|
||||||
putheader calls. This version also adds support for httplib2 (thanks
|
putheader calls. This version also adds support for httplib2 (thanks
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -20,7 +20,7 @@ class PyTest(TestCommand):
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='vcrpy',
|
name='vcrpy',
|
||||||
version='1.0.0',
|
version='1.0.1',
|
||||||
description=(
|
description=(
|
||||||
"Automatically mock your HTTP interactions to simplify and "
|
"Automatically mock your HTTP interactions to simplify and "
|
||||||
"speed up testing"
|
"speed up testing"
|
||||||
|
|||||||
@@ -39,3 +39,17 @@ def test_ignore_localhost_and_httpbin(tmpdir, httpserver):
|
|||||||
urlopen('http://httpbin.org')
|
urlopen('http://httpbin.org')
|
||||||
urlopen(httpserver.url)
|
urlopen(httpserver.url)
|
||||||
assert len(cass) == 0
|
assert len(cass) == 0
|
||||||
|
|
||||||
|
def test_ignore_localhost_twice(tmpdir, httpserver):
|
||||||
|
httpserver.serve_content('Hello!')
|
||||||
|
cass_file = str(tmpdir.join('filter_qs.yaml'))
|
||||||
|
with vcr.use_cassette(cass_file, ignore_localhost=True) as cass:
|
||||||
|
urlopen(httpserver.url)
|
||||||
|
assert len(cass) == 0
|
||||||
|
urlopen('http://httpbin.org')
|
||||||
|
assert len(cass) == 1
|
||||||
|
with vcr.use_cassette(cass_file, ignore_localhost=True) as cass:
|
||||||
|
assert len(cass) == 1
|
||||||
|
urlopen(httpserver.url)
|
||||||
|
urlopen('http://httpbin.org')
|
||||||
|
assert len(cass) == 1
|
||||||
|
|||||||
@@ -80,15 +80,18 @@ class Cassette(ContextDecorator):
|
|||||||
return self.rewound and self.record_mode == 'once' or \
|
return self.rewound and self.record_mode == 'once' or \
|
||||||
self.record_mode == 'none'
|
self.record_mode == 'none'
|
||||||
|
|
||||||
def append(self, request, response):
|
def _filter_request(self, request):
|
||||||
'''Add a request, response pair to this cassette'''
|
return filter_request(
|
||||||
request = filter_request(
|
|
||||||
request=request,
|
request=request,
|
||||||
filter_headers=self._filter_headers,
|
filter_headers=self._filter_headers,
|
||||||
filter_query_parameters=self._filter_query_parameters,
|
filter_query_parameters=self._filter_query_parameters,
|
||||||
before_record=self._before_record,
|
before_record=self._before_record,
|
||||||
ignore_hosts=self._ignore_hosts
|
ignore_hosts=self._ignore_hosts
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def append(self, request, response):
|
||||||
|
'''Add a request, response pair to this cassette'''
|
||||||
|
request = self._filter_request(request)
|
||||||
if not request:
|
if not request:
|
||||||
return
|
return
|
||||||
self.data.append((request, response))
|
self.data.append((request, response))
|
||||||
@@ -99,19 +102,19 @@ class Cassette(ContextDecorator):
|
|||||||
internal API, returns an iterator with all responses matching
|
internal API, returns an iterator with all responses matching
|
||||||
the request.
|
the request.
|
||||||
"""
|
"""
|
||||||
request = filter_request(
|
request = self._filter_request(request)
|
||||||
request=request,
|
|
||||||
filter_headers=self._filter_headers,
|
|
||||||
filter_query_parameters=self._filter_query_parameters,
|
|
||||||
before_record=self._before_record,
|
|
||||||
ignore_hosts=self._ignore_hosts
|
|
||||||
)
|
|
||||||
if not request:
|
if not request:
|
||||||
return
|
return
|
||||||
for index, (stored_request, response) in enumerate(self.data):
|
for index, (stored_request, response) in enumerate(self.data):
|
||||||
if requests_match(request, stored_request, self._match_on):
|
if requests_match(request, stored_request, self._match_on):
|
||||||
yield index, response
|
yield index, response
|
||||||
|
|
||||||
|
def can_play_response_for(self, request):
|
||||||
|
request = self._filter_request(request)
|
||||||
|
return request and request in self and \
|
||||||
|
self.record_mode != 'all' and \
|
||||||
|
self.rewound
|
||||||
|
|
||||||
def play_response(self, request):
|
def play_response(self, request):
|
||||||
'''
|
'''
|
||||||
Get the response corresponding to a request, but only if it
|
Get the response corresponding to a request, but only if it
|
||||||
|
|||||||
@@ -204,9 +204,7 @@ class VCRConnection:
|
|||||||
'''Retrieve a the response'''
|
'''Retrieve a the response'''
|
||||||
# Check to see if the cassette has a response for this request. If so,
|
# Check to see if the cassette has a response for this request. If so,
|
||||||
# then return it
|
# then return it
|
||||||
if self._vcr_request in self.cassette and \
|
if self.cassette.can_play_response_for(self._vcr_request):
|
||||||
self.cassette.record_mode != "all" and \
|
|
||||||
self.cassette.rewound:
|
|
||||||
log.info(
|
log.info(
|
||||||
"Playing response for {0} from cassette".format(
|
"Playing response for {0} from cassette".format(
|
||||||
self._vcr_request
|
self._vcr_request
|
||||||
@@ -215,7 +213,7 @@ class VCRConnection:
|
|||||||
response = self.cassette.play_response(self._vcr_request)
|
response = self.cassette.play_response(self._vcr_request)
|
||||||
return VCRHTTPResponse(response)
|
return VCRHTTPResponse(response)
|
||||||
else:
|
else:
|
||||||
if self.cassette.write_protected:
|
if self.cassette.write_protected and self.cassette._filter_request(self._vcr_request):
|
||||||
raise CannotOverwriteExistingCassetteException(
|
raise CannotOverwriteExistingCassetteException(
|
||||||
"Can't overwrite existing cassette (%r) in "
|
"Can't overwrite existing cassette (%r) in "
|
||||||
"your current record mode (%r)."
|
"your current record mode (%r)."
|
||||||
@@ -264,9 +262,7 @@ class VCRConnection:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if hasattr(self, '_vcr_request') and \
|
if hasattr(self, '_vcr_request') and \
|
||||||
self._vcr_request in self.cassette and \
|
self.cassette.can_play_response_for(self._vcr_request):
|
||||||
self.cassette.record_mode != "all" and \
|
|
||||||
self.cassette.rewound:
|
|
||||||
# We already have a response we are going to play, don't
|
# We already have a response we are going to play, don't
|
||||||
# actually connect
|
# actually connect
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user