Skip to content

Commit a7f7fbb

Browse files
committed
rename() tests and docs
1 parent 35c4cbd commit a7f7fbb

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

docs/api.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,15 @@ Remove an image. Similar to the `docker rmi` command.
526526
* force (bool): Force removal of the image
527527
* noprune (bool): Do not delete untagged parents
528528

529+
## rename
530+
531+
Rename a container. Similar to the `docker rename` command.
532+
533+
**Params**:
534+
535+
* container (str): ID of the container to rename
536+
* name (str): New name for the container
537+
529538
## restart
530539

531540
Restart a container. Similar to the `docker restart` command.

tests/fake_api.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
CURRENT_VERSION = 'v1.16'
15+
CURRENT_VERSION = 'v1.17'
1616

1717
FAKE_CONTAINER_ID = '3cc2351ab11b'
1818
FAKE_IMAGE_ID = 'e9aa60c60128'
@@ -271,6 +271,11 @@ def post_fake_restart_container():
271271
return status_code, response
272272

273273

274+
def post_fake_rename_container():
275+
status_code = 204
276+
return status_code, None
277+
278+
274279
def delete_fake_remove_container():
275280
status_code = 200
276281
response = {'Id': FAKE_CONTAINER_ID}
@@ -348,6 +353,8 @@ def post_fake_tag_image():
348353
post_fake_resize_container,
349354
'{1}/{0}/containers/3cc2351ab11b/json'.format(CURRENT_VERSION, prefix):
350355
get_fake_inspect_container,
356+
'{1}/{0}/containers/3cc2351ab11b/rename'.format(CURRENT_VERSION, prefix):
357+
post_fake_rename_container,
351358
'{1}/{0}/images/e9aa60c60128/tag'.format(CURRENT_VERSION, prefix):
352359
post_fake_tag_image,
353360
'{1}/{0}/containers/3cc2351ab11b/wait'.format(CURRENT_VERSION, prefix):

tests/integration_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,18 @@ def runTest(self):
322322
self.assertEqual('/foobar', inspect['Name'])
323323

324324

325+
class TestRenameContainer(BaseTestCase):
326+
def runTest(self):
327+
name = 'hong_meiling'
328+
res = self.client.create_container('busybox', 'true')
329+
self.assertIn('Id', res)
330+
self.tmp_containers.append(res['Id'])
331+
self.client.rename(res, name)
332+
inspect = self.client.inspect_container(res['Id'])
333+
self.assertIn('Name', inspect)
334+
self.assertEqual(name, inspect['Name'])
335+
336+
325337
class TestStartContainer(BaseTestCase):
326338
def runTest(self):
327339
res = self.client.create_container('busybox', 'true')

tests/test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,21 @@ def test_resize_container(self):
12561256
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
12571257
)
12581258

1259+
def test_rename_container(self):
1260+
try:
1261+
self.client.rename(
1262+
{'Id': fake_api.FAKE_CONTAINER_ID},
1263+
name='foobar'
1264+
)
1265+
except Exception as e:
1266+
self.fail('Command shold not raise exception: {0}'.format(e))
1267+
1268+
fake_request.assert_called_with(
1269+
url_prefix + 'containers/3cc2351ab11b/rename',
1270+
params={'name': 'foobar'},
1271+
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
1272+
)
1273+
12591274
def test_wait(self):
12601275
try:
12611276
self.client.wait(fake_api.FAKE_CONTAINER_ID)

0 commit comments

Comments
 (0)