|
| 1 | +# Copyright 2015 Google Inc. All rights reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | + |
| 16 | +import unittest2 |
| 17 | + |
| 18 | + |
| 19 | +class TestCluster(unittest2.TestCase): |
| 20 | + |
| 21 | + def _getTargetClass(self): |
| 22 | + from gcloud.bigtable.cluster import Cluster |
| 23 | + return Cluster |
| 24 | + |
| 25 | + def _makeOne(self, *args, **kwargs): |
| 26 | + return self._getTargetClass()(*args, **kwargs) |
| 27 | + |
| 28 | + def test_constructor_defaults(self): |
| 29 | + zone = 'zone' |
| 30 | + cluster_id = 'cluster-id' |
| 31 | + client = object() |
| 32 | + |
| 33 | + cluster = self._makeOne(zone, cluster_id, client) |
| 34 | + self.assertEqual(cluster.zone, zone) |
| 35 | + self.assertEqual(cluster.cluster_id, cluster_id) |
| 36 | + self.assertEqual(cluster.display_name, cluster_id) |
| 37 | + self.assertEqual(cluster.serve_nodes, 3) |
| 38 | + self.assertTrue(cluster._client is client) |
| 39 | + |
| 40 | + def test_constructor_non_default(self): |
| 41 | + zone = 'zone' |
| 42 | + cluster_id = 'cluster-id' |
| 43 | + display_name = 'display_name' |
| 44 | + serve_nodes = 8 |
| 45 | + client = object() |
| 46 | + |
| 47 | + cluster = self._makeOne(zone, cluster_id, client, |
| 48 | + display_name=display_name, |
| 49 | + serve_nodes=serve_nodes) |
| 50 | + self.assertEqual(cluster.zone, zone) |
| 51 | + self.assertEqual(cluster.cluster_id, cluster_id) |
| 52 | + self.assertEqual(cluster.display_name, display_name) |
| 53 | + self.assertEqual(cluster.serve_nodes, serve_nodes) |
| 54 | + self.assertTrue(cluster._client is client) |
| 55 | + |
| 56 | + def test_table_factory(self): |
| 57 | + from gcloud.bigtable.table import Table |
| 58 | + |
| 59 | + zone = 'zone' |
| 60 | + cluster_id = 'cluster-id' |
| 61 | + cluster = self._makeOne(zone, cluster_id, None) |
| 62 | + |
| 63 | + table_id = 'table_id' |
| 64 | + table = cluster.table(table_id) |
| 65 | + self.assertTrue(isinstance(table, Table)) |
| 66 | + self.assertEqual(table.table_id, table_id) |
| 67 | + self.assertEqual(table._cluster, cluster) |
0 commit comments