def test_create_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_create_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
        parent = client.project_path('[PROJECT]')
        instance_id = 'instanceId-2101995259'
        instance = {}
        clusters = {}

        response = client.create_instance(parent, instance_id, instance,
                                          clusters)
        result = response.result()
        assert expected_response == result

        assert len(channel.requests) == 1
        expected_request = bigtable_instance_admin_pb2.CreateInstanceRequest(
            parent=parent,
            instance_id=instance_id,
            instance=instance,
            clusters=clusters)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_create_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_create_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
        parent = client.project_path("[PROJECT]")
        instance_id = "instanceId-2101995259"
        instance = {}
        clusters = {}

        response = client.create_instance(parent, instance_id, instance, clusters)
        result = response.result()
        assert expected_response == result

        assert len(channel.requests) == 1
        expected_request = bigtable_instance_admin_pb2.CreateInstanceRequest(
            parent=parent, instance_id=instance_id, instance=instance, clusters=clusters
        )
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def _create_instance_request(self, display_name, clusters):
        from google.cloud.bigtable_admin_v2.proto import (
            bigtable_instance_admin_pb2 as messages_v2_pb2)
        from google.cloud.bigtable_admin_v2.types import instance_pb2

        instance = instance_pb2.Instance(display_name=display_name)

        return messages_v2_pb2.CreateInstanceRequest(
            parent='projects/%s' % (self.PROJECT),
            instance_id=self.INSTANCE_ID,
            instance=instance,
            clusters=clusters)
Пример #4
0
    def _create_instance_request(self, clusters):
        from google.cloud.bigtable_admin_v2.proto import (
            bigtable_instance_admin_pb2 as messages_v2_pb2)
        from google.cloud.bigtable_admin_v2.types import instance_pb2
        from google.cloud.bigtable import enums

        instance = instance_pb2.Instance(display_name=self.DISPLAY_NAME,
                                         type=enums.InstanceType.PRODUCTION,
                                         labels=self.LABELS)

        return messages_v2_pb2.CreateInstanceRequest(
            parent='projects/%s' % (self.PROJECT),
            instance_id=self.INSTANCE_ID,
            instance=instance,
            clusters=clusters)