Exemplo n.º 1
0
 def delete(self):
     """Delete this column family."""
     request_pb = table_admin_v2_pb2.ModifyColumnFamiliesRequest(
         name=self._table.name)
     request_pb.modifications.add(id=self.column_family_id, drop=True)
     client = self._table._instance._client
     # We expect a `google.protobuf.empty_pb2.Empty`
     client._table_stub.ModifyColumnFamilies(request_pb)
    def _update_test_helper(self, gc_rule=None):
        from tests.unit._testing import _FakeStub
        from google.cloud.bigtable._generated import (bigtable_table_admin_pb2
                                                      as table_admin_v2_pb2)

        project_id = 'project-id'
        zone = 'zone'
        cluster_id = 'cluster-id'
        table_id = 'table-id'
        column_family_id = 'column-family-id'
        table_name = ('projects/' + project_id + '/zones/' + zone +
                      '/clusters/' + cluster_id + '/tables/' + table_id)

        client = _Client()
        table = _Table(table_name, client=client)
        column_family = self._make_one(column_family_id,
                                       table,
                                       gc_rule=gc_rule)

        # Create request_pb
        if gc_rule is None:
            column_family_pb = _ColumnFamilyPB()
        else:
            column_family_pb = _ColumnFamilyPB(gc_rule=gc_rule.to_pb())
        request_pb = table_admin_v2_pb2.ModifyColumnFamiliesRequest(
            name=table_name)
        request_pb.modifications.add(
            id=column_family_id,
            update=column_family_pb,
        )

        # Create response_pb
        response_pb = _ColumnFamilyPB()

        # Patch the stub used by the API method.
        client._table_stub = stub = _FakeStub(response_pb)

        # Create expected_result.
        expected_result = None  # update() has no return value.

        # Perform the method and check the result.
        self.assertEqual(stub.results, (response_pb, ))
        result = column_family.update()
        self.assertEqual(stub.results, ())
        self.assertEqual(result, expected_result)
        self.assertEqual(stub.method_calls, [(
            'ModifyColumnFamilies',
            (request_pb, ),
            {},
        )])
Exemplo n.º 3
0
 def create(self):
     """Create this column family."""
     column_family = self.to_pb()
     request_pb = table_admin_v2_pb2.ModifyColumnFamiliesRequest(
         name=self._table.name)
     request_pb.modifications.add(
         id=self.column_family_id,
         create=column_family,
     )
     client = self._table._instance._client
     # We expect a `.table_v2_pb2.ColumnFamily`. We ignore it since the only
     # data it contains are the GC rule and the column family ID already
     # stored on this instance.
     client._table_stub.ModifyColumnFamilies(request_pb)
Exemplo n.º 4
0
    def update(self):
        """Update this column family.

        .. note::

            Only the GC rule can be updated. By changing the column family ID,
            you will simply be referring to a different column family.
        """
        column_family = self.to_pb()
        request_pb = table_admin_v2_pb2.ModifyColumnFamiliesRequest(
            name=self._table.name)
        request_pb.modifications.add(id=self.column_family_id,
                                     update=column_family)
        client = self._table._instance._client
        # We expect a `.table_v2_pb2.ColumnFamily`. We ignore it since the only
        # data it contains are the GC rule and the column family ID already
        # stored on this instance.
        client._table_stub.ModifyColumnFamilies(request_pb)
Exemplo n.º 5
0
    def test_delete(self):
        from google.protobuf import empty_pb2
        from google.cloud.bigtable._generated import (
            bigtable_table_admin_pb2 as table_admin_v2_pb2)
        from unit_tests.bigtable._testing import _FakeStub

        project_id = 'project-id'
        zone = 'zone'
        cluster_id = 'cluster-id'
        table_id = 'table-id'
        column_family_id = 'column-family-id'
        table_name = ('projects/' + project_id + '/zones/' + zone +
                      '/clusters/' + cluster_id + '/tables/' + table_id)

        client = _Client()
        table = _Table(table_name, client=client)
        column_family = self._makeOne(column_family_id, table)

        # Create request_pb
        request_pb = table_admin_v2_pb2.ModifyColumnFamiliesRequest(
            name=table_name)
        request_pb.modifications.add(
            id=column_family_id,
            drop=True)

        # Create response_pb
        response_pb = empty_pb2.Empty()

        # Patch the stub used by the API method.
        client._table_stub = stub = _FakeStub(response_pb)

        # Create expected_result.
        expected_result = None  # delete() has no return value.

        # Perform the method and check the result.
        self.assertEqual(stub.results, (response_pb,))
        result = column_family.delete()
        self.assertEqual(stub.results, ())
        self.assertEqual(result, expected_result)
        self.assertEqual(stub.method_calls, [(
            'ModifyColumnFamilies',
            (request_pb,),
            {},
        )])