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

fix tests

This commit is contained in:
Parker Hancock
2023-12-08 10:49:29 -06:00
committed by Jair Henrique
parent e8e9a4af9f
commit f5fc7aac22
14 changed files with 101 additions and 112 deletions

View File

@@ -8,12 +8,12 @@ import vcr
@pytest.mark.online
def test_set_serializer_default_config(tmpdir, mockbin_request_url):
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(mockbin_request_url)
urlopen(httpbin.url)
with open(str(tmpdir.join("test.json"))) as f:
file_content = f.read()
@@ -22,37 +22,37 @@ def test_set_serializer_default_config(tmpdir, mockbin_request_url):
@pytest.mark.online
def test_default_set_cassette_library_dir(tmpdir, mockbin_request_url):
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(mockbin_request_url)
urlopen(httpbin.url)
assert os.path.exists(str(tmpdir.join("subdir").join("test.json")))
@pytest.mark.online
def test_override_set_cassette_library_dir(tmpdir, mockbin_request_url):
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(mockbin_request_url)
urlopen(httpbin.url)
assert os.path.exists(str(tmpdir.join("subdir2").join("test.json")))
assert not os.path.exists(str(tmpdir.join("subdir").join("test.json")))
@pytest.mark.online
def test_override_match_on(tmpdir, mockbin_request_url):
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(mockbin_request_url)
urlopen(httpbin.url)
with my_vcr.use_cassette(str(tmpdir.join("test.json"))) as cass:
urlopen(mockbin_request_url)
urlopen(httpbin.url)
assert len(cass) == 1
assert cass.play_count == 1
@@ -67,12 +67,12 @@ def test_missing_matcher():
@pytest.mark.online
def test_dont_record_on_exception(tmpdir, mockbin_request_url):
def test_dont_record_on_exception(tmpdir, httpbin):
my_vcr = vcr.VCR(record_on_exception=False)
@my_vcr.use_cassette(str(tmpdir.join("dontsave.yml")))
def some_test():
assert b"Not in content" in urlopen(mockbin_request_url)
assert b"Not in content" in urlopen(httpbin.url)
with pytest.raises(AssertionError):
some_test()
@@ -82,6 +82,6 @@ def test_dont_record_on_exception(tmpdir, mockbin_request_url):
# Make sure context decorator has the same behavior
with pytest.raises(AssertionError):
with my_vcr.use_cassette(str(tmpdir.join("dontsave2.yml"))):
assert b"Not in content" in urlopen(mockbin_request_url).read()
assert b"Not in content" in urlopen(httpbin.url).read()
assert not os.path.exists(str(tmpdir.join("dontsave2.yml")))