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

pep8 fixes

This commit is contained in:
Kevin McCarthy
2013-08-23 19:56:13 -10:00
parent 98603541d6
commit c8299103fb
21 changed files with 177 additions and 76 deletions

View File

@@ -8,17 +8,19 @@ import urllib2
# Internal imports
import vcr
def test_nonexistent_directory(tmpdir):
'''If we load a cassette in a nonexistent directory, it can save ok'''
# Check to make sure directory doesnt exist
assert not os.path.exists(str(tmpdir.join('nonexistent')))
# Run VCR to create dir and cassette file
with vcr.use_cassette(str(tmpdir.join('nonexistent','cassette.yml'))):
with vcr.use_cassette(str(tmpdir.join('nonexistent', 'cassette.yml'))):
urllib2.urlopen('http://httpbin.org/').read()
# This should have made the file and the directory
assert os.path.exists(str(tmpdir.join('nonexistent','cassette.yml')))
assert os.path.exists(str(tmpdir.join('nonexistent', 'cassette.yml')))
def test_unpatch(tmpdir):
'''Ensure that our cassette gets unpatched when we're done'''
@@ -30,51 +32,69 @@ def test_unpatch(tmpdir):
urllib2.urlopen('http://httpbin.org/').read()
assert cass.play_count == 0
def test_basic_use(tmpdir):
'''
Copied from the docs
Copied from the docs
'''
with vcr.use_cassette('fixtures/vcr_cassettes/synopsis.yaml'):
response = urllib2.urlopen('http://www.iana.org/domains/reserved').read()
response = urllib2.urlopen(
'http://www.iana.org/domains/reserved'
).read()
assert 'Example domains' in response
def test_basic_json_use(tmpdir):
'''Ensure you can load a json serialized cassette'''
with vcr.use_cassette('fixtures/vcr_cassettes/synopsis.json', serializer='json'):
response = urllib2.urlopen('http://www.iana.org/domains/reserved').read()
assert 'Example domains' in response
'''
Ensure you can load a json serialized cassette
'''
test_fixture = 'fixtures/vcr_cassettes/synopsis.json'
with vcr.use_cassette(test_fixture, serializer='json'):
response = urllib2.urlopen('http://httpbin.org/').read()
assert 'difficult sometimes' in response
def test_patched_content(tmpdir):
'''Ensure that what you pull from a cassette is what came from the request'''
'''
Ensure that what you pull from a cassette is what came from the
request
'''
with vcr.use_cassette(str(tmpdir.join('synopsis.yaml'))) as cass:
response = urllib2.urlopen('http://www.iana.org/domains/reserved').read()
response = urllib2.urlopen('http://httpbin.org/').read()
assert cass.play_count == 0
with vcr.use_cassette(str(tmpdir.join('synopsis.yaml'))) as cass:
response2 = urllib2.urlopen('http://www.iana.org/domains/reserved').read()
response2 = urllib2.urlopen('http://httpbin.org/').read()
assert cass.play_count == 1
cass._save(force=True)
with vcr.use_cassette(str(tmpdir.join('synopsis.yaml'))) as cass:
response3 = urllib2.urlopen('http://www.iana.org/domains/reserved').read()
response3 = urllib2.urlopen('http://httpbin.org/').read()
assert cass.play_count == 1
assert response == response2
assert response2 == response3
def test_patched_content_json(tmpdir):
'''Ensure that what you pull from a json cassette is what came from the request'''
with vcr.use_cassette(str(tmpdir.join('synopsis.json')), serializer='json') as cass:
response = urllib2.urlopen('http://www.iana.org/domains/reserved').read()
'''
Ensure that what you pull from a json cassette is what came from the
request
'''
testfile = str(tmpdir.join('synopsis.json'))
with vcr.use_cassette(testfile) as cass:
response = urllib2.urlopen('http://httpbin.org/').read()
assert cass.play_count == 0
with vcr.use_cassette(str(tmpdir.join('synopsis.json')), serializer='json') as cass:
response2 = urllib2.urlopen('http://www.iana.org/domains/reserved').read()
with vcr.use_cassette(testfile) as cass:
response2 = urllib2.urlopen('http://httpbin.org/').read()
assert cass.play_count == 1
cass._save(force=True)
with vcr.use_cassette(str(tmpdir.join('synopsis.json')), serializer='json') as cass:
response3 = urllib2.urlopen('http://www.iana.org/domains/reserved').read()
with vcr.use_cassette(testfile) as cass:
response3 = urllib2.urlopen('http://httpbin.org/').read()
assert cass.play_count == 1
assert response == response2