def test_sls_build(self, *args): ''' test build sls image. ''' docker_start_mock = MagicMock( return_value={}) docker_create_mock = MagicMock( return_value={'Id': 'ID', 'Name': 'NAME'}) docker_stop_mock = MagicMock( return_value={'state': {'old': 'running', 'new': 'stopped'}, 'result': True}) docker_rm_mock = MagicMock(return_value={}) docker_commit_mock = MagicMock( return_value={'Id': 'ID2', 'Image': 'foo', 'Time_Elapsed': 42}) docker_sls_mock = MagicMock( return_value={ "file_|-/etc/test.sh_|-/etc/test.sh_|-managed": { "comment": "File /etc/test.sh is in the correct state", "name": "/etc/test.sh", "start_time": "07:04:26.834792", "result": True, "duration": 13.492, "__run_num__": 0, "changes": {} }, "test_|-always-passes_|-foo_|-succeed_without_changes": { "comment": "Success!", "name": "foo", "start_time": "07:04:26.848915", "result": True, "duration": 0.363, "__run_num__": 1, "changes": {} } }) ret = None with patch.object(docker_mod, 'start', docker_start_mock): with patch.object(docker_mod, 'create', docker_create_mock): with patch.object(docker_mod, 'stop', docker_stop_mock): with patch.object(docker_mod, 'commit', docker_commit_mock): with patch.object(docker_mod, 'sls', docker_sls_mock): with patch.object(docker_mod, 'rm_', docker_rm_mock): ret = docker_mod.sls_build( 'foo', mods='foo', ) docker_create_mock.assert_called_once_with( cmd='sleep infinity', image='opensuse/python', interactive=True, tty=True) docker_start_mock.assert_called_once_with('ID') docker_sls_mock.assert_called_once_with('ID', 'foo', 'base') docker_stop_mock.assert_called_once_with('ID') docker_rm_mock.assert_called_once_with('ID') docker_commit_mock.assert_called_once_with('ID', 'foo') self.assertEqual( {'Id': 'ID2', 'Image': 'foo', 'Time_Elapsed': 42}, ret)
def test_sls_build_dryrun(): """ test build sls image in dryrun mode. """ docker_start_mock = MagicMock(return_value={}) docker_create_mock = MagicMock(return_value={"Id": "ID", "Name": "NAME"}) docker_stop_mock = MagicMock(return_value={ "state": { "old": "running", "new": "stopped" }, "result": True }) docker_rm_mock = MagicMock(return_value={}) docker_sls_mock = MagicMock( return_value={ "file_|-/etc/test.sh_|-/etc/test.sh_|-managed": { "comment": "File /etc/test.sh is in the correct state", "name": "/etc/test.sh", "start_time": "07:04:26.834792", "result": True, "duration": 13.492, "__run_num__": 0, "changes": {}, }, "test_|-always-passes_|-foo_|-succeed_without_changes": { "comment": "Success!", "name": "foo", "start_time": "07:04:26.848915", "result": True, "duration": 0.363, "__run_num__": 1, "changes": {}, }, }) ret = None with patch.object(docker_mod, "start_", docker_start_mock), patch.object( docker_mod, "create", docker_create_mock), patch.object( docker_mod, "stop", docker_stop_mock), patch.object( docker_mod, "rm_", docker_rm_mock), patch.object(docker_mod, "sls", docker_sls_mock): ret = docker_mod.sls_build("foo", mods="foo", dryrun=True) docker_create_mock.assert_called_once_with(cmd="sleep infinity", image="opensuse/python", interactive=True, tty=True) docker_start_mock.assert_called_once_with("ID") docker_sls_mock.assert_called_once_with("ID", "foo") docker_stop_mock.assert_called_once_with("ID") docker_rm_mock.assert_called_once_with("ID") assert { "file_|-/etc/test.sh_|-/etc/test.sh_|-managed": { "comment": "File /etc/test.sh is in the correct state", "name": "/etc/test.sh", "start_time": "07:04:26.834792", "result": True, "duration": 13.492, "__run_num__": 0, "changes": {}, }, "test_|-always-passes_|-foo_|-succeed_without_changes": { "comment": "Success!", "name": "foo", "start_time": "07:04:26.848915", "result": True, "duration": 0.363, "__run_num__": 1, "changes": {}, }, } == ret