def test_list_tables(self):
        # Setup Expected Response
        next_page_token = ''
        tables_element = {}
        tables = [tables_element]
        expected_response = {
            'next_page_token': next_page_token,
            'tables': tables
        }
        expected_response = bigtable_table_admin_pb2.ListTablesResponse(
            **expected_response)

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

        # Setup Request
        parent = client.instance_path('[PROJECT]', '[INSTANCE]')

        paged_list_response = client.list_tables(parent)
        resources = list(paged_list_response)
        assert len(resources) == 1

        assert expected_response.tables[0] == resources[0]

        assert len(channel.requests) == 1
        expected_request = bigtable_table_admin_pb2.ListTablesRequest(
            parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_list_tables(self):
        # Setup Expected Response
        next_page_token = ""
        tables_element = {}
        tables = [tables_element]
        expected_response = {
            "next_page_token": next_page_token,
            "tables": tables
        }
        expected_response = bigtable_table_admin_pb2.ListTablesResponse(
            **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.BigtableTableAdminClient()

        # Setup Request
        parent = client.instance_path("[PROJECT]", "[INSTANCE]")

        paged_list_response = client.list_tables(parent)
        resources = list(paged_list_response)
        assert len(resources) == 1

        assert expected_response.tables[0] == resources[0]

        assert len(channel.requests) == 1
        expected_request = bigtable_table_admin_pb2.ListTablesRequest(
            parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def _list_tables_helper(self, table_name=None):
        from google.cloud.bigtable_admin_v2.proto import (table_pb2 as
                                                          table_data_v2_pb2)
        from google.cloud.bigtable_admin_v2.proto import (
            bigtable_table_admin_pb2 as table_messages_v1_pb2)

        channel = _make_channel()
        client = self._make_client(project=self.PROJECT,
                                   channel=channel,
                                   admin=True)
        instance = self._make_one(self.INSTANCE_ID, client, self.LOCATION_ID)

        # Create response_pb
        if table_name is None:
            table_name = self.TABLE_NAME

        response_pb = table_messages_v1_pb2.ListTablesResponse(tables=[
            table_data_v2_pb2.Table(name=table_name),
        ], )

        # Patch the stub used by the API method.
        bigtable_table_stub = (
            client._table_admin_client.bigtable_table_admin_stub)
        bigtable_table_stub.ListTables.side_effect = [response_pb]

        # Create expected_result.
        expected_table = instance.table(self.TABLE_ID)
        expected_result = [expected_table]

        # Perform the method and check the result.
        result = instance.list_tables()

        self.assertEqual(result, expected_result)
    def _list_tables_helper(self, table_name=None):
        from google.cloud.bigtable_admin_v2.proto import (
            table_pb2 as table_data_v2_pb2)
        from google.cloud.bigtable_admin_v2.proto import (
            bigtable_table_admin_pb2 as table_messages_v1_pb2)
        from google.cloud.bigtable_admin_v2.gapic import (
            bigtable_table_admin_client, bigtable_instance_admin_client)

        table_api = bigtable_table_admin_client.BigtableTableAdminClient(
            mock.Mock())
        instance_api = (
            bigtable_instance_admin_client.BigtableInstanceAdminClient(
                mock.Mock()))
        credentials = _make_credentials()
        client = self._make_client(project=self.PROJECT,
                                   credentials=credentials, admin=True)
        instance = self._make_one(self.INSTANCE_ID, client)

        # Create response_pb
        if table_name is None:
            table_name = self.TABLE_NAME

        response_pb = table_messages_v1_pb2.ListTablesResponse(
            tables=[
                table_data_v2_pb2.Table(name=table_name),
            ],
        )

        # Patch the stub used by the API method.
        client._table_admin_client = table_api
        client._instance_admin_client = instance_api
        bigtable_table_stub = (
            client._table_admin_client.transport)
        bigtable_table_stub.list_tables.side_effect = [response_pb]

        # Create expected_result.
        expected_table = instance.table(self.TABLE_ID)
        expected_result = [expected_table]

        # Perform the method and check the result.
        result = instance.list_tables()

        self.assertEqual(result, expected_result)