Skip to content

Commit

Permalink
Adding equality check for cluster_standalone.Cluster.
Browse files Browse the repository at this point in the history
This is so we can make the list_zones()/list_clusters()
tests more generic and just check equality of outputs.
  • Loading branch information
dhermes committed Jul 25, 2015
1 parent 396a105 commit 0dc197c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
5 changes: 3 additions & 2 deletions gcloud_bigtable/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,9 @@ def list_clusters(self, timeout_seconds=TIMEOUT_SECONDS):
:rtype: tuple
:returns: A pair of results, the first is a list of
:class:`.cluster_standalone.Cluster` s returned and the second
is a list of strings (the failed zones in the request).
:class:`.cluster_standalone.Cluster` s returned and the
second is a list of strings (the failed zones in the
request).
"""
request_pb = messages_pb2.ListClustersRequest(name=self.project_name)
stub = make_stub(self._credentials, CLUSTER_STUB_FACTORY,
Expand Down
10 changes: 10 additions & 0 deletions gcloud_bigtable/cluster_standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,13 @@ def name(self):
"""
return (self.client.project_name + '/zones/' + self.zone +
'/clusters/' + self.cluster_id)

def __eq__(self, other):
if not isinstance(other, self.__class__):
return False
return (other.zone == self.zone and
other.cluster_id == self.cluster_id and
other.client == self.client)

def __ne__(self, other):
return not self.__eq__(other)
27 changes: 27 additions & 0 deletions gcloud_bigtable/test_cluster_standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,30 @@ def test_from_pb_project_id_mistmatch(self):
klass = self._getTargetClass()
with self.assertRaises(ValueError):
klass.from_pb(cluster_pb, client)

def test___eq__(self):
zone = 'zone'
cluster_id = 'cluster_id'
client = object()
cluster1 = self._makeOne(zone, cluster_id, client)
cluster2 = self._makeOne(zone, cluster_id, client)
self.assertEqual(cluster1, cluster2)

def test___eq__type_differ(self):
cluster1 = self._makeOne('zone', 'cluster_id', 'client')
cluster2 = object()
self.assertNotEqual(cluster1, cluster2)

def test___ne__same_value(self):
zone = 'zone'
cluster_id = 'cluster_id'
client = object()
cluster1 = self._makeOne(zone, cluster_id, client)
cluster2 = self._makeOne(zone, cluster_id, client)
comparison_val = (cluster1 != cluster2)
self.assertFalse(comparison_val)

def test___ne__(self):
cluster1 = self._makeOne('zone1', 'cluster_id1', 'client1')
cluster2 = self._makeOne('zone2', 'cluster_id2', 'client2')
self.assertNotEqual(cluster1, cluster2)

0 comments on commit 0dc197c

Please sign in to comment.