Kaydet (Commit) 6f239fbf authored tarafından Flavio Curella's avatar Flavio Curella

Make resources hashable, so that they can be added to `set`s

Signed-off-by: 's avatarFlavio Curella <flavio.curella@gmail.com>
üst d024b1bd
......@@ -23,6 +23,9 @@ class Model(object):
def __eq__(self, other):
return isinstance(other, self.__class__) and self.id == other.id
def __hash__(self):
return hash("%s:%s" % (self.__class__.__name__, self.id))
@property
def id(self):
"""
......
......@@ -12,3 +12,17 @@ class ModelTest(unittest.TestCase):
container.reload()
assert client.api.inspect_container.call_count == 2
assert container.attrs['Name'] == "foobar"
def test_hash(self):
client = make_fake_client()
container1 = client.containers.get(FAKE_CONTAINER_ID)
my_set = set([container1])
assert len(my_set) == 1
container2 = client.containers.get(FAKE_CONTAINER_ID)
my_set.add(container2)
assert len(my_set) == 1
image1 = client.images.get(FAKE_CONTAINER_ID)
my_set.add(image1)
assert len(my_set) == 2
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment