def test_record_success_thrift(tmpdir, thrift_service, mock_server): myservice = thrift_request_builder('myservice', thrift_service, hostport=mock_server.hostport) path = tmpdir.join('data.yaml') expected_item = thrift_service.Item( 'foo', thrift_service.Value(stringValue='bar')) mock_server.expect_call(thrift_service, method='getItem').and_result(expected_item).once() client = TChannel('test') with vcr.use_cassette(str(path)) as cass: response = client.thrift(myservice.getItem('foo')).result(1) item = response.body assert item == expected_item assert cass.play_count == 0 assert path.check(file=True) with vcr.use_cassette(str(path)) as cass: response = client.thrift(myservice.getItem('foo')).result(1) item = response.body assert item == expected_item assert cass.play_count == 1
def test_record_thrift_exception(tmpdir, mock_server, thrift_service): path = tmpdir.join('data.yaml') myservice = thrift_request_builder( 'myservice', thrift_service, hostport=mock_server.hostport ) mock_server.expect_call(thrift_service, method='getItem').and_raise( thrift_service.ItemDoesNotExist('foo') ).once() client = TChannel('test') with vcr.use_cassette(str(path)) as cass: with pytest.raises(thrift_service.ItemDoesNotExist): client.thrift(myservice.getItem('foo')).result(1) assert cass.play_count == 0 assert path.check(file=True) with vcr.use_cassette(str(path)) as cass: with pytest.raises(thrift_service.ItemDoesNotExist): client.thrift(myservice.getItem('foo')).result(1) assert cass.play_count == 1
def test_record_success_thrift(tmpdir, thrift_service, mock_server): myservice = thrift_request_builder( 'myservice', thrift_service, hostport=mock_server.hostport ) path = tmpdir.join('data.yaml') expected_item = thrift_service.Item( 'foo', thrift_service.Value(stringValue='bar') ) mock_server.expect_call(thrift_service, method='getItem').and_result( expected_item ).once() client = TChannel('test') with vcr.use_cassette(str(path)) as cass: response = client.thrift(myservice.getItem('foo')).result(1) item = response.body assert item == expected_item assert cass.play_count == 0 assert path.check(file=True) with vcr.use_cassette(str(path)) as cass: response = client.thrift(myservice.getItem('foo')).result(1) item = response.body assert item == expected_item assert cass.play_count == 1
def thrift_client(thrift_service, mock_server, use_old_api): if use_old_api: from tchannel.tornado import TChannel return client_for('myservice', thrift_service)( tchannel=TChannel('thrift-client'), hostport=mock_server.hostport, ) else: from tchannel import TChannel from tchannel.thrift import thrift_request_builder myservice = thrift_request_builder('myservice', thrift_service, hostport=mock_server.hostport) return mk_fake_client(TChannel('thrift-client'), myservice)
def thrift_client(thrift_service, mock_server, use_old_api): if use_old_api: from tchannel.tornado import TChannel return client_for('myservice', thrift_service)( tchannel=TChannel('thrift-client'), hostport=mock_server.hostport, ) else: from tchannel import TChannel from tchannel.thrift import thrift_request_builder myservice = thrift_request_builder( 'myservice', thrift_service, hostport=mock_server.hostport ) return mk_fake_client( TChannel('thrift-client'), myservice )