Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Bigtable Cluster.__eq__. #1238

Merged
merged 1 commit into from
Nov 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions gcloud/bigtable/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,19 @@ def from_pb(cls, cluster_pb, client):
result = cls(match.group('zone'), match.group('cluster_id'), client)
result._update_from_pb(cluster_pb)
return result

def __eq__(self, other):
if not isinstance(other, self.__class__):
return False
# NOTE: This does not compare the configuration values, such as
# the serve_nodes or display_name. Instead, it only compares
# identifying values zone, cluster ID and client. This is
# intentional, since the same cluster can be in different states
# if not synchronized. Clusters with similar zone/cluster
# settings but different clients can't be used in the same way.
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.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,33 @@ def test_from_pb_project_mistmatch(self):
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)


class Test__get_pb_property_value(unittest2.TestCase):

Expand Down