All methods for append directories are tested and improved.

packages
Иванов Денис 4 years ago
parent ec86ff36fb
commit d655b746c7

@ -122,8 +122,10 @@
"tests/templates/format/test_xml_gconf.py::TestParsingMethods::test_joining_documents_1": true,
"tests/templates/format/test_xml_xfce.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true,
"tests/templates/format/test_xml_xfce.py::TestParsingMethods::test_joining_documents_1": true,
"tests/templates/test_directory_processor.py": true,
"tests/templates/test_directory_processor.py::TestDirectoryProcessor::test_just_for_debug_with_package_value": true,
"tests/templates/test_directory_processor.py::TestDirectoryProcessor::test_just_for_debug_without_package_value": true,
"tests/templates/test_parameters_processor.py": true,
"tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_bla_bla": true,
"tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_initialized_accoding_to_dictionary_of_correct_template_parameters__the_TemplateParameters_object_contains_processed_parameters_as_its_attributes_including_default_values": true,
"tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_initialized_using_": true,
@ -144,6 +146,7 @@
"tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_source_parameter_with_unexisting_file_path__the_initialization_of_the_object_will_be_failed": true,
"tests/templates/test_template_action.py": true,
"tests/templates/test_template_action.py::TestTemplateAction::test_create_directory": true,
"tests/templates/test_template_engine.py": true,
"tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_binded_with_datavars_module__variables_available_in_a_template": true,
"tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_calculate_tag_contains_pkg_function_with_an_existing_package_in_its_argument__the_pkg_function_returns_version_value_of_the_package_from_package_parameter_without_any_exceptions": true,
"tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_calculate_tag_with_some_parameters__the_template_engine_object_will_collect_its_parameters": true,
@ -157,12 +160,17 @@
"tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_several_conditions_and_it_is_False__the_template_engine_raises_ConditionFailed_exception": true,
"tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_variables_in_its_text__the_rendered_text_will_contain_values_of_this_variables": true,
"tests/templates/test_template_engine.py::TestTemplateEngine::test_if_value_of_variable_is_set_using_save_tag__the_new_value_of_variable_can_be_used_in_template": true,
"tests/templates/test_template_executor.py": true,
"tests/templates/test_template_executor.py::TestTemplateAction": true,
"tests/templates/test_template_executor.py::TestTemplateAction::test_if_chown_value_is_not_correct__a_TemplateExecutor_object_throws_TemplateExecutorError_exception": true,
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_for_the_testfiles_backup": true,
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_clear_directory_method_s_input_is_a_template_with_a_target_path_to_an_unexisting_directory_that_does_not_belong_to_the_template_package__the_method_just_removes_the_directory_and_all_its_files_from_a_package_CONTENTS_file": true,
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_directory_belongs_to_the_template_package__the_method_throws_TemplateCollisionError_error": true,
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_replace_directory_method_s_input_is_a_template_with_a_target_path_to_an_unexisting_directory_and_the_chown_and_the_chmod_parameters_are_set__the_method_creates_new_directory_and_add_it_to_a_package_CONTENTS_file": true,
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_link_directory_method_s_input_is_a_path_to_an_unexisting_source_directory_and_a_target_path__the_method_does_nothing": true,
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_link_directory_method_s_input_is_a_path_to_an_unexisting_source_directory_and_a_target_path__the_method_raises_the_TemplateExecutorError_exception": true,
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_to_add_link": true,
"tests/templates/test_template_wrapper.py": true,
"tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_TemplateWrapper_object_contains_package_value__the_wrapper_can_use_Package_object_for_changing_CONTENTS_file_of_the_package": true,
"tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_TemplateWrapper_object_successfully_initialized__the_object_can_be_used_for_a_removing_current_file_from_its_package": true,
"tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_TemplateWrapper_object_successfully_initialized__the_object_can_be_used_for_an_adding_any_files_to_its_package_and_hash_will_be_calculated_automatically": true,

@ -99,6 +99,20 @@
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_remove_directory_method_s_input_is_a_template_with_a_target_path_to_an_unexisting_directory_that_belongs_to_the_template_package__the_method_removes_a_target_directory_in_a_package_CONTENTS_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_remove_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_directory_that_does_not_belong_to_any_package__the_method_removes_a_target_directory_in_a_package_CONTENTS_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_clear_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_empty_directory_that_belongs_to_the_template_package__the_method_just_removes_all_its_files_from_a_package_CONTENTS_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_clear_directory_method_s_input_is_a_template_with_a_target_path_to_an_unexisting_directory_that_belongs_to_the_template_package__the_method_just_removes_the_directory_and_all_its_files_from_a_package_CONTENTS_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_clear_directory_method_s_input_is_a_template_with_a_target_path_to_an_unexisting_directory_that_does_not_belong_to_the_template_package__the_method_does_nothing",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_clear_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_directory_with_some_files_that_belongs_to_the_template_package__the_method_clears_directory_and_removes_all_its_files_from_a_package_CONTENTS_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_clear_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_directory_with_some_directories_with_files_that_belongs_to_the_template_package__the_method_clears_directory_and_removes_all_its_files_from_a_package_CONTENTS_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_clear_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_directory_that_belongs_to_the_template_package_and_chmod_and_chown_parameters_are_set__the_method_clears_directory_removes_all_its_files_from_a_package_CONTENTS_file_and_chmod_and_chown_one",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_replace_directory_method_s_input_is_a_template_with_a_target_path_to_an_unexisting_directory__the_method_creates_new_directory_and_add_it_to_a_package_CONTENTS_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_replace_directory_method_s_input_is_a_template_with_a_target_path_to_an_unexisting_directory_and_the_chown_and_the_chmod_parameters_are_set__the_method_creates_new_directory_adds_it_to_a_package_CONTENTS_file_and_chown_and_chmod_directory",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_add_to_contents",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_replace_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_empty_directory_that_belongs_to_the_template_package__the_method_does_nothing",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_replace_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_empty_directory_that_belongs_to_the_template_package_and_the_chown_and_chmod_parameters_are_set__the_method_just_chown_and_chmod_a_target_directory",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_replace_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_directory_with_some_files_that_belongs_to_the_template_package__the_method_clears_directory_and_removes_all_its_files_from_a_package_CONTENTS_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_replace_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_directory_with_some_directories_with_files_that_belongs_to_the_template_package__the_method_clears_directory_and_removes_all_its_files_from_a_package_CONTENTS_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_append_link_directory_method_s_input_is_a_template_with_a_target_path_and_a_source_path_to_the_existing_directory__the_method_creates_a_link_to_the_source_directory",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_append_link_directory_method_s_input_is_a_template_with_a_target_path_and_a_source_path_to_the_existing_directory_and_the_chown_and_chmod_parameters_are_set__the_method_creates_a_link_to_the_source_directory",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_to_remove_changed_testfiles",
"tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_the_TemplateWrapper_object_has_already_been_created__it_contains_the_correct_list_of_protected_and_unprotected_paths",
"tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_template_type_is_FILE_and_target_file_does_not_exist__the_TemplateWrapper_target_type_is_None",

@ -239,7 +239,7 @@ class TemplateWrapper:
chroot_path=self.chroot_path)
return
self.check_conflicts()
self.check_type_conflicts()
self.check_package_collision()
@ -255,7 +255,7 @@ class TemplateWrapper:
self.check_user_changes()
def check_conflicts(self):
def check_type_conflicts(self):
'''Проверка конфликтов типов.'''
if self.parameters.append == 'link':
if self.parameters.force:
@ -274,7 +274,7 @@ class TemplateWrapper:
elif self.target_type == DIR:
raise TemplateTypeConflict("the target is a directory while "
"the template has append = 'link'")
else:
elif self.target_type == FILE:
raise TemplateTypeConflict("the target is a file while the"
" template has append = 'link'")
@ -479,6 +479,9 @@ class TemplateWrapper:
def remove_from_contents(self):
'''Метод для удаления целевого файла из CONTENTS.'''
if self.target_package is None:
return
if self.template_type == DIR:
self.target_package.remove_dir(self.target_path)
elif self.template_type == FILE:
@ -487,11 +490,14 @@ class TemplateWrapper:
def clear_dir_contents(self):
'''Метод для удаления из CONTENTS всего содержимого директории после
применения append = "clear".'''
if self.template_type == DIR:
if self.template_type == DIR and self.target_package is not None:
self.target_package.clear_dir(self.target_path)
def add_to_contents(self, file_md5=None):
'''Метод для добавления целевого файла в CONTENTS.'''
if self.target_package is None:
return
if self.parameters.append == 'link':
self.target_package.add_sym(self.target_path,
self.parameters.source)
@ -502,6 +508,9 @@ class TemplateWrapper:
def update_contents_from_list(self, changed_list: dict):
'''Метод для изменения CONTENTS по списку измененных файлов.'''
if self.target_package is None:
return
for file_path, mode in changed_list.items():
if mode == "modify":
if os.path.islink(file_path):
@ -734,7 +743,7 @@ class TemplateExecutor:
template_object.parameters.chmod)
if template_object.parameters.chown:
self._chmod_directory(template_object.parameters.source,
self._chown_directory(template_object.parameters.source,
template_object.parameters.chown)
template_object.add_to_contents()
@ -1032,10 +1041,8 @@ class TemplateExecutor:
if os.path.isdir(target_path):
try:
if os.path.islink(target_path):
print('is link')
os.unlink(target_path)
else:
print('is not link')
shutil.rmtree(target_path)
return
except Exception as error:
@ -1089,20 +1096,23 @@ class TemplateExecutor:
if os.path.islink(target_path):
try:
os.unlink(target_path)
return
except OSError as error:
raise TemplateExecutorError(
'failed to delete the link: {}, reason: {}'.
format(target_path, str(error)))
if os.path.isfile(target_path):
try:
os.remove(target_path)
except OSError as error:
raise TemplateExecutorError(
'failed to delete the file: {}, reason: {}'.
format(target_path, str(error)))
return
error_message = str(error)
try:
os.remove(target_path)
return
except OSError as error:
error_message = str(error)
else:
error_message = 'target is not a file'
elif os.path.islink(target_path):
try:
os.unlink(target_path)
return
except OSError as error:
error_message = str(error)
else:
error_message = 'target file does not exist'

@ -46,13 +46,9 @@ other_package_name = PackageAtomName(
@pytest.mark.template_executor
class TestTemplateExecutor:
def test_function_to_copy_testfiles(self):
try:
shutil.copytree(os.path.join(CHROOT_PATH, 'etc.backup'),
os.path.join(CHROOT_PATH, 'etc'),
ignore_dangling_symlinks=True)
except Exception as error:
# pytest.fail(str(error))
pass
shutil.copytree(os.path.join(CHROOT_PATH, 'etc.backup'),
os.path.join(CHROOT_PATH, 'etc'),
symlinks=True)
# Сначала протестируем класс для работы с /var/lib/calculate/config файлом.
def test_if_config_file_does_not_exist__a_CalculateConfigFile_object_will_create_one_while_its_initialization(self):
@ -837,7 +833,7 @@ class TestTemplateExecutor:
CHROOT_PATH,
'/etc/append_clear_dir_testfiles/dir_0')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join'})
'append': 'clear'})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, DIR,
@ -845,11 +841,286 @@ class TestTemplateExecutor:
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_clear_directory(template_wrapper)
assert not os.listdir(target_path)
assert os.path.join(target_path, 'file')\
assert '/etc/append_clear_dir_testfiles/dir_0/file'\
not in template_wrapper.target_package
def test_if_append_clear_directory_method_s_input_is_a_template_with_a_target_path_to_an_unexisting_directory_that_belongs_to_the_template_package__the_method_just_removes_the_directory_and_all_its_files_from_a_package_CONTENTS_file(self):
target_path = join_paths(CHROOT_PATH,
'/etc/append_clear_dir_testfiles/dir_1')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'clear'})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_clear_directory(template_wrapper)
# Метод выполняется при сохранении файла CONTENTS,
# здесь вызывем напрямую.
template_wrapper.target_package.remove_empty_directories()
assert '/etc/append_clear_dir_testfiles/dir_1'\
not in template_wrapper.target_package
def test_if_append_clear_directory_method_s_input_is_a_template_with_a_target_path_to_an_unexisting_directory_that_does_not_belong_to_the_template_package__the_method_does_nothing(self):
target_path = join_paths(CHROOT_PATH,
'/etc/append_clear_dir_testfiles/dir_2')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'clear'})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_clear_directory(template_wrapper)
assert not os.path.exists(target_path)
def test_if_append_clear_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_directory_with_some_files_that_belongs_to_the_template_package__the_method_clears_directory_and_removes_all_its_files_from_a_package_CONTENTS_file(self):
pass
target_path = join_paths(CHROOT_PATH,
'/etc/append_clear_dir_testfiles/dir_3')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'clear'})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_clear_directory(template_wrapper)
assert not os.listdir(target_path)
assert '/etc/append_clear_dir_testfiles/dir_3/file_0'\
not in template_wrapper.target_package
assert '/etc/append_clear_dir_testfiles/dir_3/file_1'\
not in template_wrapper.target_package
assert '/etc/append_clear_dir_testfiles/dir_3/link'\
not in template_wrapper.target_package
def test_if_append_clear_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_directory_with_some_directories_with_files_that_belongs_to_the_template_package__the_method_clears_directory_and_removes_all_its_files_from_a_package_CONTENTS_file(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/append_clear_dir_testfiles/dir_4')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'clear'})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_clear_directory(template_wrapper)
assert not os.listdir(target_path)
assert '/etc/append_clear_dir_testfiles/dir_4/subdir_0/file'\
not in template_wrapper.target_package
assert '/etc/append_clear_dir_testfiles/dir_4/subdir_0'\
not in template_wrapper.target_package
assert '/etc/append_clear_dir_testfiles/dir_4/subdir_1/file'\
not in template_wrapper.target_package
assert '/etc/append_clear_dir_testfiles/dir_4/subdir_1'\
not in template_wrapper.target_package
assert '/etc/append_clear_dir_testfiles/dir_4/link'\
not in template_wrapper.target_package
def test_if_append_clear_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_directory_that_belongs_to_the_template_package_and_chmod_and_chown_parameters_are_set__the_method_clears_directory_removes_all_its_files_from_a_package_CONTENTS_file_and_chmod_and_chown_one(self):
target_path = join_paths(CHROOT_PATH,
'/etc/append_clear_dir_testfiles/dir_5')
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
chmod_value = int(0o777)
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'clear',
'chown': chown_value,
'chmod': chmod_value})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_clear_directory(template_wrapper)
assert not os.listdir(target_path)
assert template_executor._get_file_owner(target_path) == chown_value
assert template_executor._get_file_mode(target_path) == chmod_value
def test_if_append_replace_directory_method_s_input_is_a_template_with_a_target_path_to_an_unexisting_directory__the_method_creates_new_directory_and_add_it_to_a_package_CONTENTS_file(self):
target_path = join_paths(CHROOT_PATH,
'/etc/append_replace_dir_testfiles/dir_0')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'replace'})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_replace_directory(template_wrapper)
assert os.path.exists(target_path)
assert '/etc/append_replace_dir_testfiles/dir_0'\
in template_wrapper.target_package
def test_if_append_replace_directory_method_s_input_is_a_template_with_a_target_path_to_an_unexisting_directory_and_the_chown_and_the_chmod_parameters_are_set__the_method_creates_new_directory_adds_it_to_a_package_CONTENTS_file_and_chown_and_chmod_directory(self):
target_path = join_paths(CHROOT_PATH,
'/etc/append_replace_dir_testfiles/dir_1')
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
chmod_value = int(0o777)
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'replace',
'chown': chown_value,
'chmod': chmod_value})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_replace_directory(template_wrapper)
assert os.path.exists(target_path)
assert '/etc/append_replace_dir_testfiles/dir_1'\
in template_wrapper.target_package
assert template_executor._get_file_owner(target_path) == chown_value
assert template_executor._get_file_mode(target_path) == chmod_value
def test_add_to_contents(self):
if False:
target_path = join_paths(
CHROOT_PATH,
'/etc/append_replace_dir_testfiles/dir_5')
parameters_object = ParametersContainer(
{'package': test_package_name,
'append': 'replace'})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_wrapper.target_package.add_sym('/etc/append_replace_dir_testfiles/dir_5/link')
template_wrapper.save_changes()
assert True
def test_if_append_replace_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_empty_directory_that_belongs_to_the_template_package__the_method_does_nothing(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/append_replace_dir_testfiles/dir_2')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'replace'})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_clear_directory(template_wrapper)
assert not os.listdir(target_path)
assert '/etc/append_replace_dir_testfiles/dir_2/file'\
not in template_wrapper.target_package
def test_if_append_replace_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_empty_directory_that_belongs_to_the_template_package_and_the_chown_and_chmod_parameters_are_set__the_method_just_chown_and_chmod_a_target_directory(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/append_replace_dir_testfiles/dir_3')
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
chmod_value = int(0o777)
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'replace',
'chown': chown_value,
'chmod': chmod_value})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_clear_directory(template_wrapper)
assert not os.listdir(target_path)
assert '/etc/append_replace_dir_testfiles/dir_3/file'\
not in template_wrapper.target_package
assert template_executor._get_file_owner(target_path) == chown_value
assert template_executor._get_file_mode(target_path) == chmod_value
def test_if_append_replace_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_directory_with_some_files_that_belongs_to_the_template_package__the_method_clears_directory_and_removes_all_its_files_from_a_package_CONTENTS_file(self):
target_path = join_paths(CHROOT_PATH,
'/etc/append_replace_dir_testfiles/dir_4')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'replace'})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_replace_directory(template_wrapper)
assert not os.listdir(target_path)
assert '/etc/append_replace_dir_testfiles/dir_4/file_0'\
not in template_wrapper.target_package
assert '/etc/append_replace_dir_testfiles/dir_4/file_1'\
not in template_wrapper.target_package
assert '/etc/append_replace_dir_testfiles/dir_4/link'\
not in template_wrapper.target_package
def test_if_append_replace_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_directory_with_some_directories_with_files_that_belongs_to_the_template_package__the_method_clears_directory_and_removes_all_its_files_from_a_package_CONTENTS_file(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/append_replace_dir_testfiles/dir_5')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'replace'})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_replace_directory(template_wrapper)
assert not os.listdir(target_path)
assert '/etc/append_replace_dir_testfiles/dir_5/subdir_0/file'\
not in template_wrapper.target_package
assert '/etc/append_replace_dir_testfiles/dir_5/subdir_0'\
not in template_wrapper.target_package
assert '/etc/append_replace_dir_testfiles/dir_5/subdir_1/file'\
not in template_wrapper.target_package
assert '/etc/append_replace_dir_testfiles/dir_5/subdir_1'\
not in template_wrapper.target_package
assert '/etc/append_replace_dir_testfiles/dir_5/link'\
not in template_wrapper.target_package
def test_append_link_directory_method_s_input_is_a_template_with_a_target_path_and_a_source_path_to_the_existing_directory__the_method_creates_a_link_to_the_source_directory(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/append_link_dir_testfiles/link_dir_0')
source_path = join_paths(
CHROOT_PATH,
'/etc/append_link_dir_testfiles/dir_0')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'link',
'source': source_path})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_link_directory(template_wrapper)
assert os.path.exists(target_path)
assert os.path.islink(target_path)
assert os.readlink(target_path) == source_path
def test_append_link_directory_method_s_input_is_a_template_with_a_target_path_and_a_source_path_to_the_existing_directory_and_the_chown_and_chmod_parameters_are_set__the_method_creates_a_link_to_the_source_directory(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/append_link_dir_testfiles/link_dir_1')
source_path = join_paths(
CHROOT_PATH,
'/etc/append_link_dir_testfiles/dir_1')
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
chmod_value = int(0o777)
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'link',
'source': source_path,
'chown': chown_value,
'chmod': chmod_value})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_link_directory(template_wrapper)
assert os.path.exists(target_path)
assert os.path.islink(target_path)
assert os.readlink(target_path) == source_path
assert template_executor._get_file_owner(target_path) == chown_value
assert template_executor._get_file_mode(target_path) == chmod_value
def test_to_remove_changed_testfiles(self):
shutil.rmtree(os.path.join(CHROOT_PATH, 'etc'))

@ -1 +1 @@
/home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_executor_root/etc/remove_dir_testfiles/dir_1
dir_1

@ -0,0 +1,5 @@
[section one]
parameter_1 = value
parameter_2 = value_2
[section two]
other_parameter = other_value

@ -0,0 +1,3 @@
# Source file
[section_name]
rare_parameter = eternal_value

@ -0,0 +1,66 @@
root::0:root
bin::1:root,bin,daemon
daemon::2:root,bin,daemon
sys::3:root,bin,adm
adm::4:root,adm,daemon
tty::5:
disk::6:root,adm,haldaemon
lp::7:lp,guest
mem::8:
kmem::9:
wheel::10:root,guest
floppy::11:root,haldaemon
mail::12:mail
news::13:news
uucp::14:uucp,guest
man::15:man
console::17:
audio::18:guest
cdrom::19:haldaemon,guest
dialout::20:root
tape::26:root
video::27:root,guest
cdrw::80:haldaemon,guest
usb::85:haldaemon,guest
users::100:games,guest
nofiles:x:200:
smmsp:x:209:smmsp
portage::250:portage
utmp:x:406:
nogroup::65533:
nobody::65534:
sshd:x:22:
games:x:35:guest
plugdev:x:440:haldaemon,usbmux,guest
scanner:x:441:guest
ldap:x:439:
messagebus:x:199:
lpadmin:x:106:
polkituser:x:105:
cron:x:16:
ntp:x:123:
rpc:x:111:
fingerprint:x:104:
ssmtp:x:103:
crontab:x:102:
gdm:x:101:
haldaemon:x:999:haldaemon
openvpn:x:998:
vnstat:x:997:
dnsmasq:x:996:
polkitd:x:995:
locate:x:994:
input:x:993:
dhcp:x:992:
mysql:x:60:
netdev:x:991:
avahi:x:990:
avahi-autoipd:x:989:
nm-openvpn:x:988:
deluge:x:987:
postgres:x:70:
nullmail:x:88:
sudo:x:443:
kvm:x:78:
render:x:28:
guest:!:1000:

@ -0,0 +1,42 @@
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/bin/false
daemon:x:2:2:daemon:/sbin:/bin/false
adm:x:3:4:adm:/var/adm:/bin/false
lp:x:4:7:lp:/var/spool/lpd:/bin/false
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:Mail program user:/var/spool/mail:/sbin/nologin
news:x:9:13:news:/usr/lib/news:/bin/false
uucp:x:10:14:uucp:/var/spool/uucppublic:/bin/false
operator:x:11:0:operator:/root:/bin/bash
man:x:13:15:man:/usr/share/man:/bin/false
postmaster:x:14:12:Postmaster user:/var/spool/mail:/sbin/nologin
portage:x:250:250:portage:/var/tmp/portage:/bin/false
nobody:x:65534:65534:nobody:/:/bin/false
sshd:x:22:22:added by portage for openssh:/var/empty:/sbin/nologin
ldap:x:439:439:added by portage for openldap:/usr/lib64/openldap:/sbin/nologin
messagebus:x:101:199:System user; messagebus:/dev/null:/sbin/nologin
polkituser:x:102:105:added by portage for polkit:/dev/null:/sbin/nologin
cron:x:16:16:added by portage for cronbase:/var/spool/cron:/sbin/nologin
ntp:x:123:123:added by portage for ntp:/dev/null:/sbin/nologin
rpc:x:111:111:added by portage for portmap:/dev/null:/sbin/nologin
gdm:x:103:101:added by portage for gdm:/var/lib/gdm:/sbin/nologin
haldaemon:x:104:999:added by portage for hal:/dev/null:/sbin/nologin
openvpn:x:105:998:added by portage for openvpn:/dev/null:/sbin/nologin
usbmux:x:106:85:added by portage for usbmuxd:/dev/null:/sbin/nologin
vnstat:x:107:997:added by portage for vnstat:/dev/null:/sbin/nologin
dnsmasq:x:108:996:added by portage for dnsmasq:/dev/null:/sbin/nologin
polkitd:x:109:995:added by portage for polkit:/var/lib/polkit-1:/sbin/nologin
saned:x:110:441:added by portage for sane-backends:/dev/null:/sbin/nologin
dhcp:x:112:992:added by portage for dhcp:/var/lib/dhcp:/sbin/nologin
mysql:x:60:60:added by portage for mysql:/dev/null:/sbin/nologin
avahi:x:113:990:added by portage for avahi:/dev/null:/sbin/nologin
avahi-autoipd:x:114:989:added by portage for avahi:/dev/null:/sbin/nologin
nm-openvpn:x:115:988:added by portage for networkmanager-openvpn:/dev/null:/sbin/nologin
games:x:36:35:added by portage for games-envd:/usr/games:/bin/bash
deluge:x:116:987:added by portage for deluge:/var/lib/deluge:/sbin/nologin
postgres:x:70:70:added by portage for postgresql:/var/lib/postgresql:/bin/sh
nullmail:x:88:88:added by portage for nullmailer:/var/nullmailer:/sbin/nologin
divanov:x:1427:1000::/home/divanov:/bin/bash
guest:x:1000:1000::/home/guest:/bin/bash

@ -0,0 +1 @@
/home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_executor_root/etc/remove_file_testfiles/file_1

@ -0,0 +1,7 @@
{
"Band": "Summoning",
"Song": "Flight of the Nazgul",
"Genre": "Black metal",
"Status": "Damn good song",
"isRecommended": true
}

@ -10,10 +10,37 @@ obj /etc/append_join_dir_testfiles/dir_2/file d41d8cd98f00b204e9800998ecf8427e 1
dir /etc/append_remove_dir_testfiles
dir /etc/append_remove_dir_testfiles/dir_0
obj /etc/append_remove_dir_testfiles/dir_0/file d41d8cd98f00b204e9800998ecf8427e 1592386780
dir /etc.backup
dir /etc.backup/append_remove_dir_testfiles
dir /etc.backup/append_remove_dir_testfiles/dir_1
obj /etc.backup/append_remove_dir_testfiles/dir_1/file bd98ac718c432c5139edca29680e74b2 1592399926
dir /etc.backup/append_clear_dir_testfiles
dir /etc.backup/append_clear_dir_testfiles/dir_0
obj /etc.backup/append_clear_dir_testfiles/dir_0/file d41d8cd98f00b204e9800998ecf8427e 1592401655
dir /etc/append_remove_dir_testfiles/dir_1
obj /etc/append_remove_dir_testfiles/dir_1/file bd98ac718c432c5139edca29680e74b2 1592399926
dir /etc/append_clear_dir_testfiles
dir /etc/append_clear_dir_testfiles/dir_0
obj /etc/append_clear_dir_testfiles/dir_0/file d41d8cd98f00b204e9800998ecf8427e 1592401655
dir /etc/append_clear_dir_testfiles/dir_1
obj /etc/append_clear_dir_testfiles/dir_1/file d41d8cd98f00b204e9800998ecf8427e 1592470497
dir /etc/append_clear_dir_testfiles/dir_3
obj /etc/append_clear_dir_testfiles/dir_3/file_0 d41d8cd98f00b204e9800998ecf8427e 1592469560
obj /etc/append_clear_dir_testfiles/dir_3/file_1 d41d8cd98f00b204e9800998ecf8427e 1592469567
sym /etc/append_clear_dir_testfiles/dir_3/link -> file_1 1592484760
dir /etc/append_clear_dir_testfiles/dir_4
dir /etc/append_clear_dir_testfiles/dir_4/subdir_0
obj /etc/append_clear_dir_testfiles/dir_4/subdir_0/file d41d8cd98f00b204e9800998ecf8427e 1592474045
sym /etc/append_clear_dir_testfiles/dir_4/link -> subdir_0 1592485229
dir /etc/append_clear_dir_testfiles/dir_4/subdir_1
obj /etc/append_clear_dir_testfiles/dir_4/subdir_1/file d41d8cd98f00b204e9800998ecf8427e 1592474061
dir /etc/append_clear_dir_testfiles/dir_5
obj /etc/append_clear_dir_testfiles/dir_5/file d41d8cd98f00b204e9800998ecf8427e 1592475693
dir /etc/append_replace_dir_testfiles
dir /etc/append_replace_dir_testfiles/dir_2
obj /etc/append_replace_dir_testfiles/dir_2/file 18e9f3c2096519a5c4c1f661011b1132 1592488196
dir /etc/append_replace_dir_testfiles/dir_3
obj /etc/append_replace_dir_testfiles/dir_3/file d41d8cd98f00b204e9800998ecf8427e 1592491327
dir /etc/append_replace_dir_testfiles/dir_4
obj /etc/append_replace_dir_testfiles/dir_4/file_0 d41d8cd98f00b204e9800998ecf8427e 1592490043
obj /etc/append_replace_dir_testfiles/dir_4/file_1 d41d8cd98f00b204e9800998ecf8427e 1592490043
sym /etc/append_replace_dir_testfiles/dir_4/link -> file_1 1592491608
dir /etc/append_replace_dir_testfiles/dir_5
dir /etc/append_replace_dir_testfiles/dir_5/subdir_0
obj /etc/append_replace_dir_testfiles/dir_5/subdir_0/file d41d8cd98f00b204e9800998ecf8427e 1592490152
dir /etc/append_replace_dir_testfiles/dir_5/subdir_1
obj /etc/append_replace_dir_testfiles/dir_5/subdir_1/file d41d8cd98f00b204e9800998ecf8427e 1592490152
sym /etc/append_replace_dir_testfiles/dir_5/link -> subdir_0 1592491781

Loading…
Cancel
Save