1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-08 16:53:23 +00:00

Replaced 'url' mather with 'uri'.

This commit is contained in:
Max Shytikov
2014-04-11 01:32:10 +02:00
parent 7fe55ad8b8
commit 2fa1aaa1f7
6 changed files with 15 additions and 14 deletions

View File

@@ -73,7 +73,7 @@ my_vcr = vcr.VCR(
serializer = 'json', serializer = 'json',
cassette_library_dir = 'fixtures/cassettes', cassette_library_dir = 'fixtures/cassettes',
record_mode = 'once', record_mode = 'once',
match_on = ['url', 'method'], match_on = ['uri', 'method'],
) )
with my_vcr.use_cassette('test.json'): with my_vcr.use_cassette('test.json'):

View File

@@ -25,18 +25,18 @@ def test_method_matcher(cassette):
urlopen('http://httpbin.org/post', data=b'') # is a POST request urlopen('http://httpbin.org/post', data=b'') # is a POST request
def test_url_matcher(cassette): def test_uri_matcher(cassette):
# prepare cassete # prepare cassete
with vcr.use_cassette(cassette, match_on=['url']) as cass: with vcr.use_cassette(cassette, match_on=['uri']) as cass:
urlopen('http://httpbin.org/get?p1=q1&p2=q2') urlopen('http://httpbin.org/get?p1=q1&p2=q2')
assert len(cass) == 1 assert len(cass) == 1
# play cassette with matching on url # play cassette with matching on uri
with vcr.use_cassette(cassette, match_on=['url']) as cass: with vcr.use_cassette(cassette, match_on=['uri']) as cass:
urlopen('http://httpbin.org/get?p1=q1&p2=q2') urlopen('http://httpbin.org/get?p1=q1&p2=q2')
assert cass.play_count == 1 assert cass.play_count == 1
# should fail if url does not match # should fail if uri does not match
with pytest.raises(vcr.errors.CannotOverwriteExistingCassetteException): with pytest.raises(vcr.errors.CannotOverwriteExistingCassetteException):
with vcr.use_cassette(cassette, match_on=['url']) as cass: with vcr.use_cassette(cassette, match_on=['uri']) as cass:
urlopen('http://httpbin.org/get?p2=q2&p1=q1') urlopen('http://httpbin.org/get?p2=q2&p1=q1')

View File

@@ -26,9 +26,9 @@ def assert_matcher(matcher_name):
assert matched assert matched
def test_url_matcher(): def test_uri_matcher():
for k1, k2 in itertools.permutations(REQUESTS, 2): for k1, k2 in itertools.permutations(REQUESTS, 2):
matched = matchers.url(REQUESTS[k1], REQUESTS[k2]) matched = matchers.uri(REQUESTS[k1], REQUESTS[k2])
if set((k1, k2)) != set(('base', 'method')): if set((k1, k2)) != set(('base', 'method')):
assert not matched assert not matched
else: else:

View File

@@ -13,7 +13,7 @@ from .patch import install, reset
from .persist import load_cassette, save_cassette from .persist import load_cassette, save_cassette
from .filters import filter_request from .filters import filter_request
from .serializers import yamlserializer from .serializers import yamlserializer
from .matchers import requests_match, url, method from .matchers import requests_match, uri, method
from .errors import UnhandledHTTPRequestError from .errors import UnhandledHTTPRequestError
@@ -31,7 +31,7 @@ class Cassette(ContextDecorator):
path, path,
serializer=yamlserializer, serializer=yamlserializer,
record_mode='once', record_mode='once',
match_on=[url, method], match_on=[uri, method]):
filter_headers=[], filter_headers=[],
filter_query_parameters=[], filter_query_parameters=[],
before_record=None, before_record=None,

View File

@@ -30,7 +30,8 @@ class VCR(object):
} }
self.matchers = { self.matchers = {
'method': matchers.method, 'method': matchers.method,
'url': matchers.url, 'uri': matchers.uri,
'url': matchers.uri, # matcher for backwards compatibility
'scheme': matchers.scheme, 'scheme': matchers.scheme,
'host': matchers.host, 'host': matchers.host,
'port': matchers.method, 'port': matchers.method,

View File

@@ -5,8 +5,8 @@ def method(r1, r2):
return r1.method == r2.method return r1.method == r2.method
def url(r1, r2): def uri(r1, r2):
return r1.url == r2.url return r1.uri == r2.uri
def host(r1, r2): def host(r1, r2):