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

Use pytest-httpbin

This will help the test flakiness and speed up test runs.
This commit is contained in:
Kevin McCarthy
2015-04-11 13:07:17 -10:00
parent cfc483a08d
commit 4e36997e1a
20 changed files with 380 additions and 369 deletions

View File

@@ -5,46 +5,46 @@ import vcr
from six.moves.urllib.request import urlopen
def test_set_serializer_default_config(tmpdir):
def test_set_serializer_default_config(tmpdir, httpbin):
my_vcr = vcr.VCR(serializer='json')
with my_vcr.use_cassette(str(tmpdir.join('test.json'))):
assert my_vcr.serializer == 'json'
urlopen('http://httpbin.org/get')
urlopen(httpbin.url + '/get')
with open(str(tmpdir.join('test.json'))) as f:
assert json.loads(f.read())
def test_default_set_cassette_library_dir(tmpdir):
def test_default_set_cassette_library_dir(tmpdir, httpbin):
my_vcr = vcr.VCR(cassette_library_dir=str(tmpdir.join('subdir')))
with my_vcr.use_cassette('test.json'):
urlopen('http://httpbin.org/get')
urlopen(httpbin.url + '/get')
assert os.path.exists(str(tmpdir.join('subdir').join('test.json')))
def test_override_set_cassette_library_dir(tmpdir):
def test_override_set_cassette_library_dir(tmpdir, httpbin):
my_vcr = vcr.VCR(cassette_library_dir=str(tmpdir.join('subdir')))
cld = str(tmpdir.join('subdir2'))
with my_vcr.use_cassette('test.json', cassette_library_dir=cld):
urlopen('http://httpbin.org/get')
urlopen(httpbin.url + '/get')
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):
def test_override_match_on(tmpdir, httpbin):
my_vcr = vcr.VCR(match_on=['method'])
with my_vcr.use_cassette(str(tmpdir.join('test.json'))):
urlopen('http://httpbin.org/')
urlopen(httpbin.url)
with my_vcr.use_cassette(str(tmpdir.join('test.json'))) as cass:
urlopen('http://httpbin.org/get')
urlopen(httpbin.url + '/get')
assert len(cass) == 1
assert cass.play_count == 1