Example #1
0
def test_credentials_transport_error():
    # It is an error to provide credentials and a transport instance.
    transport = transports.RoutesRestTransport(
        credentials=ga_credentials.AnonymousCredentials(),
    )
    with pytest.raises(ValueError):
        client = RoutesClient(
            credentials=ga_credentials.AnonymousCredentials(), transport=transport,
        )

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

    # It is an error to provide scopes and a transport instance.
    transport = transports.RoutesRestTransport(
        credentials=ga_credentials.AnonymousCredentials(),
    )
    with pytest.raises(ValueError):
        client = RoutesClient(
            client_options={"scopes": ["1", "2"]}, transport=transport,
        )
Example #2
0
def test_transport_instance():
    # A client may be instantiated with a custom transport instance.
    transport = transports.RoutesRestTransport(
        credentials=ga_credentials.AnonymousCredentials(),
    )
    client = RoutesClient(transport=transport)
    assert client.transport is transport
Example #3
0
def test_routes_http_transport_client_cert_source_for_mtls():
    cred = ga_credentials.AnonymousCredentials()
    with mock.patch(
        "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"
    ) as mock_configure_mtls_channel:
        transports.RoutesRestTransport(
            credentials=cred, client_cert_source_for_mtls=client_cert_source_callback
        )
        mock_configure_mtls_channel.assert_called_once_with(client_cert_source_callback)