diff --git a/tests/fake_api.py b/tests/fake_api.py index 861c8b35..fc544af6 100644 --- a/tests/fake_api.py +++ b/tests/fake_api.py @@ -237,6 +237,18 @@ def post_fake_kill_container(): return status_code, response +def post_fake_pause_container(): + status_code = 200 + response = {'Id': FAKE_CONTAINER_ID} + return status_code, response + + +def post_fake_unpause_container(): + status_code = 200 + response = {'Id': FAKE_CONTAINER_ID} + return status_code, response + + def post_fake_restart_container(): status_code = 200 response = {'Id': FAKE_CONTAINER_ID} @@ -334,6 +346,10 @@ fake_responses = { post_fake_stop_container, '{1}/{0}/containers/3cc2351ab11b/kill'.format(CURRENT_VERSION, prefix): post_fake_kill_container, + '{1}/{0}/containers/3cc2351ab11b/pause'.format(CURRENT_VERSION, prefix): + post_fake_pause_container, + '{1}/{0}/containers/3cc2351ab11b/unpause'.format(CURRENT_VERSION, prefix): + post_fake_unpause_container, '{1}/{0}/containers/3cc2351ab11b/json'.format(CURRENT_VERSION, prefix): get_fake_port, '{1}/{0}/containers/3cc2351ab11b/restart'.format(CURRENT_VERSION, prefix): diff --git a/tests/integration_test.py b/tests/integration_test.py index d4900b7f..c22971f7 100644 --- a/tests/integration_test.py +++ b/tests/integration_test.py @@ -627,6 +627,37 @@ class TestRestartingContainer(BaseTestCase): res = [x for x in containers if 'Id' in x and x['Id'].startswith(id)] self.assertEqual(len(res), 0) + +class TestPauseUnpauseContainer(BaseTestCase): + def runTest(self): + container = self.client.create_container('busybox', ['sleep', '9999']) + id = container['Id'] + self.client.start(id) + self.tmp_containers.append(id) + + self.client.pause(id) + container_info = self.client.inspect_container(id) + self.assertIn('State', container_info) + state = container_info['State'] + self.assertIn('ExitCode', state) + self.assertEqual(state['ExitCode'], 0) + self.assertIn('Running', state) + self.assertEqual(state['Running'], True) + self.assertIn('Paused', state) + self.assertEqual(state['Paused'], True) + + self.client.unpause(id) + container_info = self.client.inspect_container(id) + self.assertIn('State', container_info) + state = container_info['State'] + self.assertIn('ExitCode', state) + self.assertEqual(state['ExitCode'], 0) + self.assertIn('Running', state) + self.assertEqual(state['Running'], True) + self.assertIn('Paused', state) + self.assertEqual(state['Paused'], False) + + ################# # LINKS TESTS # ################# diff --git a/tests/test.py b/tests/test.py index 984e350e..1e3ed2ac 100644 --- a/tests/test.py +++ b/tests/test.py @@ -1064,6 +1064,26 @@ class DockerClientTest(Cleanup, unittest.TestCase): timeout=(docker.client.DEFAULT_TIMEOUT_SECONDS + timeout) ) + def test_pause_container(self): + try: + self.client.pause(fake_api.FAKE_CONTAINER_ID) + except Exception as e: + self.fail('Command should not raise exception: {0}'.format(e)) + fake_request.assert_called_with( + url_prefix + 'containers/3cc2351ab11b/pause', + timeout=(docker.client.DEFAULT_TIMEOUT_SECONDS) + ) + + def test_unpause_container(self): + try: + self.client.unpause(fake_api.FAKE_CONTAINER_ID) + except Exception as e: + self.fail('Command should not raise exception: {0}'.format(e)) + fake_request.assert_called_with( + url_prefix + 'containers/3cc2351ab11b/unpause', + timeout=(docker.client.DEFAULT_TIMEOUT_SECONDS) + ) + def test_kill_container(self): try: self.client.kill(fake_api.FAKE_CONTAINER_ID)