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

update tests

This commit is contained in:
Kevin McCarthy
2013-08-10 16:18:27 -10:00
parent d76c9994a7
commit 1a73334b50

View File

@@ -1,34 +1,32 @@
'''Basic tests about cassettes''' '''Basic tests about cassettes'''
# coding=utf-8 # coding=utf-8
# Internal imports
import vcr
from .common import TestVCR
# External imports # External imports
import os import os
import urllib2 import urllib2
# Internal imports
import vcr
class TestCassette(TestVCR): def test_nonexistent_directory(tmpdir):
'''We should be able to save a cassette''' '''If we load a cassette in a nonexistent directory, it can save ok'''
fixtures = os.path.join('tests', 'fixtures', 'basic') # Check to make sure directory doesnt exist
assert not os.path.exists(str(tmpdir.join('nonexistent')))
def test_nonexistent_directory(self): # Run VCR to create dir and cassette file
'''If we load a cassette in a nonexistent directory, it can save ok''' with vcr.use_cassette(str(tmpdir.join('nonexistent','cassette.yml'))):
self.assertFalse(os.path.exists(self.fixture('nonexistent')))
with vcr.use_cassette(self.fixture('nonexistent', 'cass.yaml')):
urllib2.urlopen('http://httpbin.org/').read()
# This should have made the file and the directory
self.assertTrue(
os.path.exists(self.fixture('nonexistent', 'cass.yaml')))
def test_unpatch(self):
'''Ensure that our cassette gets unpatched when we're done'''
with vcr.use_cassette(self.fixture('unpatch.yaml')) as cass:
urllib2.urlopen('http://httpbin.org/').read()
# Make the same requests, and assert that we haven't served any more
# requests out of cache
urllib2.urlopen('http://httpbin.org/').read() urllib2.urlopen('http://httpbin.org/').read()
self.assertEqual(cass.play_count, 0)
# This should have made the file and the directory
assert os.path.exists(str(tmpdir.join('nonexistent','cassette.yml')))
def test_unpatch(tmpdir):
'''Ensure that our cassette gets unpatched when we're done'''
with vcr.use_cassette(str(tmpdir.join('unpatch.yaml'))) as cass:
urllib2.urlopen('http://httpbin.org/').read()
# Make the same request, and assert that we haven't served any more
# requests out of cache
urllib2.urlopen('http://httpbin.org/').read()
assert cass.play_count == 0