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

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

    # It is an error to provide scopes and a transport instance.
    transport = transports.ZoneOperationsRestTransport(
        credentials=ga_credentials.AnonymousCredentials(), )
    with pytest.raises(ValueError):
        client = ZoneOperationsClient(
            client_options={"scopes": ["1", "2"]},
            transport=transport,
        )
def test_transport_instance():
    # A client may be instantiated with a custom transport instance.
    transport = transports.ZoneOperationsRestTransport(
        credentials=ga_credentials.AnonymousCredentials(),
    )
    client = ZoneOperationsClient(transport=transport)
    assert client.transport is transport
def test_zone_operations_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.ZoneOperationsRestTransport(
            credentials=cred, client_cert_source_for_mtls=client_cert_source_callback
        )
        mock_configure_mtls_channel.assert_called_once_with(client_cert_source_callback)