diff options
author | Joffrey F <f.joffrey@gmail.com> | 2015-04-22 18:02:59 -0700 |
---|---|---|
committer | Joffrey F <f.joffrey@gmail.com> | 2015-04-22 18:02:59 -0700 |
commit | 8316fa4e03571e2c7ce4bc9fd91f7f86ee39a254 (patch) | |
tree | b75b732f5acdc3cb74cf65ecece848df9a0f4190 | |
parent | 7e7d8ee7ac2dc8458c7d7303fc5e1d5ca3c790ab (diff) | |
parent | 6228929a88575c9c0e250bc1969e9611e542abc4 (diff) | |
download | docker-py-8316fa4e03571e2c7ce4bc9fd91f7f86ee39a254.tar.gz |
Merge pull request #555 from docker/client_side_trunc
Handle ID truncate on client side in containers list
-rw-r--r-- | docker/client.py | 5 | ||||
-rw-r--r-- | tests/integration_test.py | 12 | ||||
-rw-r--r-- | tests/test.py | 2 |
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 |