Пример #1
0
def test_disk_types_host_no_port():
    client = DiskTypesClient(
        credentials=ga_credentials.AnonymousCredentials(),
        client_options=client_options.ClientOptions(
            api_endpoint="compute.googleapis.com"),
    )
    assert client.transport._host == "compute.googleapis.com:443"
Пример #2
0
def test_common_location_path():
    project = "winkle"
    location = "nautilus"
    expected = "projects/{project}/locations/{location}".format(
        project=project,
        location=location,
    )
    actual = DiskTypesClient.common_location_path(project, location)
    assert expected == actual
Пример #3
0
def test_list_rest(transport: str = "rest",
                   request_type=compute.ListDiskTypesRequest):
    client = DiskTypesClient(
        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.DiskTypeList(
            id="id_value",
            items=[
                compute.DiskType(creation_timestamp="creation_timestamp_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.DiskTypeList.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.DiskType(creation_timestamp="creation_timestamp_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)
Пример #4
0
def test_client_withDEFAULT_CLIENT_INFO():
    client_info = gapic_v1.client_info.ClientInfo()

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

    with mock.patch.object(transports.DiskTypesTransport,
                           "_prep_wrapped_messages") as prep:
        transport_class = DiskTypesClient.get_transport_class()
        transport = transport_class(
            credentials=ga_credentials.AnonymousCredentials(),
            client_info=client_info,
        )
        prep.assert_called_once_with(client_info)
Пример #5
0
def test_disk_types_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)
        DiskTypesClient()
        adc.assert_called_once_with(
            scopes=(
                "https://www.googleapis.com/auth/compute.readonly",
                "https://www.googleapis.com/auth/compute",
                "https://www.googleapis.com/auth/cloud-platform",
            ),
            quota_project_id=None,
        )
Пример #6
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 DiskTypesClient._get_default_mtls_endpoint(None) is None
    assert DiskTypesClient._get_default_mtls_endpoint(
        api_endpoint) == api_mtls_endpoint
    assert (DiskTypesClient._get_default_mtls_endpoint(api_mtls_endpoint) ==
            api_mtls_endpoint)
    assert (DiskTypesClient._get_default_mtls_endpoint(sandbox_endpoint) ==
            sandbox_mtls_endpoint)
    assert (DiskTypesClient._get_default_mtls_endpoint(sandbox_mtls_endpoint)
            == sandbox_mtls_endpoint)
    assert DiskTypesClient._get_default_mtls_endpoint(
        non_googleapi) == non_googleapi
Пример #7
0
def test_transport_instance():
    # A client may be instantiated with a custom transport instance.
    transport = transports.DiskTypesRestTransport(
        credentials=ga_credentials.AnonymousCredentials(), )
    client = DiskTypesClient(transport=transport)
    assert client.transport is transport
Пример #8
0
def test_aggregated_list_pager():
    client = DiskTypesClient(
        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.DiskTypeAggregatedList(
                items={
                    "a": compute.DiskTypesScopedList(),
                    "b": compute.DiskTypesScopedList(),
                    "c": compute.DiskTypesScopedList(),
                },
                next_page_token="abc",
            ),
            compute.DiskTypeAggregatedList(
                items={},
                next_page_token="def",
            ),
            compute.DiskTypeAggregatedList(
                items={
                    "g": compute.DiskTypesScopedList(),
                },
                next_page_token="ghi",
            ),
            compute.DiskTypeAggregatedList(items={
                "h": compute.DiskTypesScopedList(),
                "i": compute.DiskTypesScopedList(),
            }, ),
        )
        # Two responses for two calls
        response = response + response

        # Wrap the values into proper Response objs
        response = tuple(
            compute.DiskTypeAggregatedList.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.aggregated_list(request={})

        assert pager._metadata == metadata

        assert isinstance(pager.get("a"), compute.DiskTypesScopedList)
        assert pager.get("h") is None

        results = list(pager)
        assert len(results) == 6
        assert all(isinstance(i, tuple) for i in results)
        for result in results:
            assert isinstance(result, tuple)
            assert tuple(type(t)
                         for t in result) == (str, compute.DiskTypesScopedList)

        assert pager.get("a") is None
        assert isinstance(pager.get("h"), compute.DiskTypesScopedList)

        pages = list(client.aggregated_list(request={}).pages)
        for page_, token in zip(pages, ["abc", "def", "ghi", ""]):
            assert page_.raw_page.next_page_token == token
Пример #9
0
def test_common_project_path():
    project = "cuttlefish"
    expected = "projects/{project}".format(project=project, )
    actual = DiskTypesClient.common_project_path(project)
    assert expected == actual
Пример #10
0
def test_common_organization_path():
    organization = "oyster"
    expected = "organizations/{organization}".format(
        organization=organization, )
    actual = DiskTypesClient.common_organization_path(organization)
    assert expected == actual
Пример #11
0
def test_common_folder_path():
    folder = "whelk"
    expected = "folders/{folder}".format(folder=folder, )
    actual = DiskTypesClient.common_folder_path(folder)
    assert expected == actual
Пример #12
0
def test_common_billing_account_path():
    billing_account = "squid"
    expected = "billingAccounts/{billing_account}".format(
        billing_account=billing_account, )
    actual = DiskTypesClient.common_billing_account_path(billing_account)
    assert expected == actual