def test_report_empty_call():
    # This test is a coverage failsafe to make sure that totally empty calls,
    # i.e. request == None and no flattened fields passed, work.
    client = ServiceControllerClient(
        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
    )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.report), "__call__") as call:
        client.report()
        call.assert_called()
        _, args, _ = call.mock_calls[0]
        assert args[0] == service_controller.ReportRequest()
Ejemplo n.º 2
0
def test_service_controller_host_no_port():
    client = ServiceControllerClient(
        credentials=credentials.AnonymousCredentials(),
        client_options=client_options.ClientOptions(
            api_endpoint="servicecontrol.googleapis.com"),
    )
    assert client.transport._host == "servicecontrol.googleapis.com:443"
Ejemplo n.º 3
0
def test_common_organization_path():
    organization = "oyster"

    expected = "organizations/{organization}".format(
        organization=organization, )
    actual = ServiceControllerClient.common_organization_path(organization)
    assert expected == actual
def test_transport_instance():
    # A client may be instantiated with a custom transport instance.
    transport = transports.ServiceControllerGrpcTransport(
        credentials=ga_credentials.AnonymousCredentials(),
    )
    client = ServiceControllerClient(transport=transport)
    assert client.transport is transport
def test_common_location_path():
    project = "winkle"
    location = "nautilus"
    expected = "projects/{project}/locations/{location}".format(
        project=project, location=location,
    )
    actual = ServiceControllerClient.common_location_path(project, location)
    assert expected == actual
Ejemplo n.º 6
0
def test_service_controller_auth_adc():
    # If no credentials are provided, we should use ADC credentials.
    with mock.patch.object(auth, "default") as adc:
        adc.return_value = (credentials.AnonymousCredentials(), None)
        ServiceControllerClient()
        adc.assert_called_once_with(
            scopes=(
                "https://www.googleapis.com/auth/cloud-platform",
                "https://www.googleapis.com/auth/servicecontrol",
            ),
            quota_project_id=None,
        )
def test__get_default_mtls_endpoint():
    api_endpoint = "example.googleapis.com"
    api_mtls_endpoint = "example.mtls.googleapis.com"
    sandbox_endpoint = "example.sandbox.googleapis.com"
    sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com"
    non_googleapi = "api.example.com"

    assert ServiceControllerClient._get_default_mtls_endpoint(None) is None
    assert (
        ServiceControllerClient._get_default_mtls_endpoint(api_endpoint)
        == api_mtls_endpoint
    )
    assert (
        ServiceControllerClient._get_default_mtls_endpoint(api_mtls_endpoint)
        == api_mtls_endpoint
    )
    assert (
        ServiceControllerClient._get_default_mtls_endpoint(sandbox_endpoint)
        == sandbox_mtls_endpoint
    )
    assert (
        ServiceControllerClient._get_default_mtls_endpoint(sandbox_mtls_endpoint)
        == sandbox_mtls_endpoint
    )
    assert (
        ServiceControllerClient._get_default_mtls_endpoint(non_googleapi)
        == non_googleapi
    )