def test_partial_update_instance(self):
        # Setup Expected Response
        name = "name3373707"
        display_name = "displayName1615086568"
        expected_response = {"name": name, "display_name": display_name}
        expected_response = instance_pb2.Instance(**expected_response)
        operation = operations_pb2.Operation(
            name="operations/test_partial_update_instance", done=True)
        operation.response.Pack(expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = bigtable_admin_v2.BigtableInstanceAdminClient()

        # Setup Request
        instance = {}
        update_mask = {}

        response = client.partial_update_instance(instance, update_mask)
        result = response.result()
        assert expected_response == result

        assert len(channel.requests) == 1
        expected_request = bigtable_instance_admin_pb2.PartialUpdateInstanceRequest(
            instance=instance, update_mask=update_mask)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
コード例 #2
0
    def test_partial_update_instance(self):
        # Setup Expected Response
        name = 'name3373707'
        display_name = 'displayName1615086568'
        expected_response = {'name': name, 'display_name': display_name}
        expected_response = instance_pb2.Instance(**expected_response)
        operation = operations_pb2.Operation(
            name='operations/test_partial_update_instance', done=True)
        operation.response.Pack(expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        client = bigtable_admin_v2.BigtableInstanceAdminClient(channel=channel)

        # Setup Request
        instance = {}
        update_mask = {}

        response = client.partial_update_instance(instance, update_mask)
        result = response.result()
        assert expected_response == result

        assert len(channel.requests) == 1
        expected_request = bigtable_instance_admin_pb2.PartialUpdateInstanceRequest(
            instance=instance, update_mask=update_mask)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
コード例 #3
0
    def test_update_empty(self):
        from google.api_core import operation
        from google.cloud.bigtable_admin_v2.gapic import (
            bigtable_instance_admin_client)
        from google.longrunning import operations_pb2
        from google.protobuf import field_mask_pb2
        from google.cloud.bigtable_admin_v2.types import instance_pb2
        from google.cloud.bigtable_admin_v2.proto import (
            bigtable_instance_admin_pb2 as instance_v2_pb2)

        credentials = _make_credentials()
        client = self._make_client(project=self.PROJECT,
                                   credentials=credentials,
                                   admin=True)
        instance = self._make_one(None, client)

        expected_request_instance = instance_pb2.Instance(
            name=instance.name,
            display_name=instance.display_name,
            type=instance.type_,
            labels=instance.labels)
        expected_request_update_mask = field_mask_pb2.FieldMask()
        expected_request = instance_v2_pb2.PartialUpdateInstanceRequest(
            instance=expected_request_instance,
            update_mask=expected_request_update_mask)

        response_pb = operations_pb2.Operation(name=self.OP_NAME)

        channel = ChannelStub(responses=[response_pb])
        instance_api = (
            bigtable_instance_admin_client.BigtableInstanceAdminClient(
                channel=channel))

        # Mock api calls
        client._instance_admin_client = instance_api

        # Perform the method and check the result.
        result = instance.update()
        actual_request = channel.requests[0][1]

        self.assertIsInstance(result, operation.Operation)
        self.assertEqual(actual_request, expected_request)
コード例 #4
0
    def test_update(self):
        import datetime
        from google.api_core import operation
        from google.longrunning import operations_pb2
        from google.protobuf.any_pb2 import Any
        from google.cloud.bigtable_admin_v2.proto import (
            bigtable_instance_admin_pb2 as messages_v2_pb2)
        from google.cloud._helpers import _datetime_to_pb_timestamp
        from google.cloud.bigtable import enums
        from google.cloud.bigtable_admin_v2.gapic import (
            bigtable_instance_admin_client)
        from google.protobuf import field_mask_pb2
        from google.cloud.bigtable_admin_v2.types import instance_pb2
        from google.cloud.bigtable_admin_v2.proto import (
            bigtable_instance_admin_pb2 as instance_v2_pb2)

        NOW = datetime.datetime.utcnow()
        NOW_PB = _datetime_to_pb_timestamp(NOW)
        credentials = _make_credentials()
        client = self._make_client(project=self.PROJECT,
                                   credentials=credentials, admin=True)
        instance = self._make_one(
            self.INSTANCE_ID, client, display_name=self.DISPLAY_NAME,
            instance_type=enums.Instance.Type.DEVELOPMENT, labels=self.LABELS)

        expected_request_instance = instance_pb2.Instance(
            name=instance.name, display_name=instance.display_name,
            type=instance.type_, labels=instance.labels)
        expected_request_update_mask = field_mask_pb2.FieldMask(
            paths=['display_name', 'type', 'labels'])
        expected_request = instance_v2_pb2.PartialUpdateInstanceRequest(
            instance=expected_request_instance,
            update_mask=expected_request_update_mask)

        metadata = messages_v2_pb2.UpdateInstanceMetadata(
            request_time=NOW_PB)
        type_url = 'type.googleapis.com/{}'.format(
            messages_v2_pb2.UpdateInstanceMetadata.DESCRIPTOR.full_name)
        response_pb = operations_pb2.Operation(
            name=self.OP_NAME,
            metadata=Any(
                type_url=type_url,
                value=metadata.SerializeToString(),
            )
        )

        channel = ChannelStub(responses=[response_pb])
        instance_api = (
            bigtable_instance_admin_client.BigtableInstanceAdminClient(
                channel=channel))

        # Mock api calls
        client._instance_admin_client = instance_api

        # Perform the method and check the result.
        result = instance.update()
        actual_request = channel.requests[0][1]

        self.assertEqual(actual_request, expected_request)
        self.assertIsInstance(result, operation.Operation)
        self.assertEqual(result.operation.name, self.OP_NAME)
        self.assertIsInstance(result.metadata,
                              messages_v2_pb2.UpdateInstanceMetadata)