summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <joffrey@docker.com>2015-04-22 17:57:10 -0700
committerJoffrey F <joffrey@docker.com>2015-04-22 18:00:53 -0700
commit6228929a88575c9c0e250bc1969e9611e542abc4 (patch)
treeb75b732f5acdc3cb74cf65ecece848df9a0f4190
parentc328be7deb59077b73d2263cfdf6eaaecc01ad64 (diff)
downloaddocker-py-client_side_trunc.tar.gz
Handle ID truncate on client side in containers list (and changed default from True to False)client_side_trunc
-rw-r--r--docker/client.py5
-rw-r--r--tests/integration_test.py12
-rw-r--r--tests/test.py2
3 files changed, 13 insertions, 6 deletions
diff --git a/docker/client.py b/docker/client.py
index a94849d..00ba0de 100644
--- a/docker/client.py
+++ b/docker/client.py
@@ -411,7 +411,7 @@ class Client(requests.Session):
return self._result(self._post_json(u, data=conf, params=params),
json=True)
- def containers(self, quiet=False, all=False, trunc=True, latest=False,
+ def containers(self, quiet=False, all=False, trunc=False, latest=False,
since=None, before=None, limit=-1, size=False,
filters=None):
params = {
@@ -429,6 +429,9 @@ class Client(requests.Session):
if quiet:
return [{'Id': x['Id']} for x in res]
+ if trunc:
+ for x in res:
+ x['Id'] = x['Id'][:12]
return res
def copy(self, container, resource):
diff --git a/tests/integration_test.py b/tests/integration_test.py
index fe3a339..eb7a0eb 100644
--- a/tests/integration_test.py
+++ b/tests/integration_test.py
@@ -1681,10 +1681,7 @@ class UnixconnTestCase(unittest.TestCase):
# REGRESSION TESTS #
####################
-class TestRegressions(unittest.TestCase):
- def setUp(self):
- self.client = docker.Client(timeout=5, base_url=DEFAULT_BASE_URL)
-
+class TestRegressions(BaseTestCase):
def test_443(self):
dfile = io.BytesIO()
with self.assertRaises(docker.errors.APIError) as exc:
@@ -1693,6 +1690,13 @@ class TestRegressions(unittest.TestCase):
self.assertEqual(exc.exception.response.status_code, 500)
dfile.close()
+ def test_542(self):
+ self.client.start(
+ self.client.create_container('busybox', ['true'])
+ )
+ result = self.client.containers(trunc=True)
+ self.assertEqual(len(result[0]['Id']), 12)
+
if __name__ == '__main__':
c = docker.Client(base_url=DEFAULT_BASE_URL)
diff --git a/tests/test.py b/tests/test.py
index 59bf4cc..f2af58b 100644
--- a/tests/test.py
+++ b/tests/test.py
@@ -312,7 +312,7 @@ class DockerClientTest(Cleanup, base.BaseTestCase):
'since': None,
'size': 0,
'limit': -1,
- 'trunc_cmd': 1,
+ 'trunc_cmd': 0,
'before': None
},
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS