Exemplo n.º 1
0
    def test_tables(self):
        from google.cloud.bigtable.table import Table

        table_name1 = "table-name1"
        table_name2 = "table-name2"
        instance = _Instance(list_tables_result=[
            Table(table_name1, None),
            Table(table_name2, None)
        ])
        connection = self._make_one(autoconnect=False, instance=instance)
        result = connection.tables()
        self.assertEqual(result, [table_name1, table_name2])
Exemplo n.º 2
0
    def test_tables_with_prefix(self):
        from google.cloud.bigtable.table import Table

        table_prefix = 'prefix'
        table_prefix_separator = '<>'
        unprefixed_table_name1 = 'table-name1'

        table_name1 = (table_prefix + table_prefix_separator +
                       unprefixed_table_name1)
        table_name2 = 'table-name2'
        instance = _Instance(list_tables_result=[
            Table(table_name1, None),
            Table(table_name2, None),
        ])
        connection = self._make_one(
            autoconnect=False, instance=instance, table_prefix=table_prefix,
            table_prefix_separator=table_prefix_separator)
        result = connection.tables()
        self.assertEqual(result, [unprefixed_table_name1])
Exemplo n.º 3
0
    def test_tables_with_prefix(self):
        from google.cloud.bigtable.table import Table

        table_prefix = "prefix"
        table_prefix_separator = "<>"
        unprefixed_table_name1 = "table-name1"

        table_name1 = table_prefix + table_prefix_separator + unprefixed_table_name1
        table_name2 = "table-name2"
        instance = _Instance(list_tables_result=[
            Table(table_name1, None),
            Table(table_name2, None)
        ])
        connection = self._make_one(
            autoconnect=False,
            instance=instance,
            table_prefix=table_prefix,
            table_prefix_separator=table_prefix_separator,
        )
        result = connection.tables()
        self.assertEqual(result, [unprefixed_table_name1])
    def table(self, name, use_prefix=True):
        """Table factory.

        :type name: str
        :param name: The name of the table to be created.

        :type use_prefix: bool
        :param use_prefix: Whether to use the table prefix (if any).

        :rtype: :class:`Table <google.cloud.happybase.table.Table>`
        :returns: Table instance owned by this connection.
        """
        if use_prefix:
            name = self._table_name(name)
        return Table(name, self)