コード例 #1
0
def test_record(vcr_service, cassette, call, mock_server, use_known_peers):
    allow(cassette).can_replay.and_return(False)
    expect(cassette).record.with_args(
        proxy.Request(
            serviceName='service',
            endpoint='endpoint',
            headers='headers',
            body='body',
            knownPeers=[mock_server.hostport] if use_known_peers else [],
            hostPort='' if use_known_peers else mock_server.hostport,
        ),
        proxy.Response(
            code=0,
            headers='response headers',
            body='response body',
        ),
    )

    mock_server.expect_call('endpoint').and_write(
        headers='response headers',
        body='response body',
    ).once()

    response = yield call(
        service='service',
        endpoint='endpoint',
        headers='headers',
        body='body',
    )

    assert response.body.headers == 'response headers'
    assert response.body.body == 'response body'
コード例 #2
0
def test_no_peers(vcr_service, cassette, vcr_hostport):
    allow(cassette).can_replay.and_return(False)
    vcr_request = proxy.Request(
        serviceName='hello_service',
        endpoint='hello',
        headers='',
        body='body',
    )
    with pytest.raises(proxy.NoPeersAvailableError):
        yield TChannel('foo').thrift(
            proxy.VCRProxy.send(vcr_request),
            hostport=vcr_hostport,
        )
コード例 #3
0
 def f(endpoint, body, headers=None, service=None):
     kwargs = {
         'serviceName': service or '',
         'endpoint': endpoint,
         'headers': headers or '',
         'body': body,
     }
     if use_known_peers:
         kwargs['knownPeers'] = [mock_server.hostport]
     else:
         kwargs['hostPort'] = mock_server.hostport
     vcr_request = proxy.Request(**kwargs)
     return tchannel.thrift(
         proxy.VCRProxy.send(vcr_request),
         hostport=vcr_hostport,
     )