| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -197,6 +197,7 @@ class ColumnFamily(object): | |||
| 197 | 197 | ||
| 198 | 198 | We can use a :class:`ColumnFamily` to: | |
| 199 | 199 | ||
| 200 | + * :meth:`create` itself | ||
| 200 | 201 | * :meth:`delete` itself | |
| 201 | 202 | ||
| 202 | 203 | :type column_family_id: str | |
@@ -244,6 +245,24 @@ def __eq__(self, other): | |||
| 244 | 245 | def __ne__(self, other): | |
| 245 | 246 | return not self.__eq__(other) | |
| 246 | 247 | ||
| 248 | + def create(self): | ||
| 249 | + """Create this column family.""" | ||
| 250 | + if self.gc_rule is None: | ||
| 251 | + column_family = data_pb2.ColumnFamily() | ||
| 252 | + else: | ||
| 253 | + column_family = data_pb2.ColumnFamily(gc_rule=self.gc_rule.to_pb()) | ||
| 254 | + request_pb = messages_pb2.CreateColumnFamilyRequest( | ||
| 255 | + name=self._table.name, | ||
| 256 | + column_family_id=self.column_family_id, | ||
| 257 | + column_family=column_family, | ||
| 258 | + ) | ||
| 259 | + client = self._table._cluster._client | ||
| 260 | + # We expect a `.data_pb2.ColumnFamily`. We ignore it since the only | ||
| 261 | + # data it contains are the GC rule and the column family ID already | ||
| 262 | + # stored on this instance. | ||
| 263 | + client._table_stub.CreateColumnFamily(request_pb, | ||
| 264 | + client.timeout_seconds) | ||
| 265 | + | ||
| 247 | 266 | def delete(self): | |
| 248 | 267 | """Delete this column family.""" | |
| 249 | 268 | request_pb = messages_pb2.DeleteColumnFamilyRequest(name=self.name) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -395,6 +395,65 @@ def test___ne__(self): | |||
| 395 | 395 | column_family2 = self._makeOne('column_family_id2', None) | |
| 396 | 396 | self.assertNotEqual(column_family1, column_family2) | |
| 397 | 397 | ||
| 398 | + def _create_test_helper(self, gc_rule=None): | ||
| 399 | + from gcloud.bigtable._generated import ( | ||
| 400 | + bigtable_table_data_pb2 as data_pb2) | ||
| 401 | + from gcloud.bigtable._generated import ( | ||
| 402 | + bigtable_table_service_messages_pb2 as messages_pb2) | ||
| 403 | + from gcloud.bigtable._testing import _FakeStub | ||
| 404 | + | ||
| 405 | + project_id = 'project-id' | ||
| 406 | + zone = 'zone' | ||
| 407 | + cluster_id = 'cluster-id' | ||
| 408 | + table_id = 'table-id' | ||
| 409 | + column_family_id = 'column-family-id' | ||
| 410 | + timeout_seconds = 4 | ||
| 411 | + table_name = ('projects/' + project_id + '/zones/' + zone + | ||
| 412 | + '/clusters/' + cluster_id + '/tables/' + table_id) | ||
| 413 | + | ||
| 414 | + client = _Client(timeout_seconds=timeout_seconds) | ||
| 415 | + table = _Table(table_name, client=client) | ||
| 416 | + column_family = self._makeOne(column_family_id, table, gc_rule=gc_rule) | ||
| 417 | + | ||
| 418 | + # Create request_pb | ||
| 419 | + if gc_rule is None: | ||
| 420 | + column_family_pb = data_pb2.ColumnFamily() | ||
| 421 | + else: | ||
| 422 | + column_family_pb = data_pb2.ColumnFamily(gc_rule=gc_rule.to_pb()) | ||
| 423 | + request_pb = messages_pb2.CreateColumnFamilyRequest( | ||
| 424 | + name=table_name, | ||
| 425 | + column_family_id=column_family_id, | ||
| 426 | + column_family=column_family_pb, | ||
| 427 | + ) | ||
| 428 | + | ||
| 429 | + # Create response_pb | ||
| 430 | + response_pb = data_pb2.ColumnFamily() | ||
| 431 | + | ||
| 432 | + # Patch the stub used by the API method. | ||
| 433 | + client._table_stub = stub = _FakeStub(response_pb) | ||
| 434 | + | ||
| 435 | + # Create expected_result. | ||
| 436 | + expected_result = None # create() has no return value. | ||
| 437 | + | ||
| 438 | + # Perform the method and check the result. | ||
| 439 | + self.assertEqual(stub.results, (response_pb,)) | ||
| 440 | + result = column_family.create() | ||
| 441 | + self.assertEqual(stub.results, ()) | ||
| 442 | + self.assertEqual(result, expected_result) | ||
| 443 | + self.assertEqual(stub.method_calls, [( | ||
| 444 | + 'CreateColumnFamily', | ||
| 445 | + (request_pb, timeout_seconds), | ||
| 446 | + {}, | ||
| 447 | + )]) | ||
| 448 | + | ||
| 449 | + def test_create(self): | ||
| 450 | + self._create_test_helper(gc_rule=None) | ||
| 451 | + | ||
| 452 | + def test_create_with_gc_rule(self): | ||
| 453 | + from gcloud.bigtable.column_family import MaxVersionsGCRule | ||
| 454 | + gc_rule = MaxVersionsGCRule(1337) | ||
| 455 | + self._create_test_helper(gc_rule=gc_rule) | ||
| 456 | + | ||
| 398 | 457 | def test_delete(self): | |
| 399 | 458 | from gcloud.bigtable._generated import ( | |
| 400 | 459 | bigtable_table_service_messages_pb2 as messages_pb2) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments