diff --git a/compose/container.py b/compose/container.py index 2565c8ffc..3a1ce0b9f 100644 --- a/compose/container.py +++ b/compose/container.py @@ -60,7 +60,7 @@ class Container(object): @property def short_id(self): - return self.id[:10] + return self.id[:12] @property def name(self): diff --git a/tests/unit/container_test.py b/tests/unit/container_test.py index 886911504..189b0c992 100644 --- a/tests/unit/container_test.py +++ b/tests/unit/container_test.py @@ -12,8 +12,9 @@ from compose.container import get_container_name class ContainerTest(unittest.TestCase): def setUp(self): + self.container_id = "abcabcabcbabc12345" self.container_dict = { - "Id": "abc", + "Id": self.container_id, "Image": "busybox:latest", "Command": "top", "Created": 1387384730, @@ -41,19 +42,22 @@ class ContainerTest(unittest.TestCase): self.assertEqual( container.dictionary, { - "Id": "abc", + "Id": self.container_id, "Image": "busybox:latest", "Name": "/composetest_db_1", }) def test_from_ps_prefixed(self): - self.container_dict['Names'] = ['/swarm-host-1' + n for n in self.container_dict['Names']] + self.container_dict['Names'] = [ + '/swarm-host-1' + n for n in self.container_dict['Names'] + ] - container = Container.from_ps(None, - self.container_dict, - has_been_inspected=True) + container = Container.from_ps( + None, + self.container_dict, + has_been_inspected=True) self.assertEqual(container.dictionary, { - "Id": "abc", + "Id": self.container_id, "Image": "busybox:latest", "Name": "/composetest_db_1", }) @@ -142,6 +146,10 @@ class ContainerTest(unittest.TestCase): self.assertEqual(container.get('HostConfig.VolumesFrom'), ["volume_id"]) self.assertEqual(container.get('Foo.Bar.DoesNotExist'), None) + def test_short_id(self): + container = Container(None, self.container_dict, has_been_inspected=True) + assert container.short_id == self.container_id[:12] + class GetContainerNameTestCase(unittest.TestCase):