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

Compare commits

...

6 Commits

Author SHA1 Message Date
Kevin McCarthy
2275749eaa bump for version 0.3.4 2013-10-24 19:56:36 -10:00
smallcode
16fbe40d87 Update filesystem.py
fix WindowsError: [Error 32].
because must close the file before rename the file in window system.
2013-10-22 17:41:56 +08:00
Kevin McCarthy
deed8cab97 Fix issue #36 - error message for unregistered matcher was broken 2013-09-29 15:56:50 -10:00
Kevin McCarthy
cf8646d8d6 Bump version for bugfix release 2013-09-21 16:52:09 -10:00
Hector Dearman
c03459e582 allow match_on to be passed as an argument VCR 2013-09-21 16:52:09 -10:00
Kevin McCarthy
912452e863 Only use the relative path in HTTP requests
This causes a pretty big problem on out-of-spec HTTP servers (like
Flickr). Closes #31
2013-09-17 13:19:26 -10:00
8 changed files with 45 additions and 9 deletions

View File

@@ -259,6 +259,13 @@ This library is a work in progress, so the API might change on you.
There are probably some [bugs](https://github.com/kevin1024/vcrpy/issues?labels=bug&page=1&state=open) floating around too.
##Changelog
* 0.3.4: Bugfix: close file before renaming it. This fixes an issue on Windows. Thanks @smallcode for the fix.
* 0.3.3: Bugfix for error message when an unreigstered custom matcher
was used
* 0.3.2: Fix issue with new config syntax and the `match_on` parameter.
Thanks, @chromy!
* 0.3.1: Fix issue causing full paths to be sent on the HTTP request
line.
* 0.3.0: *Backwards incompatible release* - Added support for record
modes, and changed the default recording behavior to the "once" record
mode. Please see the documentation on record modes for more. Added

View File

@@ -19,7 +19,7 @@ class PyTest(TestCommand):
sys.exit(errno)
setup(name='vcrpy',
version='0.3.0',
version='0.3.4',
description="A Python port of Ruby's VCR to make mocking HTTP easier",
author='Kevin McCarthy',
author_email='me@kevinmccarthy.org',

View File

@@ -1,6 +1,7 @@
import os
import json
import urllib2
import pytest
import vcr
@@ -34,3 +35,22 @@ def test_override_set_cassette_library_dir(tmpdir):
assert os.path.exists(str(tmpdir.join('subdir2').join('test.json')))
assert not os.path.exists(str(tmpdir.join('subdir').join('test.json')))
def test_override_match_on(tmpdir):
my_vcr = vcr.VCR(match_on=['method'])
with my_vcr.use_cassette(str(tmpdir.join('test.json'))) as cass:
urllib2.urlopen('http://httpbin.org/')
urllib2.urlopen('http://httpbin.org/get')
assert len(cass) == 1
assert cass.play_count == 1
def test_missing_matcher():
my_vcr = vcr.VCR()
my_vcr.register_matcher("awesome", object)
with pytest.raises(KeyError):
with my_vcr.use_cassette("test.yaml", match_on=['notawesome']):
pass

View File

@@ -45,3 +45,10 @@ def test_flickr_multipart_upload():
assert len(cass) == 1
_pretend_to_be_flickr_library()
assert cass.play_count == 1
def test_flickr_should_respond_with_200(tmpdir):
testfile = str(tmpdir.join('flickr.yml'))
with vcr.use_cassette(testfile):
r = requests.post("http://api.flickr.com/services/upload")
assert r.status_code == 200

View File

@@ -50,6 +50,7 @@ def test_cassette_len():
def _mock_requests_match(request1, request2, matchers):
return request1 == request2
@mock.patch('vcr.cassette.requests_match', _mock_requests_match)
def test_cassette_contains():
a = Cassette('test')

View File

@@ -8,9 +8,11 @@ class VCR(object):
def __init__(self,
serializer='yaml',
cassette_library_dir=None,
record_mode="once"):
record_mode="once",
match_on=['url', 'method'],
):
self.serializer = serializer
self.match_on = ['url', 'method']
self.match_on = match_on
self.cassette_library_dir = cassette_library_dir
self.serializers = {
'yaml': yamlserializer,
@@ -40,10 +42,9 @@ class VCR(object):
try:
matchers = [self.matchers[m] for m in matcher_names]
except KeyError:
print "Matcher {0} doesn't exist or isn't registered".format(
matcher_name
raise KeyError(
"Matcher {0} doesn't exist or isn't registered".format(m)
)
raise KeyError
return matchers
def use_cassette(self, path, **kwargs):

View File

@@ -13,7 +13,7 @@ class FilesystemPersister(object):
fd, name = tempfile.mkstemp(dir=dirname, prefix=filename)
with os.fdopen(fd, 'w') as fout:
fout.write(contents)
os.rename(name, path)
os.rename(name, path)
@classmethod
def write(cls, cassette_path, data):

View File

@@ -79,7 +79,7 @@ class VCRConnectionMixin:
def _send_request(self, method, url, body, headers):
"""
Coppy+pasted from python stdlib 2.6 source because it
Copy+pasted from python stdlib 2.6 source because it
has a call to self.send() which I have overridden
#stdlibproblems #fml
"""
@@ -160,7 +160,7 @@ class VCRConnectionMixin:
self._baseclass.request(
self,
method=self._vcr_request.method,
url=self._vcr_request.url,
url=self._vcr_request.path,
body=self._vcr_request.body,
headers=dict(self._vcr_request.headers or {})
)