<s> from __future__ import absolute_import <EOL> from __future__ import unicode_literals <EOL> import os <EOL> import docker <EOL> import pytest <EOL> from compose . cli . docker_client import docker_client <EOL> from compose . cli . docker_client import tls_config_from_options <EOL> from tests import mock <EOL> from tests import unittest <EOL> class DockerClientTestCase ( unittest . TestCase ) : <EOL> def test_docker_client_no_home ( self ) : <EOL> with mock . patch . dict ( os . environ ) : <EOL> del os . environ [ '<STR_LIT>' ] <EOL> docker_client ( os . environ ) <EOL> def test_docker_client_with_custom_timeout ( self ) : <EOL> timeout = <NUM_LIT> <EOL> with mock . patch ( '<STR_LIT>' , <NUM_LIT> ) : <EOL> client = docker_client ( os . environ ) <EOL> self . assertEqual ( client . timeout , int ( timeout ) ) <EOL> class TLSConfigTestCase ( unittest . TestCase ) : <EOL> ca_cert = '<STR_LIT>' <EOL> client_cert = '<STR_LIT>' <EOL> key = '<STR_LIT>' <EOL> def test_simple_tls ( self ) : <EOL> options = { '<STR_LIT>' : True } <EOL> result = tls_config_from_options ( options ) <EOL> assert result is True <EOL> def test_tls_ca_cert ( self ) : <EOL> options = { <EOL> '<STR_LIT>' : self . ca_cert , '<STR_LIT>' : True <EOL> } <EOL> result = tls_config_from_options ( options ) <EOL> assert isinstance ( result , docker . tls . TLSConfig ) <EOL> assert result . ca_cert == options [ '<STR_LIT>' ] <EOL> assert result . verify is True <EOL> def test_tls_ca_cert_explicit ( self ) : <EOL> options = { <EOL> '<STR_LIT>' : self . ca_cert , '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True <EOL> } <EOL> result = tls_config_from_options ( options ) <EOL> assert isinstance ( result , docker . tls . TLSConfig ) <EOL> assert result . ca_cert == options [ '<STR_LIT>' ] <EOL> assert result . verify is True <EOL> def test_tls_client_cert ( self ) : <EOL> options = { <EOL> '<STR_LIT>' : self . client_cert , '<STR_LIT>' : self . key <EOL> } <EOL> result = tls_config_from_options ( options ) <EOL> assert isinstance ( result , docker . tls . TLSConfig ) <EOL> assert result . cert == ( options [ '<STR_LIT>' ] , options [ '<STR_LIT>' ] ) <EOL> def test_tls_client_cert_explicit ( self ) : <EOL> options = { <EOL> '<STR_LIT>' : self . client_cert , '<STR_LIT>' : self . key , <EOL> '<STR_LIT>' : True <EOL> } <EOL> result = tls_config_from_options ( options ) <EOL> assert isinstance ( result , docker . tls . TLSConfig ) <EOL> assert result . cert == ( options [ '<STR_LIT>' ] , options [ '<STR_LIT>' ] ) <EOL> def test_tls_client_and_ca ( self ) : <EOL> options = { <EOL> '<STR_LIT>' : self . client_cert , '<STR_LIT>' : self . key , <EOL> '<STR_LIT>' : True , '<STR_LIT>' : self . ca_cert <EOL> } <EOL> result = tls_config_from_options ( options ) <EOL> assert isinstance ( result , docker . tls . TLSConfig ) <EOL> assert result . cert == ( options [ '<STR_LIT>' ] , options [ '<STR_LIT>' ] ) <EOL> assert result . ca_cert == options [ '<STR_LIT>' ] <EOL> assert result . verify is True <EOL> def test_tls_client_and_ca_explicit ( self ) : <EOL> options = { <EOL> '<STR_LIT>' : self . client_cert , '<STR_LIT>' : self . key , <EOL> '<STR_LIT>' : True , '<STR_LIT>' : self . ca_cert , <EOL> '<STR_LIT>' : True <EOL> } <EOL> result = tls_config_from_options ( options ) <EOL> assert isinstance ( result , docker . tls . TLSConfig ) <EOL> assert result . cert == ( options [ '<STR_LIT>' ] , options [ '<STR_LIT>' ] ) <EOL> assert result . ca_cert == options [ '<STR_LIT>' ] <EOL> assert result . verify is True <EOL> def test_tls_client_missing_key ( self ) : <EOL> options = { '<STR_LIT>' : self . client_cert } <EOL> with pytest . raises ( docker . errors . TLSParameterError ) : <EOL> tls_config_from_options ( options ) <EOL> options = { '<STR_LIT>' : self . key } <EOL> with pytest . raises ( docker . errors . TLSParameterError ) : <EOL> tls_config_from_options ( options ) <EOL> def test_assert_hostname_explicit_skip ( self ) : <EOL> options = { '<STR_LIT>' : self . ca_cert , '<STR_LIT>' : True } <EOL> result = tls_config_from_options ( options ) <EOL> assert isinstance ( result , docker . tls . TLSConfig ) <EOL> assert result . assert_hostname is False </s>
