def test_list_instances(self):
        # Setup Expected Response
        next_page_token = "nextPageToken-1530815211"
        expected_response = {"next_page_token": next_page_token}
        expected_response = bigtable_instance_admin_pb2.ListInstancesResponse(
            **expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        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]")

        response = client.list_instances(parent)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = bigtable_instance_admin_pb2.ListInstancesRequest(
            parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Exemplo n.º 2
0
    def test_list_instances(self):
        from google.cloud.bigtable_admin_v2.proto import (instance_pb2 as
                                                          data_v2_pb2)
        from google.cloud.bigtable_admin_v2.proto import (
            bigtable_instance_admin_pb2 as messages_v2_pb2)
        from google.cloud.bigtable_admin_v2.gapic import \
            bigtable_instance_admin_client
        from google.cloud.bigtable.instance import Instance

        FAILED_LOCATION = 'FAILED'
        INSTANCE_ID1 = 'instance-id1'
        INSTANCE_ID2 = 'instance-id2'
        INSTANCE_NAME1 = ('projects/' + self.PROJECT + '/instances/' +
                          INSTANCE_ID1)
        INSTANCE_NAME2 = ('projects/' + self.PROJECT + '/instances/' +
                          INSTANCE_ID2)

        credentials = _make_credentials()
        api = bigtable_instance_admin_client.BigtableInstanceAdminClient(
            mock.Mock())
        client = self._make_one(project=self.PROJECT,
                                credentials=credentials,
                                admin=True)

        # Create response_pb
        response_pb = messages_v2_pb2.ListInstancesResponse(
            failed_locations=[
                FAILED_LOCATION,
            ],
            instances=[
                data_v2_pb2.Instance(
                    name=INSTANCE_NAME1,
                    display_name=INSTANCE_NAME1,
                ),
                data_v2_pb2.Instance(
                    name=INSTANCE_NAME2,
                    display_name=INSTANCE_NAME2,
                ),
            ],
        )

        # Patch the stub used by the API method.
        client._instance_admin_client = api
        bigtable_instance_stub = (client.instance_admin_client.transport)
        bigtable_instance_stub.list_instances.side_effect = [response_pb]

        # Perform the method and check the result.
        instances, failed_locations = client.list_instances()

        instance_1, instance_2 = instances

        self.assertIsInstance(instance_1, Instance)
        self.assertEqual(instance_1.name, INSTANCE_NAME1)
        self.assertTrue(instance_1._client is client)

        self.assertIsInstance(instance_2, Instance)
        self.assertEqual(instance_2.name, INSTANCE_NAME2)
        self.assertTrue(instance_2._client is client)

        self.assertEqual(failed_locations, [FAILED_LOCATION])
    def test_list_instances(self):
        from google.cloud.bigtable_admin_v2.proto import (instance_pb2 as
                                                          data_v2_pb2)
        from google.cloud.bigtable_admin_v2.proto import (
            bigtable_instance_admin_pb2 as messages_v2_pb2)

        FAILED_LOCATION = 'FAILED'
        INSTANCE_ID1 = 'instance-id1'
        INSTANCE_ID2 = 'instance-id2'
        INSTANCE_NAME1 = ('projects/' + self.PROJECT + '/instances/' +
                          INSTANCE_ID1)
        INSTANCE_NAME2 = ('projects/' + self.PROJECT + '/instances/' +
                          INSTANCE_ID2)

        channel = _make_channel()
        client = self._make_one(project=self.PROJECT,
                                channel=channel,
                                admin=True)

        # Create response_pb
        response_pb = messages_v2_pb2.ListInstancesResponse(
            failed_locations=[
                FAILED_LOCATION,
            ],
            instances=[
                data_v2_pb2.Instance(
                    name=INSTANCE_NAME1,
                    display_name=INSTANCE_NAME1,
                ),
                data_v2_pb2.Instance(
                    name=INSTANCE_NAME2,
                    display_name=INSTANCE_NAME2,
                ),
            ],
        )

        # Patch the stub used by the API method.
        bigtable_instance_stub = (
            client._instance_admin_client.bigtable_instance_admin_stub)
        bigtable_instance_stub.ListInstances.side_effect = [response_pb]
        expected_result = response_pb

        # Perform the method and check the result.
        result = client.list_instances()
        self.assertEqual(result, expected_result)
    def test_list_instances(self):
        # Setup Expected Response
        next_page_token = 'nextPageToken-1530815211'
        expected_response = {'next_page_token': next_page_token}
        expected_response = bigtable_instance_admin_pb2.ListInstancesResponse(
            **expected_response)

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

        # Setup Request
        parent = client.project_path('[PROJECT]')

        response = client.list_instances(parent)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = bigtable_instance_admin_pb2.ListInstancesRequest(
            parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request