From a710fbf60a8015a3a9acabe739d40e0a3ab894ce Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Mon, 1 Feb 2016 14:19:43 -0800 Subject: [PATCH] Unit test for Client.update_container method Signed-off-by: Joffrey F --- tests/unit/container_test.py | 18 ++++++++++++++++++ tests/unit/fake_api.py | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/tests/unit/container_test.py b/tests/unit/container_test.py index c2b25734..621e471b 100644 --- a/tests/unit/container_test.py +++ b/tests/unit/container_test.py @@ -1407,3 +1407,21 @@ class ContainerTest(DockerClientTest): params={'ps_args': 'waux'}, timeout=DEFAULT_TIMEOUT_SECONDS ) + + @requires_api_version('1.22') + def test_container_update(self): + self.client.update_container( + fake_api.FAKE_CONTAINER_ID, mem_limit='2k', cpu_shares=124, + blkio_weight=345 + ) + args = fake_request.call_args + self.assertEqual( + args[0][1], url_prefix + 'containers/3cc2351ab11b/update' + ) + self.assertEqual( + json.loads(args[1]['data']), + {'Memory': 2 * 1024, 'CpuShares': 124, 'BlkioWeight': 345} + ) + self.assertEqual( + args[1]['headers']['Content-Type'], 'application/json' + ) diff --git a/tests/unit/fake_api.py b/tests/unit/fake_api.py index 8852da02..99525956 100644 --- a/tests/unit/fake_api.py +++ b/tests/unit/fake_api.py @@ -441,6 +441,11 @@ def get_fake_volume(): def fake_remove_volume(): return 204, None + +def post_fake_update_container(): + return 200, {'Warnings': []} + + # Maps real api url to fake response callback prefix = 'http+docker://localunixsocket' fake_responses = { @@ -478,6 +483,8 @@ fake_responses = { get_fake_diff, '{1}/{0}/containers/3cc2351ab11b/export'.format(CURRENT_VERSION, prefix): get_fake_export, + '{1}/{0}/containers/3cc2351ab11b/update'.format(CURRENT_VERSION, prefix): + post_fake_update_container, '{1}/{0}/containers/3cc2351ab11b/exec'.format(CURRENT_VERSION, prefix): post_fake_exec_create, '{1}/{0}/exec/d5d177f121dc/start'.format(CURRENT_VERSION, prefix):