コード例 #1
0
def test_ad_group_criterion_service_transport_auth_adc():
    # If credentials and host are not provided, the transport class should use
    # ADC credentials.
    with mock.patch.object(google.auth, 'default') as adc:
        adc.return_value = (ga_credentials.AnonymousCredentials(), None)
        transports.AdGroupCriterionServiceGrpcTransport(
            host="squid.clam.whelk")
        adc.assert_called_once_with(
            scopes=('https://www.googleapis.com/auth/adwords', ))
コード例 #2
0
def test_credentials_transport_error():
    # It is an error to provide credentials and a transport instance.
    transport = transports.AdGroupCriterionServiceGrpcTransport(
        credentials=ga_credentials.AnonymousCredentials(), )
    with pytest.raises(ValueError):
        client = AdGroupCriterionServiceClient(
            credentials=ga_credentials.AnonymousCredentials(),
            transport=transport,
        )
コード例 #3
0
def test_ad_group_criterion_service_grpc_transport_channel():
    channel = grpc.insecure_channel('http://localhost/')

    # Check that channel is used if provided.
    transport = transports.AdGroupCriterionServiceGrpcTransport(
        host="squid.clam.whelk",
        channel=channel,
    )
    assert transport.grpc_channel == channel
    assert transport._host == "squid.clam.whelk:443"
    assert transport._ssl_channel_credentials == None
コード例 #4
0
def test_transport_get_channel():
    # A client may be instantiated with a custom transport instance.
    transport = transports.AdGroupCriterionServiceGrpcTransport(
        credentials=ga_credentials.AnonymousCredentials(), )
    channel = transport.grpc_channel
    assert channel
コード例 #5
0
def test_transport_instance():
    # A client may be instantiated with a custom transport instance.
    transport = transports.AdGroupCriterionServiceGrpcTransport(
        credentials=ga_credentials.AnonymousCredentials(), )
    client = AdGroupCriterionServiceClient(transport=transport)
    assert client.transport is transport
コード例 #6
0
def test_ad_group_criterion_service_client_client_options():
    # Check that if channel is provided we won't create a new one.
    with mock.patch(
            'google.ads.googleads.v8.services.services.ad_group_criterion_service.AdGroupCriterionServiceClient.get_transport_class'
    ) as gtc:
        transport = transports.AdGroupCriterionServiceGrpcTransport(
            credentials=ga_credentials.AnonymousCredentials())
        client = AdGroupCriterionServiceClient(transport=transport)
        gtc.assert_not_called()

    # Check that if channel is provided via str we will create a new one.
    with mock.patch(
            'google.ads.googleads.v8.services.services.ad_group_criterion_service.AdGroupCriterionServiceClient.get_transport_class'
    ) as gtc:
        client = AdGroupCriterionServiceClient(transport="grpc")
        gtc.assert_called()

    # Check the case api_endpoint is provided.
    options = client_options.ClientOptions(api_endpoint="squid.clam.whelk")
    with mock.patch(
            'google.ads.googleads.v8.services.services.ad_group_criterion_service.transports.AdGroupCriterionServiceGrpcTransport.__init__'
    ) as grpc_transport:
        grpc_transport.return_value = None
        client = AdGroupCriterionServiceClient(client_options=options)
        grpc_transport.assert_called_once_with(
            ssl_channel_credentials=None,
            credentials=None,
            host="squid.clam.whelk",
            client_info=transports.base.DEFAULT_CLIENT_INFO,
        )

    # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT
    # is "never".
    with mock.patch.dict(os.environ,
                         {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}):
        with mock.patch(
                'google.ads.googleads.v8.services.services.ad_group_criterion_service.transports.AdGroupCriterionServiceGrpcTransport.__init__'
        ) as grpc_transport:
            grpc_transport.return_value = None
            client = AdGroupCriterionServiceClient()
            grpc_transport.assert_called_once_with(
                ssl_channel_credentials=None,
                credentials=None,
                host=client.DEFAULT_ENDPOINT,
                client_info=transports.base.DEFAULT_CLIENT_INFO,
            )

    # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
    # "always".
    with mock.patch.dict(os.environ,
                         {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}):
        with mock.patch(
                'google.ads.googleads.v8.services.services.ad_group_criterion_service.transports.AdGroupCriterionServiceGrpcTransport.__init__'
        ) as grpc_transport:
            grpc_transport.return_value = None
            client = AdGroupCriterionServiceClient()
            grpc_transport.assert_called_once_with(
                ssl_channel_credentials=None,
                credentials=None,
                host=client.DEFAULT_MTLS_ENDPOINT,
                client_info=transports.base.DEFAULT_CLIENT_INFO,
            )

    # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
    # unsupported value.
    with mock.patch.dict(os.environ,
                         {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}):
        with pytest.raises(MutualTLSChannelError):
            client = AdGroupCriterionServiceClient()

    # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value.
    with mock.patch.dict(os.environ,
                         {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}):
        with pytest.raises(ValueError):
            client = AdGroupCriterionServiceClient()