mirror of https://github.com/docker/docker-py.git
rename() tests and docs
This commit is contained in:
parent
35c4cbd9c4
commit
a7f7fbb0fd
|
@ -526,6 +526,15 @@ Remove an image. Similar to the `docker rmi` command.
|
||||||
* force (bool): Force removal of the image
|
* force (bool): Force removal of the image
|
||||||
* noprune (bool): Do not delete untagged parents
|
* noprune (bool): Do not delete untagged parents
|
||||||
|
|
||||||
|
## rename
|
||||||
|
|
||||||
|
Rename a container. Similar to the `docker rename` command.
|
||||||
|
|
||||||
|
**Params**:
|
||||||
|
|
||||||
|
* container (str): ID of the container to rename
|
||||||
|
* name (str): New name for the container
|
||||||
|
|
||||||
## restart
|
## restart
|
||||||
|
|
||||||
Restart a container. Similar to the `docker restart` command.
|
Restart a container. Similar to the `docker restart` command.
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
CURRENT_VERSION = 'v1.16'
|
CURRENT_VERSION = 'v1.17'
|
||||||
|
|
||||||
FAKE_CONTAINER_ID = '3cc2351ab11b'
|
FAKE_CONTAINER_ID = '3cc2351ab11b'
|
||||||
FAKE_IMAGE_ID = 'e9aa60c60128'
|
FAKE_IMAGE_ID = 'e9aa60c60128'
|
||||||
|
@ -271,6 +271,11 @@ def post_fake_restart_container():
|
||||||
return status_code, response
|
return status_code, response
|
||||||
|
|
||||||
|
|
||||||
|
def post_fake_rename_container():
|
||||||
|
status_code = 204
|
||||||
|
return status_code, None
|
||||||
|
|
||||||
|
|
||||||
def delete_fake_remove_container():
|
def delete_fake_remove_container():
|
||||||
status_code = 200
|
status_code = 200
|
||||||
response = {'Id': FAKE_CONTAINER_ID}
|
response = {'Id': FAKE_CONTAINER_ID}
|
||||||
|
@ -348,6 +353,8 @@ fake_responses = {
|
||||||
post_fake_resize_container,
|
post_fake_resize_container,
|
||||||
'{1}/{0}/containers/3cc2351ab11b/json'.format(CURRENT_VERSION, prefix):
|
'{1}/{0}/containers/3cc2351ab11b/json'.format(CURRENT_VERSION, prefix):
|
||||||
get_fake_inspect_container,
|
get_fake_inspect_container,
|
||||||
|
'{1}/{0}/containers/3cc2351ab11b/rename'.format(CURRENT_VERSION, prefix):
|
||||||
|
post_fake_rename_container,
|
||||||
'{1}/{0}/images/e9aa60c60128/tag'.format(CURRENT_VERSION, prefix):
|
'{1}/{0}/images/e9aa60c60128/tag'.format(CURRENT_VERSION, prefix):
|
||||||
post_fake_tag_image,
|
post_fake_tag_image,
|
||||||
'{1}/{0}/containers/3cc2351ab11b/wait'.format(CURRENT_VERSION, prefix):
|
'{1}/{0}/containers/3cc2351ab11b/wait'.format(CURRENT_VERSION, prefix):
|
||||||
|
|
|
@ -322,6 +322,18 @@ class TestCreateContainerWithName(BaseTestCase):
|
||||||
self.assertEqual('/foobar', inspect['Name'])
|
self.assertEqual('/foobar', inspect['Name'])
|
||||||
|
|
||||||
|
|
||||||
|
class TestRenameContainer(BaseTestCase):
|
||||||
|
def runTest(self):
|
||||||
|
name = 'hong_meiling'
|
||||||
|
res = self.client.create_container('busybox', 'true')
|
||||||
|
self.assertIn('Id', res)
|
||||||
|
self.tmp_containers.append(res['Id'])
|
||||||
|
self.client.rename(res, name)
|
||||||
|
inspect = self.client.inspect_container(res['Id'])
|
||||||
|
self.assertIn('Name', inspect)
|
||||||
|
self.assertEqual(name, inspect['Name'])
|
||||||
|
|
||||||
|
|
||||||
class TestStartContainer(BaseTestCase):
|
class TestStartContainer(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
res = self.client.create_container('busybox', 'true')
|
res = self.client.create_container('busybox', 'true')
|
||||||
|
|
|
@ -1256,6 +1256,21 @@ class DockerClientTest(Cleanup, unittest.TestCase):
|
||||||
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_rename_container(self):
|
||||||
|
try:
|
||||||
|
self.client.rename(
|
||||||
|
{'Id': fake_api.FAKE_CONTAINER_ID},
|
||||||
|
name='foobar'
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
self.fail('Command shold not raise exception: {0}'.format(e))
|
||||||
|
|
||||||
|
fake_request.assert_called_with(
|
||||||
|
url_prefix + 'containers/3cc2351ab11b/rename',
|
||||||
|
params={'name': 'foobar'},
|
||||||
|
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||||
|
)
|
||||||
|
|
||||||
def test_wait(self):
|
def test_wait(self):
|
||||||
try:
|
try:
|
||||||
self.client.wait(fake_api.FAKE_CONTAINER_ID)
|
self.client.wait(fake_api.FAKE_CONTAINER_ID)
|
||||||
|
|
Loading…
Reference in New Issue