|
|
|
@ -49,7 +49,6 @@ other_package_name = PackageAtomName(
|
|
|
|
|
class TestTemplateExecutor:
|
|
|
|
|
def test_function_to_copy_testfiles(self):
|
|
|
|
|
TemplateWrapper._protected_is_set = False
|
|
|
|
|
|
|
|
|
|
shutil.copytree(os.path.join(CHROOT_PATH, 'etc.backup'),
|
|
|
|
|
os.path.join(CHROOT_PATH, 'etc'),
|
|
|
|
|
symlinks=True)
|
|
|
|
@ -2464,7 +2463,7 @@ class TestTemplateExecutor:
|
|
|
|
|
assert template_executor._get_file_owner(target_path) == chown_value
|
|
|
|
|
assert template_executor._get_file_mode(target_path) == chmod_value
|
|
|
|
|
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_with_the_run_parameter_and_a_target_path_to_an_existing_directory_and_its_text_is_empty__the_method_does_nothing(self):
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_run_parameter_and_a_target_path_to_an_existing_file_from_an_existing_directory_and_its_text_is_empty__the_method_does_nothing(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/run_parameter_testfiles/dir_0')
|
|
|
|
@ -2476,7 +2475,7 @@ class TestTemplateExecutor:
|
|
|
|
|
'/path/to/template',
|
|
|
|
|
save_changes=False)
|
|
|
|
|
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_with_the_run_parameter_and_a_target_path_to_an_existing_directory_and_its_text_is_correct__the_method_runs_a_template_text_in_the_target_directory_and_returns_the_object_with_its_stdout(self):
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_run_parameter_and_a_target_path_to_an_existing_directory_and_its_text_is_correct__the_method_runs_a_template_text_in_the_target_directory_and_returns_the_object_with_its_stdout(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/run_parameter_testfiles/dir_0/file_0')
|
|
|
|
@ -2492,10 +2491,10 @@ print(os.getcwd())'''
|
|
|
|
|
'/path/to/template',
|
|
|
|
|
template_text=template_text,
|
|
|
|
|
save_changes=False)
|
|
|
|
|
assert output['stdout'].strip() == target_path
|
|
|
|
|
assert output['stdout'].strip() == os.path.dirname(target_path)
|
|
|
|
|
assert output['stderr'] is None
|
|
|
|
|
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_with_the_run_parameter_and_a_directory_from_a_target_path_does_not_exist__the_method_throws_TemplateExecutorError_exception(self):
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_run_parameter_and_a_directory_from_a_target_path_does_not_exist__the_method_throws_TemplateExecutorError_exception(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/run_parameter_testfiles/dir_1/file_0')
|
|
|
|
@ -2508,7 +2507,7 @@ print(os.getcwd())'''
|
|
|
|
|
'/path/to/template',
|
|
|
|
|
save_changes=False)
|
|
|
|
|
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_with_the_run_parameter_and_a_target_path_to_an_existing_file_and_its_text_is_correct__the_method_runs_a_template_text_in_a_directory_that_contains_a_file_from_a_target_path_and_returns_the_object_with_its_stdout(self):
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_run_parameter_and_a_target_path_to_an_existing_file_and_its_text_is_correct__the_method_runs_a_template_text_in_a_directory_that_contains_a_file_from_a_target_path_and_returns_the_object_with_its_stdout(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/run_parameter_testfiles/file_0')
|
|
|
|
@ -2527,10 +2526,10 @@ print(os.getcwd())'''
|
|
|
|
|
assert output['stdout'].strip() == os.path.dirname(target_path)
|
|
|
|
|
assert output['stderr'] is None
|
|
|
|
|
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_with_the_run_parameter_and_a_target_path_to_an_unexisting_file__the_method_throws_TemplateExecutorError_exception(self):
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_run_parameter_and_a_target_path_to_an_unexisting_file_from_an_unexisting_directory__the_method_throws_TemplateExecutorError_exception(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/run_parameter_testfiles/file_1')
|
|
|
|
|
'/etc/run_parameter_testfiles/dir_1/file_0')
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'run': '/usr/bin/python'})
|
|
|
|
|
with pytest.raises(TemplateExecutorError):
|
|
|
|
@ -2540,10 +2539,49 @@ print(os.getcwd())'''
|
|
|
|
|
'/path/to/template',
|
|
|
|
|
save_changes=False)
|
|
|
|
|
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_with_the_run_parameter_a_target_path_to_an_existing_directory_and_its_text_is_not_correct__the_method_runs_a_template_text_and_returns_the_object_with_its_stderr(self):
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_run_parameter_and_a_target_path_to_an_unexisting_file_from_an_directory_that_replaced_to_a_file__the_method_throws_TemplateExecutorError_exception(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/run_parameter_testfiles/dir_0')
|
|
|
|
|
'/etc/run_parameter_testfiles/dir_2/file_0')
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'run': '/usr/bin/python'})
|
|
|
|
|
with pytest.raises(TemplateExecutorError):
|
|
|
|
|
template_executor.execute_template(target_path,
|
|
|
|
|
parameters_object,
|
|
|
|
|
FILE,
|
|
|
|
|
'/path/to/template',
|
|
|
|
|
save_changes=False)
|
|
|
|
|
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_of_the_DIR_type_with_the_run_parameter_and_a_target_path_to_an_unexisting_directory__the_method_throws_TemplateExecutorError_exception(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/run_parameter_testfiles/dir_1')
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'run': '/usr/bin/python'})
|
|
|
|
|
with pytest.raises(TemplateExecutorError):
|
|
|
|
|
template_executor.execute_template(target_path,
|
|
|
|
|
parameters_object,
|
|
|
|
|
DIR,
|
|
|
|
|
'/path/to/template',
|
|
|
|
|
save_changes=False)
|
|
|
|
|
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_of_the_DIR_type_with_the_run_parameter_and_a_target_path_to_an_existing_file__the_method_throws_TemplateExecutorError_exception(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/run_parameter_testfiles/dir_2')
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'run': '/usr/bin/python'})
|
|
|
|
|
with pytest.raises(TemplateExecutorError):
|
|
|
|
|
template_executor.execute_template(target_path,
|
|
|
|
|
parameters_object,
|
|
|
|
|
DIR,
|
|
|
|
|
'/path/to/template',
|
|
|
|
|
save_changes=False)
|
|
|
|
|
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_run_parameter_a_target_path_to_an_unexisting_file_from_an_existing_directory_and_its_text_is_not_correct__the_method_runs_a_template_text_and_returns_the_object_with_its_stderr(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/run_parameter_testfiles/dir_0/file_0')
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'run': '/usr/bin/python'})
|
|
|
|
|
traceback_text = '''Traceback (most recent call last):
|
|
|
|
@ -2581,10 +2619,14 @@ print(os.getcwd())'''
|
|
|
|
|
template_text=template_text,
|
|
|
|
|
save_changes=False)
|
|
|
|
|
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_with_the_exec_parameter_and_a_target_path_to_an_existing_directory_and_its_text_is_empty__the_method_creates_an_empty_exec_file_and_saves_a_path_to_exec_file_interpreter_and_a_target_path_as_cwd_path(self):
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_exec_parameter_and_a_target_path_to_an_unexisting_file_from_existing_directory_and_its_text_is_empty__the_method_creates_an_empty_exec_file_and_saves_a_path_to_exec_file_interpreter_and_a_target_path_as_cwd_path(self):
|
|
|
|
|
if os.path.exists(EXECUTE_ARCHIVE_PATH):
|
|
|
|
|
shutil.rmtree(EXECUTE_ARCHIVE_PATH)
|
|
|
|
|
template_executor.execute_files = OrderedDict()
|
|
|
|
|
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/exec_parameter_testfiles/dir_0')
|
|
|
|
|
'/etc/exec_parameter_testfiles/dir_0/file_0')
|
|
|
|
|
interpreter = '/usr/bin/python'
|
|
|
|
|
execute_file_path = os.path.join(EXECUTE_ARCHIVE_PATH, 'exec_0001')
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
@ -2598,19 +2640,20 @@ print(os.getcwd())'''
|
|
|
|
|
assert template_executor.execute_files[execute_file_path][
|
|
|
|
|
'interpreter'] == interpreter
|
|
|
|
|
assert template_executor.execute_files[execute_file_path][
|
|
|
|
|
'cwd_path'] == target_path
|
|
|
|
|
'cwd_path'] == os.path.dirname(target_path)
|
|
|
|
|
with open(os.path.join(EXECUTE_ARCHIVE_PATH,
|
|
|
|
|
'exec_0001'), 'r') as exec_file:
|
|
|
|
|
exec_file_text = exec_file.read()
|
|
|
|
|
assert exec_file_text == ''
|
|
|
|
|
|
|
|
|
|
os.remove(execute_file_path)
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_exec_parameter_and_a_target_path_to_an_unexisting_file_from_an_existing_directory_and_its_text_is_not_empty__the_method_creates_an_exec_file_and_saves_a_path_to_exec_file_interpreter_and_a_target_path_as_cwd_path(self):
|
|
|
|
|
if os.path.exists(EXECUTE_ARCHIVE_PATH):
|
|
|
|
|
shutil.rmtree(EXECUTE_ARCHIVE_PATH)
|
|
|
|
|
template_executor.execute_files = OrderedDict()
|
|
|
|
|
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_with_the_exec_parameter_and_a_target_path_to_an_existing_directory_and_its_text_is_not_empty__the_method_creates_an_exec_file_and_saves_a_path_to_exec_file_interpreter_and_a_target_path_as_cwd_path(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/exec_parameter_testfiles/dir_0')
|
|
|
|
|
'/etc/exec_parameter_testfiles/dir_0/file_0')
|
|
|
|
|
interpreter = '/usr/bin/python'
|
|
|
|
|
execute_file_path = os.path.join(EXECUTE_ARCHIVE_PATH, 'exec_0001')
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
@ -2628,19 +2671,52 @@ print(os.getcwd())'''
|
|
|
|
|
assert template_executor.execute_files[execute_file_path][
|
|
|
|
|
'interpreter'] == interpreter
|
|
|
|
|
assert template_executor.execute_files[execute_file_path][
|
|
|
|
|
'cwd_path'] == target_path
|
|
|
|
|
'cwd_path'] == os.path.dirname(target_path)
|
|
|
|
|
with open(os.path.join(EXECUTE_ARCHIVE_PATH,
|
|
|
|
|
'exec_0001'), 'r') as exec_file:
|
|
|
|
|
exec_file_text = exec_file.read()
|
|
|
|
|
assert exec_file_text == template_text
|
|
|
|
|
|
|
|
|
|
os.remove(execute_file_path)
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_of_the_DIR_type_with_the_exec_parameter_and_a_target_path_to_an_unexisting_directory__the_method_throws_TemplateExecutorError_exception(self):
|
|
|
|
|
if os.path.exists(EXECUTE_ARCHIVE_PATH):
|
|
|
|
|
shutil.rmtree(EXECUTE_ARCHIVE_PATH)
|
|
|
|
|
template_executor.execute_files = OrderedDict()
|
|
|
|
|
|
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/run_parameter_testfiles/dir_1')
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'exec': '/usr/bin/python'})
|
|
|
|
|
with pytest.raises(TemplateExecutorError):
|
|
|
|
|
template_executor.execute_template(target_path,
|
|
|
|
|
parameters_object,
|
|
|
|
|
DIR,
|
|
|
|
|
'/path/to/template',
|
|
|
|
|
save_changes=False)
|
|
|
|
|
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_of_the_DIR_type_with_the_exec_parameter_and_a_target_path_to_an_existing_file__the_method_throws_TemplateExecutorError_exception(self):
|
|
|
|
|
if os.path.exists(EXECUTE_ARCHIVE_PATH):
|
|
|
|
|
shutil.rmtree(EXECUTE_ARCHIVE_PATH)
|
|
|
|
|
template_executor.execute_files = OrderedDict()
|
|
|
|
|
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_with_the_exec_parameter_and_a_target_path_to_an_unexisting_directory__the_method_throws_TemplateExecutorError_exception(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/run_parameter_testfiles/dir_1')
|
|
|
|
|
'/etc/exec_parameter_testfiles/dir_4')
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'exec': '/usr/bin/python'})
|
|
|
|
|
with pytest.raises(TemplateExecutorError):
|
|
|
|
|
template_executor.execute_template(target_path,
|
|
|
|
|
parameters_object,
|
|
|
|
|
DIR,
|
|
|
|
|
'/path/to/template',
|
|
|
|
|
save_changes=False)
|
|
|
|
|
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_exec_parameter_and_a_target_path_to_an_unexisting_file_in_the_directory_that_replaced_to_a_file__the_method_throws_TemplateExecutorError_exception(self):
|
|
|
|
|
if os.path.exists(EXECUTE_ARCHIVE_PATH):
|
|
|
|
|
shutil.rmtree(EXECUTE_ARCHIVE_PATH)
|
|
|
|
|
template_executor.execute_files = OrderedDict()
|
|
|
|
|
|
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/run_parameter_testfiles/dir_4/file_1')
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'exec': '/usr/bin/python'})
|
|
|
|
|
with pytest.raises(TemplateExecutorError):
|
|
|
|
@ -2650,7 +2726,28 @@ print(os.getcwd())'''
|
|
|
|
|
'/path/to/template',
|
|
|
|
|
save_changes=False)
|
|
|
|
|
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_with_the_exec_parameter_and_a_target_path_to_an_existing_file_and_its_text_is_not_empty__the_method_creates_an_exec_file_and_saves_a_path_to_exec_file_interpreter_and_a_path_to_a_file_from_a_target_path_as_cwd_path(self):
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_exec_parameter_and_a_target_path_to_an_unexisting_file_from_unexisting_directory__the_method_throws_TemplateExecutorError_exception(self):
|
|
|
|
|
if os.path.exists(EXECUTE_ARCHIVE_PATH):
|
|
|
|
|
shutil.rmtree(EXECUTE_ARCHIVE_PATH)
|
|
|
|
|
template_executor.execute_files = OrderedDict()
|
|
|
|
|
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/exec_parameter_testfiles/dir_1/file_0')
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'exec': '/usr/bin/python'})
|
|
|
|
|
with pytest.raises(TemplateExecutorError):
|
|
|
|
|
template_executor.execute_template(target_path,
|
|
|
|
|
parameters_object,
|
|
|
|
|
DIR,
|
|
|
|
|
'/path/to/template',
|
|
|
|
|
save_changes=False)
|
|
|
|
|
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_exec_parameter_and_a_target_path_to_an_existing_file_and_its_text_is_not_empty__the_method_creates_an_exec_file_and_saves_a_path_to_exec_file_interpreter_and_a_path_to_a_file_from_a_target_path_as_cwd_path(self):
|
|
|
|
|
if os.path.exists(EXECUTE_ARCHIVE_PATH):
|
|
|
|
|
shutil.rmtree(EXECUTE_ARCHIVE_PATH)
|
|
|
|
|
template_executor.execute_files = OrderedDict()
|
|
|
|
|
|
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/exec_parameter_testfiles/file_0')
|
|
|
|
|
interpreter = '/usr/bin/python'
|
|
|
|
@ -2676,23 +2773,42 @@ print(os.getcwd())'''
|
|
|
|
|
exec_file_text = exec_file.read()
|
|
|
|
|
assert exec_file_text == template_text
|
|
|
|
|
|
|
|
|
|
os.remove(execute_file_path)
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_exec_parameter_and_a_target_path_to_an_unexisting_file_from_the_existing_directory__the_method_saves_the_exec_file_and_sets_cwd_path_to_a_file_s_directory(self):
|
|
|
|
|
if os.path.exists(EXECUTE_ARCHIVE_PATH):
|
|
|
|
|
shutil.rmtree(EXECUTE_ARCHIVE_PATH)
|
|
|
|
|
template_executor.execute_files = OrderedDict()
|
|
|
|
|
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_template_with_the_exec_parameter_and_a_target_path_to_an_unexisting_file__the_method_throws_TemplateExecutorError_exception(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/exec_parameter_testfiles/file_1')
|
|
|
|
|
interpreter = '/usr/bin/python'
|
|
|
|
|
execute_file_path = os.path.join(EXECUTE_ARCHIVE_PATH, 'exec_0001')
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'exec': '/usr/bin/python'})
|
|
|
|
|
with pytest.raises(TemplateExecutorError):
|
|
|
|
|
template_executor.execute_template(target_path,
|
|
|
|
|
parameters_object,
|
|
|
|
|
FILE,
|
|
|
|
|
'/path/to/template',
|
|
|
|
|
save_changes=False)
|
|
|
|
|
template_text = '''
|
|
|
|
|
import os
|
|
|
|
|
print(os.getcwd())'''
|
|
|
|
|
template_executor.execute_template(target_path,
|
|
|
|
|
parameters_object,
|
|
|
|
|
FILE,
|
|
|
|
|
'/path/to/template',
|
|
|
|
|
template_text=template_text,
|
|
|
|
|
save_changes=False)
|
|
|
|
|
assert os.path.exists(execute_file_path)
|
|
|
|
|
assert template_executor.execute_files[execute_file_path][
|
|
|
|
|
'interpreter'] == interpreter
|
|
|
|
|
assert template_executor.execute_files[execute_file_path][
|
|
|
|
|
'cwd_path'] == os.path.dirname(target_path)
|
|
|
|
|
with open(os.path.join(EXECUTE_ARCHIVE_PATH,
|
|
|
|
|
'exec_0001'), 'r') as exec_file:
|
|
|
|
|
exec_file_text = exec_file.read()
|
|
|
|
|
assert exec_file_text == template_text
|
|
|
|
|
|
|
|
|
|
def test_if_the_execute_template_method_s_input_is_a_several_templates_with_the_exec_parameter_and_a_target_paths_to_an_existing_directories_and_files_and_its_text_is_not_empty__the_method_creates_some_exec_files_and_saves_a_paths_to_exec_files_its_interpreters_and_paths_to_a_directories_from_a_target_path_as_cwd_path(self):
|
|
|
|
|
if os.path.exists(EXECUTE_ARCHIVE_PATH):
|
|
|
|
|
shutil.rmtree(EXECUTE_ARCHIVE_PATH)
|
|
|
|
|
template_executor.execute_files = OrderedDict()
|
|
|
|
|
|
|
|
|
|
interpreter = '/usr/bin/python'
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'exec': '/usr/bin/python'})
|
|
|
|
@ -2705,12 +2821,13 @@ print(os.getcwd())'''
|
|
|
|
|
'/etc/exec_parameter_testfiles/dir_2'),
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/exec_parameter_testfiles/dir_3')]
|
|
|
|
|
template_types = [FILE, DIR, DIR]
|
|
|
|
|
counter = 1
|
|
|
|
|
for target_path in target_paths:
|
|
|
|
|
for target_path, template_type in zip(target_paths, template_types):
|
|
|
|
|
template_text = "print('{}')".format(counter)
|
|
|
|
|
template_executor.execute_template(target_path,
|
|
|
|
|
parameters_object,
|
|
|
|
|
FILE,
|
|
|
|
|
template_type,
|
|
|
|
|
'/path/to/template',
|
|
|
|
|
template_text=template_text,
|
|
|
|
|
save_changes=False)
|
|
|
|
@ -2731,12 +2848,11 @@ print(os.getcwd())'''
|
|
|
|
|
assert exec_file_text == "print('{}')".format(counter)
|
|
|
|
|
counter += 1
|
|
|
|
|
|
|
|
|
|
for exec_path in execute_file_paths:
|
|
|
|
|
os.remove(exec_path)
|
|
|
|
|
|
|
|
|
|
def test_if_some_exec_files_is_saved_and_contains_correct_scripts__the_execute_file_method_can_be_used_for_executing_this_exec_files_and_the_returns_its_stdout_and_stderr(self):
|
|
|
|
|
if os.path.exists(EXECUTE_ARCHIVE_PATH):
|
|
|
|
|
shutil.rmtree(EXECUTE_ARCHIVE_PATH)
|
|
|
|
|
template_executor.execute_files = OrderedDict()
|
|
|
|
|
|
|
|
|
|
def test_if_some_exec_files_is_saved_and_contains_correct_scripts__the_execute_file_method_can_be_used_for_executing_this_exec_files_and_the_returns_its_stdout_and_stderr(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'exec': '/usr/bin/python'})
|
|
|
|
|
target_path = join_paths(
|
|
|
|
@ -2746,7 +2862,7 @@ print(os.getcwd())'''
|
|
|
|
|
template_text = "print('{}')".format(number)
|
|
|
|
|
template_executor.execute_template(target_path,
|
|
|
|
|
parameters_object,
|
|
|
|
|
FILE,
|
|
|
|
|
DIR,
|
|
|
|
|
'/path/to/template',
|
|
|
|
|
template_text=template_text,
|
|
|
|
|
save_changes=False)
|
|
|
|
@ -2756,19 +2872,21 @@ print(os.getcwd())'''
|
|
|
|
|
output = template_executor.execute_file(
|
|
|
|
|
template_executor.execute_files[exec_file_path]['interpreter'],
|
|
|
|
|
exec_file_path,
|
|
|
|
|
template_executor.execute_files[exec_file_path]['cwd_path'] )
|
|
|
|
|
template_executor.execute_files[exec_file_path]['cwd_path'])
|
|
|
|
|
assert output['stdout'].strip() == str(counter)
|
|
|
|
|
assert output['stderr'] is None
|
|
|
|
|
counter += 1
|
|
|
|
|
|
|
|
|
|
def test_if_some_exec_files_is_saved_and_contains_not_correct_scripts__the_execute_file_method_can_be_used_for_executing_this_exec_files_and_returns_its_stderr_and_stdout(self):
|
|
|
|
|
if os.path.exists(EXECUTE_ARCHIVE_PATH):
|
|
|
|
|
shutil.rmtree(EXECUTE_ARCHIVE_PATH)
|
|
|
|
|
template_executor.execute_files = OrderedDict()
|
|
|
|
|
|
|
|
|
|
def test_if_some_exec_files_is_saved_and_contains_not_correct_scripts__the_execute_file_method_can_be_used_for_executing_this_exec_files_and_returns_its_stderr_and_stdout(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'exec': '/usr/bin/python'})
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/run_exec_testfiles/dir_0')
|
|
|
|
|
'/etc/run_exec_testfiles/dir_0/template_name')
|
|
|
|
|
template_text = '''
|
|
|
|
|
import os
|
|
|
|
|
print(os.suspicious_attribute)'''
|
|
|
|
@ -2794,8 +2912,6 @@ AttributeError: module 'os' has no attribute 'suspicious_attribute'
|
|
|
|
|
assert output['stderr'] == stderr_text
|
|
|
|
|
counter += 1
|
|
|
|
|
|
|
|
|
|
template_executor.execute_files = OrderedDict()
|
|
|
|
|
|
|
|
|
|
def test_for_mirror(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
@ -2804,4 +2920,5 @@ AttributeError: module 'os' has no attribute 'suspicious_attribute'
|
|
|
|
|
shutil.rmtree(os.path.join(CHROOT_PATH, 'unprotected'))
|
|
|
|
|
shutil.rmtree(os.path.join(CHROOT_PATH,
|
|
|
|
|
'var/lib/calculate/config-archive'))
|
|
|
|
|
shutil.rmtree(os.path.join(EXECUTE_ARCHIVE_PATH))
|
|
|
|
|
if os.path.exists(EXECUTE_ARCHIVE_PATH):
|
|
|
|
|
shutil.rmtree(os.path.join(EXECUTE_ARCHIVE_PATH))
|
|
|
|
|