Skip to content

Commit

Permalink
Create 1.40 client for device-requests test
Browse files Browse the repository at this point in the history
Signed-off-by: Laurie O <laurie_opperman@hotmail.com>
  • Loading branch information
EpicWink committed Apr 27, 2020
1 parent 32d2e3b commit b9410ab
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions tests/unit/api_container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
import signal

import docker
from docker.api import APIClient
import pytest
import six

from . import fake_api
from ..helpers import requires_api_version
from .api_test import (
BaseAPIClientTest, url_prefix, fake_request, DEFAULT_TIMEOUT_SECONDS,
fake_inspect_container
fake_inspect_container, url_base
)

try:
Expand Down Expand Up @@ -767,10 +768,14 @@ def test_create_container_with_devices(self):
assert args[1]['headers'] == {'Content-Type': 'application/json'}
assert args[1]['timeout'] == DEFAULT_TIMEOUT_SECONDS

@requires_api_version('1.40')
def test_create_container_with_device_requests(self):
self.client.create_container(
'busybox', 'true', host_config=self.client.create_host_config(
client = APIClient(version='1.40')
fake_api.fake_responses.setdefault(
'{0}/v1.40/containers/create'.format(fake_api.prefix),
fake_api.post_fake_create_container,
)
client.create_container(
'busybox', 'true', host_config=client.create_host_config(
device_requests=[
{
'device_ids': [
Expand All @@ -793,9 +798,9 @@ def test_create_container_with_device_requests(self):
)

args = fake_request.call_args
assert args[0][1] == url_prefix + 'containers/create'
assert args[0][1] == url_base + 'v1.40/' + 'containers/create'
expected_payload = self.base_create_payload()
expected_payload['HostConfig'] = self.client.create_host_config()
expected_payload['HostConfig'] = client.create_host_config()
expected_payload['HostConfig']['DeviceRequests'] = [
{
'Driver': '',
Expand All @@ -820,7 +825,8 @@ def test_create_container_with_device_requests(self):
}
]
assert json.loads(args[1]['data']) == expected_payload
assert args[1]['headers'] == {'Content-Type': 'application/json'}
assert args[1]['headers']['Content-Type'] == 'application/json'
assert set(args[1]['headers']) <= {'Content-Type', 'User-Agent'}
assert args[1]['timeout'] == DEFAULT_TIMEOUT_SECONDS

def test_create_container_with_labels_dict(self):
Expand Down

0 comments on commit b9410ab

Please sign in to comment.