예제 #1
0
def test_list_rest_flattened():
    client = GlobalOrganizationOperationsClient(
        credentials=ga_credentials.AnonymousCredentials(), )

    # Mock the http request call within the method and fake a response.
    with mock.patch.object(Session, "request") as req:
        # Designate an appropriate value for the returned response.
        return_value = compute.OperationList()

        # Wrap the value into a proper Response obj
        json_return_value = compute.OperationList.to_json(return_value)
        response_value = Response()
        response_value.status_code = 200
        response_value._content = json_return_value.encode("UTF-8")
        req.return_value = response_value

        # Call the method with a truthy value for each flattened field,
        # using the keyword arguments to the method.
        client.list()

        # Establish that the underlying call was made with the expected
        # request object values.
        assert len(req.mock_calls) == 1
        _, http_call, http_params = req.mock_calls[0]
        body = http_params.get("data")
        params = http_params.get("params")
예제 #2
0
def test_credentials_transport_error():
    # It is an error to provide credentials and a transport instance.
    transport = transports.GlobalOrganizationOperationsRestTransport(
        credentials=ga_credentials.AnonymousCredentials(), )
    with pytest.raises(ValueError):
        client = GlobalOrganizationOperationsClient(
            credentials=ga_credentials.AnonymousCredentials(),
            transport=transport,
        )

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

    # It is an error to provide scopes and a transport instance.
    transport = transports.GlobalOrganizationOperationsRestTransport(
        credentials=ga_credentials.AnonymousCredentials(), )
    with pytest.raises(ValueError):
        client = GlobalOrganizationOperationsClient(
            client_options={"scopes": ["1", "2"]},
            transport=transport,
        )
예제 #3
0
def test_delete_rest(
    transport: str = "rest",
    request_type=compute.DeleteGlobalOrganizationOperationRequest,
):
    client = GlobalOrganizationOperationsClient(
        credentials=ga_credentials.AnonymousCredentials(),
        transport=transport,
    )

    # Everything is optional in proto3 as far as the runtime is concerned,
    # and we are mocking out the actual API, so just send an empty request.
    request = request_type()

    # Mock the http request call within the method and fake a response.
    with mock.patch.object(Session, "request") as req:
        # Designate an appropriate value for the returned response.
        return_value = compute.DeleteGlobalOrganizationOperationResponse()

        # Wrap the value into a proper Response obj
        json_return_value = compute.DeleteGlobalOrganizationOperationResponse.to_json(
            return_value)
        response_value = Response()
        response_value.status_code = 200
        response_value._content = json_return_value.encode("UTF-8")
        req.return_value = response_value
        response = client.delete(request)

    # Establish that the response is the type that we expect.
    assert isinstance(response,
                      compute.DeleteGlobalOrganizationOperationResponse)
예제 #4
0
def test_list_rest_flattened_error():
    client = GlobalOrganizationOperationsClient(
        credentials=ga_credentials.AnonymousCredentials(), )

    # Attempting to call a method with both a request object and flattened
    # fields is an error.
    with pytest.raises(ValueError):
        client.list(compute.ListGlobalOrganizationOperationsRequest(), )
예제 #5
0
def test_parse_common_billing_account_path():
    expected = {
        "billing_account": "clam",
    }
    path = GlobalOrganizationOperationsClient.common_billing_account_path(**expected)

    # Check that the path construction is reversible.
    actual = GlobalOrganizationOperationsClient.parse_common_billing_account_path(path)
    assert expected == actual
예제 #6
0
def test_parse_common_project_path():
    expected = {
        "project": "mussel",
    }
    path = GlobalOrganizationOperationsClient.common_project_path(**expected)

    # Check that the path construction is reversible.
    actual = GlobalOrganizationOperationsClient.parse_common_project_path(path)
    assert expected == actual
예제 #7
0
def test_parse_common_organization_path():
    expected = {
        "organization": "nudibranch",
    }
    path = GlobalOrganizationOperationsClient.common_organization_path(**expected)

    # Check that the path construction is reversible.
    actual = GlobalOrganizationOperationsClient.parse_common_organization_path(path)
    assert expected == actual
예제 #8
0
def test_global_organization_operations_client_get_transport_class():
    transport = GlobalOrganizationOperationsClient.get_transport_class()
    available_transports = [
        transports.GlobalOrganizationOperationsRestTransport,
    ]
    assert transport in available_transports

    transport = GlobalOrganizationOperationsClient.get_transport_class("rest")
    assert transport == transports.GlobalOrganizationOperationsRestTransport
예제 #9
0
def test_parse_common_folder_path():
    expected = {
        "folder": "octopus",
    }
    path = GlobalOrganizationOperationsClient.common_folder_path(**expected)

    # Check that the path construction is reversible.
    actual = GlobalOrganizationOperationsClient.parse_common_folder_path(path)
    assert expected == actual
예제 #10
0
def test_list_pager():
    client = GlobalOrganizationOperationsClient(
        credentials=ga_credentials.AnonymousCredentials(), )

    # Mock the http request call within the method and fake a response.
    with mock.patch.object(Session, "request") as req:
        # Set the response as a series of pages
        response = (
            compute.OperationList(
                items=[
                    compute.Operation(),
                    compute.Operation(),
                    compute.Operation(),
                ],
                next_page_token="abc",
            ),
            compute.OperationList(
                items=[],
                next_page_token="def",
            ),
            compute.OperationList(
                items=[
                    compute.Operation(),
                ],
                next_page_token="ghi",
            ),
            compute.OperationList(items=[
                compute.Operation(),
                compute.Operation(),
            ], ),
        )
        # Two responses for two calls
        response = response + response

        # Wrap the values into proper Response objs
        response = tuple(compute.OperationList.to_json(x) for x in response)
        return_values = tuple(Response() for i in response)
        for return_val, response_val in zip(return_values, response):
            return_val._content = response_val.encode("UTF-8")
            return_val.status_code = 200
        req.side_effect = return_values

        metadata = ()
        pager = client.list(request={})

        assert pager._metadata == metadata

        results = list(pager)
        assert len(results) == 6
        assert all(isinstance(i, compute.Operation) for i in results)

        pages = list(client.list(request={}).pages)
        for page_, token in zip(pages, ["abc", "def", "ghi", ""]):
            assert page_.raw_page.next_page_token == token
예제 #11
0
def test_global_organization_operations_host_with_port():
    client = GlobalOrganizationOperationsClient(
        credentials=ga_credentials.AnonymousCredentials(),
        client_options=client_options.ClientOptions(
            api_endpoint="compute.googleapis.com:8000"),
    )
    assert client.transport._host == "compute.googleapis.com:8000"
예제 #12
0
def test_transport_instance():
    # A client may be instantiated with a custom transport instance.
    transport = transports.GlobalOrganizationOperationsRestTransport(
        credentials=ga_credentials.AnonymousCredentials(),
    )
    client = GlobalOrganizationOperationsClient(transport=transport)
    assert client.transport is transport
예제 #13
0
def test_common_billing_account_path():
    billing_account = "squid"
    expected = "billingAccounts/{billing_account}".format(
        billing_account=billing_account, )
    actual = GlobalOrganizationOperationsClient.common_billing_account_path(
        billing_account)
    assert expected == actual
예제 #14
0
def test_common_organization_path():
    organization = "oyster"
    expected = "organizations/{organization}".format(
        organization=organization, )
    actual = GlobalOrganizationOperationsClient.common_organization_path(
        organization)
    assert expected == actual
예제 #15
0
def test_list_rest(
    transport: str = "rest",
    request_type=compute.ListGlobalOrganizationOperationsRequest,
):
    client = GlobalOrganizationOperationsClient(
        credentials=ga_credentials.AnonymousCredentials(),
        transport=transport,
    )

    # Everything is optional in proto3 as far as the runtime is concerned,
    # and we are mocking out the actual API, so just send an empty request.
    request = request_type()

    # Mock the http request call within the method and fake a response.
    with mock.patch.object(Session, "request") as req:
        # Designate an appropriate value for the returned response.
        return_value = compute.OperationList(
            id="id_value",
            items=[
                compute.Operation(
                    client_operation_id="client_operation_id_value")
            ],
            kind="kind_value",
            next_page_token="next_page_token_value",
            self_link="self_link_value",
            warning=compute.Warning(code=compute.Warning.Code.CLEANUP_FAILED),
        )

        # Wrap the value into a proper Response obj
        json_return_value = compute.OperationList.to_json(return_value)
        response_value = Response()
        response_value.status_code = 200
        response_value._content = json_return_value.encode("UTF-8")
        req.return_value = response_value
        response = client.list(request)

    # Establish that the response is the type that we expect.
    assert isinstance(response, pagers.ListPager)
    assert response.id == "id_value"
    assert response.items == [
        compute.Operation(client_operation_id="client_operation_id_value")
    ]
    assert response.kind == "kind_value"
    assert response.next_page_token == "next_page_token_value"
    assert response.self_link == "self_link_value"
    assert response.warning == compute.Warning(
        code=compute.Warning.Code.CLEANUP_FAILED)
예제 #16
0
def test_common_location_path():
    project = "winkle"
    location = "nautilus"
    expected = "projects/{project}/locations/{location}".format(
        project=project, location=location,
    )
    actual = GlobalOrganizationOperationsClient.common_location_path(project, location)
    assert expected == actual
예제 #17
0
def test_client_withDEFAULT_CLIENT_INFO():
    client_info = gapic_v1.client_info.ClientInfo()

    with mock.patch.object(
        transports.GlobalOrganizationOperationsTransport, "_prep_wrapped_messages"
    ) as prep:
        client = GlobalOrganizationOperationsClient(
            credentials=ga_credentials.AnonymousCredentials(), client_info=client_info,
        )
        prep.assert_called_once_with(client_info)

    with mock.patch.object(
        transports.GlobalOrganizationOperationsTransport, "_prep_wrapped_messages"
    ) as prep:
        transport_class = GlobalOrganizationOperationsClient.get_transport_class()
        transport = transport_class(
            credentials=ga_credentials.AnonymousCredentials(), client_info=client_info,
        )
        prep.assert_called_once_with(client_info)
예제 #18
0
def test_global_organization_operations_auth_adc_old_google_auth():
    # If no credentials are provided, we should use ADC credentials.
    with mock.patch.object(google.auth, "default", autospec=True) as adc:
        adc.return_value = (ga_credentials.AnonymousCredentials(), None)
        GlobalOrganizationOperationsClient()
        adc.assert_called_once_with(
            scopes=(
                "https://www.googleapis.com/auth/compute",
                "https://www.googleapis.com/auth/cloud-platform",
            ),
            quota_project_id=None,
        )
예제 #19
0
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 GlobalOrganizationOperationsClient._get_default_mtls_endpoint(None) is None
    assert (
        GlobalOrganizationOperationsClient._get_default_mtls_endpoint(api_endpoint)
        == api_mtls_endpoint
    )
    assert (
        GlobalOrganizationOperationsClient._get_default_mtls_endpoint(api_mtls_endpoint)
        == api_mtls_endpoint
    )
    assert (
        GlobalOrganizationOperationsClient._get_default_mtls_endpoint(sandbox_endpoint)
        == sandbox_mtls_endpoint
    )
    assert (
        GlobalOrganizationOperationsClient._get_default_mtls_endpoint(
            sandbox_mtls_endpoint
        )
        == sandbox_mtls_endpoint
    )
    assert (
        GlobalOrganizationOperationsClient._get_default_mtls_endpoint(non_googleapi)
        == non_googleapi
    )
예제 #20
0
def test_get_rest(transport: str = "rest",
                  request_type=compute.GetGlobalOrganizationOperationRequest):
    client = GlobalOrganizationOperationsClient(
        credentials=ga_credentials.AnonymousCredentials(),
        transport=transport,
    )

    # Everything is optional in proto3 as far as the runtime is concerned,
    # and we are mocking out the actual API, so just send an empty request.
    request = request_type()

    # Mock the http request call within the method and fake a response.
    with mock.patch.object(Session, "request") as req:
        # Designate an appropriate value for the returned response.
        return_value = compute.Operation(
            client_operation_id="client_operation_id_value",
            creation_timestamp="creation_timestamp_value",
            description="description_value",
            end_time="end_time_value",
            error=compute.Error(errors=[compute.Errors(code="code_value")]),
            http_error_message="http_error_message_value",
            http_error_status_code=2374,
            id=205,
            insert_time="insert_time_value",
            kind="kind_value",
            name="name_value",
            operation_group_id="operation_group_id_value",
            operation_type="operation_type_value",
            progress=885,
            region="region_value",
            self_link="self_link_value",
            start_time="start_time_value",
            status=compute.Operation.Status.DONE,
            status_message="status_message_value",
            target_id=947,
            target_link="target_link_value",
            user="******",
            warnings=[
                compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)
            ],
            zone="zone_value",
        )

        # Wrap the value into a proper Response obj
        json_return_value = compute.Operation.to_json(return_value)
        response_value = Response()
        response_value.status_code = 200
        response_value._content = json_return_value.encode("UTF-8")
        req.return_value = response_value
        response = client.get(request)

    # Establish that the response is the type that we expect.
    assert isinstance(response, compute.Operation)
    assert response.client_operation_id == "client_operation_id_value"
    assert response.creation_timestamp == "creation_timestamp_value"
    assert response.description == "description_value"
    assert response.end_time == "end_time_value"
    assert response.error == compute.Error(
        errors=[compute.Errors(code="code_value")])
    assert response.http_error_message == "http_error_message_value"
    assert response.http_error_status_code == 2374
    assert response.id == 205
    assert response.insert_time == "insert_time_value"
    assert response.kind == "kind_value"
    assert response.name == "name_value"
    assert response.operation_group_id == "operation_group_id_value"
    assert response.operation_type == "operation_type_value"
    assert response.progress == 885
    assert response.region == "region_value"
    assert response.self_link == "self_link_value"
    assert response.start_time == "start_time_value"
    assert response.status == compute.Operation.Status.DONE
    assert response.status_message == "status_message_value"
    assert response.target_id == 947
    assert response.target_link == "target_link_value"
    assert response.user == "user_value"
    assert response.warnings == [
        compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)
    ]
    assert response.zone == "zone_value"
예제 #21
0
def test_common_project_path():
    project = "cuttlefish"
    expected = "projects/{project}".format(project=project, )
    actual = GlobalOrganizationOperationsClient.common_project_path(project)
    assert expected == actual
예제 #22
0
def test_common_folder_path():
    folder = "whelk"
    expected = "folders/{folder}".format(folder=folder, )
    actual = GlobalOrganizationOperationsClient.common_folder_path(folder)
    assert expected == actual