def test_create_with_labels_dictlist(self, *args): ''' Create container with labels dictlist. ''' __salt__ = { 'config.get': Mock(), 'mine.send': Mock(), } host_config = {} client = Mock() client.api_version = '1.19' client.create_host_config.return_value = host_config client.create_container.return_value = {} with patch.dict(dockerng_mod.__dict__, {'__salt__': __salt__}): with patch.dict(dockerng_mod.__context__, {'docker.client': client}): dockerng_mod.create( 'image', name='ctn', labels=[{'KEY1': 'VALUE1'}, {'KEY2': 'VALUE2'}], validate_input=True, ) client.create_container.assert_called_once_with( labels={'KEY1': 'VALUE1', 'KEY2': 'VALUE2'}, host_config=host_config, image='image', name='ctn', )
def test_create_with_labels_dictlist(self, *args): ''' Create container with labels dictlist. ''' __salt__ = { 'config.get': Mock(), 'mine.send': Mock(), } host_config = {} client = Mock() client.api_version = '1.19' client.create_host_config.return_value = host_config client.create_container.return_value = {} with patch.dict(dockerng_mod.__dict__, {'__salt__': __salt__}): with patch.dict(dockerng_mod.__context__, {'docker.client': client}): dockerng_mod.create( 'image', name='ctn', labels=[{ 'KEY1': 'VALUE1' }, { 'KEY2': 'VALUE2' }], validate_input=True, ) client.create_container.assert_called_once_with( labels={ 'KEY1': 'VALUE1', 'KEY2': 'VALUE2' }, host_config=host_config, image='image', name='ctn', )
def test_create_with_labels_list(self, *args): ''' Create container with labels list. ''' __salt__ = { 'config.get': Mock(), 'mine.send': Mock(), 'dockerng.version': MagicMock(return_value={}), } host_config = {} client = Mock() client.api_version = '1.19' client.create_host_config.return_value = host_config client.create_container.return_value = {} get_client_mock = MagicMock(return_value=client) with patch.dict(dockerng_mod.__dict__, {'__salt__': __salt__}): with patch.object(dockerng_mod, '_get_client', get_client_mock): with patch.object(dockerng_mod, 'get_client_args', self.client_args_mock): dockerng_mod.create( 'image', name='ctn', labels=['KEY1', 'KEY2'], validate_input=True, ) client.create_container.assert_called_once_with( labels=['KEY1', 'KEY2'], host_config=host_config, image='image', name='ctn', )
def test_create_with_arg_cmd(self, *args): ''' When cmd argument is passed check it is renamed to command. ''' __salt__ = { 'config.get': Mock(), 'mine.send': Mock(), } host_config = {} client = Mock() client.api_version = '1.19' client.create_host_config.return_value = host_config client.create_container.return_value = {} with patch.dict(dockerng_mod.__dict__, {'__salt__': __salt__}): with patch.dict(dockerng_mod.__context__, {'docker.client': client}): dockerng_mod.create('image', cmd='ls', name='ctn') client.create_container.assert_called_once_with( command='ls', host_config=host_config, image='image', name='ctn')
def test_create_send_host_config(self, *args): ''' Check host_config object is passed to create_container. ''' __salt__ = { 'config.get': Mock(), 'mine.send': Mock(), } host_config = {'PublishAllPorts': True} client = Mock() client.api_version = '1.19' client.create_host_config.return_value = host_config client.create_container.return_value = {} with patch.dict(dockerng_mod.__dict__, {'__salt__': __salt__}): with patch.dict(dockerng_mod.__context__, {'docker.client': client}): dockerng_mod.create('image', name='ctn', publish_all_ports=True) client.create_container.assert_called_once_with( host_config=host_config, image='image', name='ctn')