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:
@@ -73,7 +73,7 @@ my_vcr = vcr.VCR(
|
||||
serializer = 'json',
|
||||
cassette_library_dir = 'fixtures/cassettes',
|
||||
record_mode = 'once',
|
||||
match_on = ['url', 'method'],
|
||||
match_on = ['uri', 'method'],
|
||||
)
|
||||
|
||||
with my_vcr.use_cassette('test.json'):
|
||||
|
||||
@@ -25,18 +25,18 @@ def test_method_matcher(cassette):
|
||||
urlopen('http://httpbin.org/post', data=b'') # is a POST request
|
||||
|
||||
|
||||
def test_url_matcher(cassette):
|
||||
def test_uri_matcher(cassette):
|
||||
# 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')
|
||||
assert len(cass) == 1
|
||||
|
||||
# play cassette with matching on url
|
||||
with vcr.use_cassette(cassette, match_on=['url']) as cass:
|
||||
# play cassette with matching on uri
|
||||
with vcr.use_cassette(cassette, match_on=['uri']) as cass:
|
||||
urlopen('http://httpbin.org/get?p1=q1&p2=q2')
|
||||
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 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')
|
||||
|
||||
@@ -26,9 +26,9 @@ def assert_matcher(matcher_name):
|
||||
assert matched
|
||||
|
||||
|
||||
def test_url_matcher():
|
||||
def test_uri_matcher():
|
||||
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')):
|
||||
assert not matched
|
||||
else:
|
||||
|
||||
@@ -13,7 +13,7 @@ from .patch import install, reset
|
||||
from .persist import load_cassette, save_cassette
|
||||
from .filters import filter_request
|
||||
from .serializers import yamlserializer
|
||||
from .matchers import requests_match, url, method
|
||||
from .matchers import requests_match, uri, method
|
||||
from .errors import UnhandledHTTPRequestError
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class Cassette(ContextDecorator):
|
||||
path,
|
||||
serializer=yamlserializer,
|
||||
record_mode='once',
|
||||
match_on=[url, method],
|
||||
match_on=[uri, method]):
|
||||
filter_headers=[],
|
||||
filter_query_parameters=[],
|
||||
before_record=None,
|
||||
|
||||
@@ -30,7 +30,8 @@ class VCR(object):
|
||||
}
|
||||
self.matchers = {
|
||||
'method': matchers.method,
|
||||
'url': matchers.url,
|
||||
'uri': matchers.uri,
|
||||
'url': matchers.uri, # matcher for backwards compatibility
|
||||
'scheme': matchers.scheme,
|
||||
'host': matchers.host,
|
||||
'port': matchers.method,
|
||||
|
||||
@@ -5,8 +5,8 @@ def method(r1, r2):
|
||||
return r1.method == r2.method
|
||||
|
||||
|
||||
def url(r1, r2):
|
||||
return r1.url == r2.url
|
||||
def uri(r1, r2):
|
||||
return r1.uri == r2.uri
|
||||
|
||||
|
||||
def host(r1, r2):
|
||||
|
||||
Reference in New Issue
Block a user