当前位置: 首页>>代码示例>>Python>>正文


Python cassette.Cassette类代码示例

本文整理汇总了Python中vcr.cassette.Cassette的典型用法代码示例。如果您正苦于以下问题:Python Cassette类的具体用法?Python Cassette怎么用?Python Cassette使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Cassette类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_before_record_response

def test_before_record_response():
    before_record_response = mock.Mock(return_value='mutated')
    cassette = Cassette('test', before_record_response=before_record_response)
    cassette.append('req', 'res')

    before_record_response.assert_called_once_with('res')
    assert cassette.responses[0] == 'mutated'
开发者ID:IvanMalison,项目名称:vcrpy,代码行数:7,代码来源:test_cassettes.py

示例2: test_serialize_cassette

 def test_serialize_cassette(self):
     c1 = Cassette()
     c1.requests = ['a', 'b', 'c']
     c1.responses = ['d', 'e', 'f']
     ser = c1.serialize()
     c2 = Cassette(ser)
     self.assertEqual(c1.requests, c2.requests)
     self.assertEqual(c1.responses, c2.responses)
开发者ID:sriprasanna,项目名称:vcrpy,代码行数:8,代码来源:test.py

示例3: test_nesting_context_managers_by_checking_references_of_http_connection

def test_nesting_context_managers_by_checking_references_of_http_connection():
    original = httplib.HTTPConnection
    with Cassette.use(path='test'):
        first_cassette_HTTPConnection = httplib.HTTPConnection
        with Cassette.use(path='test'):
            second_cassette_HTTPConnection = httplib.HTTPConnection
            assert second_cassette_HTTPConnection is not first_cassette_HTTPConnection
            with Cassette.use(path='test'):
                assert httplib.HTTPConnection is not second_cassette_HTTPConnection
                with force_reset():
                    assert httplib.HTTPConnection is original
            assert httplib.HTTPConnection is second_cassette_HTTPConnection
        assert httplib.HTTPConnection is first_cassette_HTTPConnection
开发者ID:IvanMalison,项目名称:vcrpy,代码行数:13,代码来源:test_cassettes.py

示例4: test_cassette_load

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
开发者ID:chromy,项目名称:vcrpy,代码行数:7,代码来源:test_cassettes.py

示例5: test_cassette_load

def test_cassette_load(tmpdir):
    a_file = tmpdir.join('test_cassette.yml')
    a_file.write(yaml.dump({'interactions': [
        {'request': {'body': '', 'uri': 'foo', 'method': 'GET', 'headers': {}},
         'response': 'bar'}
    ]}))
    a_cassette = Cassette.load(path=str(a_file))
    assert len(a_cassette) == 1
开发者ID:IvanMalison,项目名称:vcrpy,代码行数:8,代码来源:test_cassettes.py

示例6: test_custom_patchers

def test_custom_patchers():
    class Test(object):
        attribute = None

    with Cassette.use(path="custom_patches", custom_patches=((Test, "attribute", VCRHTTPSConnection),)):
        assert issubclass(Test.attribute, VCRHTTPSConnection)
        assert VCRHTTPSConnection is not Test.attribute
        old_attribute = Test.attribute

        with Cassette.use(path="custom_patches", custom_patches=((Test, "attribute", VCRHTTPSConnection),)):
            assert issubclass(Test.attribute, VCRHTTPSConnection)
            assert VCRHTTPSConnection is not Test.attribute
            assert Test.attribute is not old_attribute

        assert issubclass(Test.attribute, VCRHTTPSConnection)
        assert VCRHTTPSConnection is not Test.attribute
        assert Test.attribute is old_attribute
开发者ID:teury,项目名称:vcrpy,代码行数:17,代码来源:test_cassettes.py

示例7: test_nesting_cassette_context_managers

def test_nesting_cassette_context_managers(*args):
    first_response = {"body": {"string": b"first_response"}, "headers": {}, "status": {"message": "m", "code": 200}}

    second_response = copy.deepcopy(first_response)
    second_response["body"]["string"] = b"second_response"

    with contextlib.ExitStack() as exit_stack:
        first_cassette = exit_stack.enter_context(Cassette.use(path="test"))
        exit_stack.enter_context(mock.patch.object(first_cassette, "play_response", return_value=first_response))
        assert_get_response_body_is("first_response")

        # Make sure a second cassette can supercede the first
        with Cassette.use(path="test") as second_cassette:
            with mock.patch.object(second_cassette, "play_response", return_value=second_response):
                assert_get_response_body_is("second_response")

        # Now the first cassette should be back in effect
        assert_get_response_body_is("first_response")
开发者ID:teury,项目名称:vcrpy,代码行数:18,代码来源:test_cassettes.py

示例8: test_nesting_cassette_context_managers

def test_nesting_cassette_context_managers(*args):
    first_response = {'body': {'string': b'first_response'}, 'headers': {},
                      'status': {'message': 'm', 'code': 200}}

    second_response = copy.deepcopy(first_response)
    second_response['body']['string'] = b'second_response'

    with contextlib.ExitStack() as exit_stack:
        first_cassette = exit_stack.enter_context(Cassette.use(path='test'))
        exit_stack.enter_context(mock.patch.object(first_cassette, 'play_response',
                                                    return_value=first_response))
        assert_get_response_body_is('first_response')

        # Make sure a second cassette can supercede the first
        with Cassette.use(path='test') as second_cassette:
            with mock.patch.object(second_cassette, 'play_response', return_value=second_response):
                assert_get_response_body_is('second_response')

        # Now the first cassette should be back in effect
        assert_get_response_body_is('first_response')
开发者ID:IvanMalison,项目名称:vcrpy,代码行数:20,代码来源:test_cassettes.py

示例9: test_cassette_load

def test_cassette_load(tmpdir):
    a_file = tmpdir.join("test_cassette.yml")
    a_file.write(
        yaml.dump(
            {
                "interactions": [
                    {"request": {"body": "", "uri": "foo", "method": "GET", "headers": {}}, "response": "bar"}
                ]
            }
        )
    )
    a_cassette = Cassette.load(path=str(a_file))
    assert len(a_cassette) == 1
开发者ID:teury,项目名称:vcrpy,代码行数:13,代码来源:test_cassettes.py

示例10: test_arg_getter_functionality

def test_arg_getter_functionality():
    arg_getter = mock.Mock(return_value={"path": "test"})
    context_decorator = Cassette.use_arg_getter(arg_getter)

    with context_decorator as cassette:
        assert cassette._path == "test"

    arg_getter.return_value = {"path": "other"}

    with context_decorator as cassette:
        assert cassette._path == "other"

    arg_getter.return_value = {"path": "other", "filter_headers": ("header_name",)}

    @context_decorator
    def function():
        pass

    with mock.patch.object(Cassette, "load", return_value=mock.MagicMock(inject=False)) as cassette_load:
        function()
        cassette_load.assert_called_once_with(**arg_getter.return_value)
开发者ID:teury,项目名称:vcrpy,代码行数:21,代码来源:test_cassettes.py

示例11: test_arg_getter_functionality

def test_arg_getter_functionality():
    arg_getter = mock.Mock(return_value={'path': 'test'})
    context_decorator = Cassette.use_arg_getter(arg_getter)

    with context_decorator as cassette:
        assert cassette._path == 'test'

    arg_getter.return_value = {'path': 'other'}

    with context_decorator as cassette:
        assert cassette._path == 'other'

    arg_getter.return_value = {'path': 'other', 'filter_headers': ('header_name',)}

    @context_decorator
    def function():
        pass

    with mock.patch.object(
        Cassette, 'load',
        return_value=mock.MagicMock(inject=False)
    ) as cassette_load:
        function()
        cassette_load.assert_called_once_with(**arg_getter.return_value)
开发者ID:IvanMalison,项目名称:vcrpy,代码行数:24,代码来源:test_cassettes.py

示例12: test_cassette_cant_read_same_request_twice

def test_cassette_cant_read_same_request_twice():
    a = Cassette('test')
    a.append('foo', 'bar')
    a.play_response('foo')
    with pytest.raises(UnhandledHTTPRequestError):
        a.play_response('foo')
开发者ID:IvanMalison,项目名称:vcrpy,代码行数:6,代码来源:test_cassettes.py

示例13: test_cassette_responses_of

def test_cassette_responses_of():
    a = Cassette('test')
    a.append('foo', 'bar')
    assert a.responses_of('foo') == ['bar']
开发者ID:IvanMalison,项目名称:vcrpy,代码行数:4,代码来源:test_cassettes.py

示例14: test_cassette_get_missing_response

def test_cassette_get_missing_response():
    a = Cassette('test')
    with pytest.raises(UnhandledHTTPRequestError):
        a.responses_of('foo')
开发者ID:IvanMalison,项目名称:vcrpy,代码行数:4,代码来源:test_cassettes.py

示例15: test_cassette_len

def test_cassette_len():
    a = Cassette('test')
    a.append('foo', 'bar')
    a.append('foo2', 'bar2')
    assert len(a) == 2
开发者ID:IvanMalison,项目名称:vcrpy,代码行数:5,代码来源:test_cassettes.py


注:本文中的vcr.cassette.Cassette类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。