Skip to content

Commit adbf19b

Browse files
committed
Merge pull request #246 from d11wtq/feature/resize
Add resize() method to Client
2 parents a8e03d3 + 1ec551c commit adbf19b

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

docker/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,15 @@ def start(self, container, binds=None, port_bindings=None, lxc_conf=None,
811811
res = self._post_json(url, data=start_config)
812812
self._raise_for_status(res)
813813

814+
def resize(self, container, height, width):
815+
if isinstance(container, dict):
816+
container = container.get('Id')
817+
818+
params = {'h': height, 'w': width}
819+
url = self._url("/containers/{0}/resize".format(container))
820+
res = self._post(url, params=params)
821+
self._raise_for_status(res)
822+
814823
def stop(self, container, timeout=10):
815824
if isinstance(container, dict):
816825
container = container.get('Id')

tests/fake_api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ def post_fake_start_container():
103103
return status_code, response
104104

105105

106+
def post_fake_resize_container():
107+
status_code = 200
108+
response = {'Id': FAKE_CONTAINER_ID}
109+
return status_code, response
110+
111+
106112
def post_fake_create_container():
107113
status_code = 200
108114
response = {'Id': FAKE_CONTAINER_ID}
@@ -310,6 +316,8 @@ def post_fake_tag_image():
310316
get_fake_containers,
311317
'{1}/{0}/containers/3cc2351ab11b/start'.format(CURRENT_VERSION, prefix):
312318
post_fake_start_container,
319+
'{1}/{0}/containers/3cc2351ab11b/resize'.format(CURRENT_VERSION, prefix):
320+
post_fake_resize_container,
313321
'{1}/{0}/containers/3cc2351ab11b/json'.format(CURRENT_VERSION, prefix):
314322
get_fake_inspect_container,
315323
'{1}/{0}/images/e9aa60c60128/tag'.format(CURRENT_VERSION, prefix):

tests/test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,22 @@ def test_start_container_with_dict_instead_of_id(self):
690690
docker.client.DEFAULT_TIMEOUT_SECONDS
691691
)
692692

693+
def test_resize_container(self):
694+
try:
695+
self.client.resize(
696+
{'Id': fake_api.FAKE_CONTAINER_ID},
697+
height=15,
698+
width=120
699+
)
700+
except Exception as e:
701+
self.fail('Command should not raise exception: {0}'.format(e))
702+
703+
fake_request.assert_called_with(
704+
url_prefix + 'containers/3cc2351ab11b/resize',
705+
params={'h': 15, 'w': 120},
706+
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
707+
)
708+
693709
def test_wait(self):
694710
try:
695711
self.client.wait(fake_api.FAKE_CONTAINER_ID)

0 commit comments

Comments
 (0)