1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-09 09:13:23 +00:00
Files
vcrpy/tests/unit/test_cassettes.py
Kevin McCarthy 188b57a2fa Fix API by adding 'responses_of' method
`responses_of` replaces `response_of`, since each request can have
several matching responses now.

This breaks backwards compatibility if you are using the
response_of method, so a version bump will be required.
2013-12-01 14:26:35 -10:00

66 lines
1.6 KiB
Python

import pytest
import yaml
import mock
from vcr.cassette import Cassette
def test_cassette_load(tmpdir):
a_file = tmpdir.join('test_cassette.yml')
a_file.write(yaml.dump([
{'request': 'foo', 'response': 'bar'}
]))
a_cassette = Cassette.load(str(a_file))
assert len(a_cassette) == 1
def test_cassette_not_played():
a = Cassette('test')
assert not a.play_count
def test_cassette_append():
a = Cassette('test')
a.append('foo', 'bar')
assert a.requests == ['foo']
assert a.responses == ['bar']
def test_cassette_len():
a = Cassette('test')
a.append('foo', 'bar')
a.append('foo2', 'bar2')
assert len(a) == 2
def _mock_requests_match(request1, request2, matchers):
return request1 == request2
@mock.patch('vcr.cassette.requests_match', _mock_requests_match)
def test_cassette_contains():
a = Cassette('test')
a.append('foo', 'bar')
assert 'foo' in a
@mock.patch('vcr.cassette.requests_match', _mock_requests_match)
def test_cassette_responses_of():
a = Cassette('test')
a.append('foo', 'bar')
assert a.responses_of('foo') == ['bar']
@mock.patch('vcr.cassette.requests_match', _mock_requests_match)
def test_cassette_get_missing_response():
a = Cassette('test')
with pytest.raises(KeyError):
a.responses_of('foo')
@mock.patch('vcr.cassette.requests_match', _mock_requests_match)
def test_cassette_cant_read_same_request_twice():
a = Cassette('test')
a.append('foo','bar')
a.play_response('foo')
with pytest.raises(KeyError):
a.play_response('foo')