-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also adding a table() factory in Cluster.
- Loading branch information
Showing
5 changed files
with
133 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright 2015 Google Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""User friendly container for Google Cloud Bigtable Table.""" | ||
|
||
|
||
class Table(object): | ||
"""Representation of a Google Cloud Bigtable Table. | ||
:type table_id: string | ||
:param table_id: The ID of the table. | ||
:type cluster: :class:`.cluster.Cluster` | ||
:param cluster: The cluster that owns the table. | ||
""" | ||
|
||
def __init__(self, table_id, cluster): | ||
self.table_id = table_id | ||
self._cluster = cluster | ||
|
||
@property | ||
def cluster(self): | ||
"""Getter for table's cluster. | ||
:rtype: :class:`.cluster.Cluster` | ||
:returns: The cluster stored on the table. | ||
""" | ||
return self._cluster | ||
|
||
@property | ||
def name(self): | ||
"""Table name used in requests. | ||
.. note:: | ||
This property will not change if ``table_id`` does not, but the | ||
return value is not cached. | ||
The table name is of the form | ||
"projects/*/zones/*/clusters/*/tables/{table_id}" | ||
:rtype: string | ||
:returns: The table name. | ||
""" | ||
return self.cluster.name + '/tables/' + self.table_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright 2015 Google Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
import unittest2 | ||
|
||
|
||
TABLE_ID = 'table-id' | ||
|
||
|
||
class TestTable(unittest2.TestCase): | ||
|
||
def _getTargetClass(self): | ||
from gcloud_bigtable.table import Table | ||
return Table | ||
|
||
def _makeOne(self, *args, **kwargs): | ||
return self._getTargetClass()(*args, **kwargs) | ||
|
||
def test_constructor(self): | ||
cluster = object() | ||
table = self._makeOne(TABLE_ID, cluster) | ||
self.assertEqual(table.table_id, TABLE_ID) | ||
self.assertTrue(table._cluster is cluster) | ||
|
||
def test_cluster_getter(self): | ||
cluster = object() | ||
table = self._makeOne(TABLE_ID, cluster) | ||
self.assertTrue(table.cluster is cluster) | ||
|
||
def test_name_property(self): | ||
cluster_name = 'cluster_name' | ||
cluster = _Cluster(cluster_name) | ||
table = self._makeOne(TABLE_ID, cluster) | ||
expected_name = cluster_name + '/tables/' + TABLE_ID | ||
self.assertEqual(table.name, expected_name) | ||
|
||
|
||
class _Cluster(object): | ||
|
||
def __init__(self, name): | ||
self.name = name |