def test_do_docker_create(self, mockClient):
"""
Assert that the docker_create task
calls the docker client.create_container() function.
"""
image = "IMAGENAME"
volumes = ['/:/data/output:z',
'/:/data/input:ro']
memory_limit = '1g'
command = "echo test"
config = {}
environment = {'a': 1, 'b': 2}
label = {"type": "delft3d"}
folder = ['input', 'output']
name = 'test-8172318273'
workingdir = os.path.join(os.getcwd(), 'test')
folders = [os.path.join(workingdir, f) for f in folder]
parameters = {u'test':
{u'1': u'a', u'2': u'b', 'units': 'ignoreme'}
}
mockClient.return_value.create_host_config.return_value = config
do_docker_create.delay(label, parameters, environment, name,
image, volumes, memory_limit, folders, command)
# Assert that docker is called
mockClient.return_value.create_container.assert_called_with(
image,
host_config=config,
command=command,
name=name,
environment=environment,
labels=label
)
# Assert that folders are created
listdir = os.listdir(workingdir)
for f in listdir:
self.assertIn(f, listdir)
for folder in folders:
ini = os.path.join(folder, 'input.ini')
self.assertTrue(os.path.isfile(ini))
config = configparser.SafeConfigParser()
config.readfp(open(ini))
for key in parameters.keys():
self.assertTrue(config.has_section(key))
for option, value in parameters[key].items():
if option != 'units':
self.assertTrue(config.has_option(key, option))
self.assertEqual(config.get(key, option), value)
else: # units should be ignored
self.assertFalse(config.has_option(key, option))
评论列表
文章目录