summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Hensley <spaceboy@indirect.com>2014-10-04 23:41:21 -0400
committerPatrick Hensley <spaceboy@indirect.com>2014-10-04 23:46:33 -0400
commit288e53b28b3eaf75260fb65befb9138aa62c49b8 (patch)
treea5fd8f0a0a5750647a9ccf0fc7c730da08e5c7e8
parent75e53f1add3ab5f57984938d346d23e3be840546 (diff)
downloaddocker-py-288e53b28b3eaf75260fb65befb9138aa62c49b8.tar.gz
Unit and integration tests for pause/unpause.
-rw-r--r--tests/fake_api.py16
-rw-r--r--tests/integration_test.py31
-rw-r--r--tests/test.py20
3 files changed, 67 insertions, 0 deletions
diff --git a/tests/fake_api.py b/tests/fake_api.py
index 861c8b3..fc544af 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 d4900b7..c22971f 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 984e350..1e3ed2a 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)