From e0c6a8429d6b81f7ffadad67f77501ab9a9d100a Mon Sep 17 00:00:00 2001 From: Max Shytikov Date: Tue, 1 Apr 2014 22:59:33 +0200 Subject: [PATCH] Added integration test for match on 'url' --- tests/integration/test_matchers.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/integration/test_matchers.py b/tests/integration/test_matchers.py index 1b7765d..c4b7999 100644 --- a/tests/integration/test_matchers.py +++ b/tests/integration/test_matchers.py @@ -19,6 +19,24 @@ def test_method_matcher(cassette): urlopen('http://httpbin.org/get') assert cass.play_count == 1 + # should fail if method does not match with pytest.raises(vcr.errors.CannotOverwriteExistingCassetteException): with vcr.use_cassette(cassette, match_on=['method']) as cass: - urlopen('http://httpbin.org/post', data='') + urlopen('http://httpbin.org/post', data=b'') # is a POST request + + +def test_url_matcher(cassette): + # prepare cassete + with vcr.use_cassette(cassette, match_on=['url']) 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: + urlopen('http://httpbin.org/get?p1=q1&p2=q2') + assert cass.play_count == 1 + + # should fail if url does not match + with pytest.raises(vcr.errors.CannotOverwriteExistingCassetteException): + with vcr.use_cassette(cassette, match_on=['url']) as cass: + urlopen('http://httpbin.org/get?p2=q2&p1=q1')