Пример #1
0
def test_credentials_transport_error():
    # It is an error to provide credentials and a transport instance.
    transport = transports.ImageAnnotatorGrpcTransport(
        credentials=credentials.AnonymousCredentials(), )
    with pytest.raises(ValueError):
        client = ImageAnnotatorClient(
            credentials=credentials.AnonymousCredentials(),
            transport=transport,
        )

    # It is an error to provide a credentials file and a transport instance.
    transport = transports.ImageAnnotatorGrpcTransport(
        credentials=credentials.AnonymousCredentials(), )
    with pytest.raises(ValueError):
        client = ImageAnnotatorClient(
            client_options={"credentials_file": "credentials.json"},
            transport=transport,
        )

    # It is an error to provide scopes and a transport instance.
    transport = transports.ImageAnnotatorGrpcTransport(
        credentials=credentials.AnonymousCredentials(), )
    with pytest.raises(ValueError):
        client = ImageAnnotatorClient(
            client_options={"scopes": ["1", "2"]},
            transport=transport,
        )
Пример #2
0
def test_transport_instance():
    # A client may be instantiated with a custom transport instance.
    transport = transports.ImageAnnotatorGrpcTransport(
        credentials=credentials.AnonymousCredentials(),
    )
    client = ImageAnnotatorClient(transport=transport)
    assert client.transport is transport
Пример #3
0
def test_image_annotator_grpc_transport_channel():
    channel = grpc.insecure_channel("http://localhost/")

    # Check that channel is used if provided.
    transport = transports.ImageAnnotatorGrpcTransport(
        host="squid.clam.whelk",
        channel=channel,
    )
    assert transport.grpc_channel == channel
    assert transport._host == "squid.clam.whelk:443"
Пример #4
0
def test_transport_get_channel():
    # A client may be instantiated with a custom transport instance.
    transport = transports.ImageAnnotatorGrpcTransport(
        credentials=credentials.AnonymousCredentials(), )
    channel = transport.grpc_channel
    assert channel

    transport = transports.ImageAnnotatorGrpcAsyncIOTransport(
        credentials=credentials.AnonymousCredentials(), )
    channel = transport.grpc_channel
    assert channel
Пример #5
0
def test_image_annotator_transport_auth_adc():
    # If credentials and host are not provided, the transport class should use
    # ADC credentials.
    with mock.patch.object(auth, "default") as adc:
        adc.return_value = (credentials.AnonymousCredentials(), None)
        transports.ImageAnnotatorGrpcTransport(host="squid.clam.whelk",
                                               quota_project_id="octopus")
        adc.assert_called_once_with(
            scopes=(
                "https://www.googleapis.com/auth/cloud-platform",
                "https://www.googleapis.com/auth/cloud-vision",
            ),
            quota_project_id="octopus",
        )