Backup testfiles is added. Some of the append parameter methods are tested for directories.

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

@ -159,6 +159,7 @@
"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::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_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_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,

@ -30,6 +30,7 @@
"tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_pkg_function_without_any_arguments_but_with_package_parameter_in_calculate_tag__the_pkg_function_returns_version_value_of_the_package_from_package_parameter",
"tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_pkg_function_without_any_arguments_and_without_package_parameter_in_calculate_tag__the_pkg_function_returns_empty_version_value",
"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",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_function_to_copy_testfiles",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_config_file_does_not_exist__a_CalculateConfigFile_object_will_create_one_while_its_initialization",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_config_directory_is_on_the_config_path_instead_of_config_file__a_CalculateConfigFile_object_throws_TemplateExecutorError_exception",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_a_CalculateConfigFile_object_is_initialized__the_object_can_be_used_for_setting_hash_sum_for_the_any_file",
@ -94,7 +95,11 @@
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_directory_method_s_input_is_a_template_with_a_target_path_to_an_unexisting_directory__the_method_creates_new_directory_and_adds_it_to_a_package_contents_file",
"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_that_does_not_belong_to_any_package__the_method_just_adds_new_directory_to_a_package_contents_file",
"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_does_nothing",
"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",
"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_belongs_to_the_template_package__the_method_removes_a_target_directory_in_a_filesystem_and_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_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_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",
"tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_template_type_is_DIR_and_target_file_is_DIR__the_TemplateWrapper_target_type_is_DIR",

@ -699,7 +699,7 @@ class TemplateExecutor:
if template_object.target_type is not None:
self._remove_directory(template_object.target_path)
template_object.remove_from_contents()
template_object.remove_from_contents()
def _append_skip_directory(self, template_object: TemplateWrapper):
pass
@ -720,7 +720,7 @@ class TemplateExecutor:
self._chown_directory(template_object.target_path,
template_object.parameters.chown)
template_object.clear_dir_contents()
template_object.clear_dir_contents()
def _append_link_directory(self, template_object: TemplateWrapper):
'''Метод описывающий действия для append = "link", если шаблон --
@ -1963,7 +1963,8 @@ class DirectoryProcessor:
self.output.set_warning(
"'package' parameter is not defined.\nTemplate: {}".
format(template_path))
# считаем наличие параметра package необязательным.
# считаем наличие параметра package необязательным на данном
# этапе.
# return False
elif parameters.package != self.for_package:

@ -45,6 +45,15 @@ 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
# Сначала протестируем класс для работы с /var/lib/calculate/config файлом.
def test_if_config_file_does_not_exist__a_CalculateConfigFile_object_will_create_one_while_its_initialization(self):
temporary_chroot = join_paths(
@ -214,21 +223,6 @@ class TestTemplateExecutor:
'/etc/chown_testfiles/dir_0')).\
st_gid == chown_value['gid']
if os.getuid() == 0 and "SSH_connection" not in os.environ:
chown_value = {'uid': int(os.environ['SUDO_UID']),
'gid': int(os.environ['SUDO_GID'])}
template_executor._chown_directory(join_paths(
CHROOT_PATH,
'/etc/chown_testfiles/dir_0'),
chown_value)
assert os.stat(join_paths(CHROOT_PATH,
'/etc/chown_testfiles/dir_0')).\
st_uid == chown_value['uid']
assert os.stat(join_paths(CHROOT_PATH,
'/etc/chown_testfiles/dir_0')).\
st_gid == chown_value['gid']
def test_if_the_chown_directory_method_input_is_path_to_the_unexisting_directory_and_correct_chown_value__the_chown_directory_method_does_nothing(self):
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
with pytest.raises(TemplateExecutorError):
@ -254,21 +248,6 @@ class TestTemplateExecutor:
'/etc/chown_testfiles/file_0')).\
st_gid == chown_value['gid']
if os.getuid() == 0 and "SSH_CONNECTION" not in os.environ:
chown_value = {'uid': int(os.environ['SUDO_UID']),
'gid': int(os.environ['SUDO_GID'])}
template_executor._chown_file(join_paths(
CHROOT_PATH,
'/etc/chown_testfiles/file_0'),
chown_value)
assert os.stat(join_paths(CHROOT_PATH,
'/etc/chown_testfiles/file_0')).\
st_uid == chown_value['uid']
assert os.stat(join_paths(CHROOT_PATH,
'/etc/chown_testfiles/file_0')).\
st_gid == chown_value['gid']
def test_if_the_chown_file_method_input_is_path_to_the_unexisting_file_and_correct_chown_value__the_chown_directory_method_does_nothing(self):
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
with pytest.raises(TemplateExecutorError):
@ -294,17 +273,6 @@ class TestTemplateExecutor:
assert result == chmod_value
chmod_value = int(0o755)
template_executor._chmod_directory(join_paths(
CHROOT_PATH,
'/etc/chmod_testfiles/dir_0'),
chmod_value)
result = stat.S_IMODE(os.stat(join_paths(
CHROOT_PATH,
'/etc/chmod_testfiles/dir_0')).st_mode)
assert result == chmod_value
def test_if_the_chmod_directory_method_input_is_path_to_the_unexisting_directory_and_correct_chmod_value__the_chmod_directory_method_does_nothing(self):
chmod_value = int(0o777)
with pytest.raises(TemplateExecutorError):
@ -329,17 +297,6 @@ class TestTemplateExecutor:
assert result == chmod_value
chmod_value = int(0o644)
template_executor._chmod_file(join_paths(
CHROOT_PATH,
'/etc/chmod_testfiles/file_0'),
chmod_value)
result = stat.S_IMODE(os.stat(join_paths(
CHROOT_PATH,
'/etc/chmod_testfiles/file_0')).st_mode)
assert result == chmod_value
def test_if_the_chmod_file_method_input_is_path_to_the_unexisting_file_and_correct_chmod_value__the_chmod_file_method_does_nothing(self):
chmod_value = int(0o777)
with pytest.raises(TemplateExecutorError):
@ -364,15 +321,6 @@ class TestTemplateExecutor:
'/etc/chown_testfiles/dir_2'))
assert owner == chown_value
if os.getuid() == 0 and "SSH_CONNECTION" not in os.environ:
chown_value = {'uid': int(os.environ['SUDO_UID']),
'gid': int(os.environ['SUDO_GID'])}
template_executor._chown_directory(join_paths(
CHROOT_PATH,
'/etc/chown_testfiles/dir_2'),
chown_value)
def test_if_the_get_file_owner_method_is_called_with_a_path_to_a_directory_that_does_not_exists__the_method_throws_TemplateExecutorError_exception(self):
with pytest.raises(TemplateExecutorError):
template_executor._get_file_owner(join_paths(
@ -390,15 +338,6 @@ class TestTemplateExecutor:
'/etc/chown_testfiles/file_2'))
assert owner == chown_value
if os.getuid() == 0 and "SSH_CONNECTION" not in os.environ:
chown_value = {'uid': int(os.environ['SUDO_UID']),
'gid': int(os.environ['SUDO_GID'])}
template_executor._chown_directory(join_paths(
CHROOT_PATH,
'/etc/chown_testfiles/file_2'),
chown_value)
def test_if_the_get_file_owner_method_is_called_with_a_path_to_a_file_that_does_not_exists__the_method_throws_TemplateExecutorError_exception(self):
with pytest.raises(TemplateExecutorError):
template_executor._get_file_owner(join_paths(
@ -417,12 +356,6 @@ class TestTemplateExecutor:
'/etc/chmod_testfiles/dir_2'))
assert mode == chmod_value
chmod_value = int(0o755)
template_executor._chmod_directory(join_paths(
CHROOT_PATH,
'/etc/chmod_testfiles/dir_2'),
chmod_value)
def test_if_the_get_file_mode_method_is_called_with_a_path_to_a_directory_that_does_not_exists__the_method_throws_TemplateExecutorError_exception(self):
with pytest.raises(TemplateExecutorError):
template_executor._get_file_mode(join_paths(
@ -442,12 +375,6 @@ class TestTemplateExecutor:
assert mode == chmod_value
chmod_value = int(0o644)
template_executor._chmod_file(join_paths(
CHROOT_PATH,
'/etc/chmod_testfiles/file_2'),
chmod_value)
def test_if_the_get_file_mode_method_is_called_with_a_path_to_a_file_that_does_not_exists__the_method_throws_TemplateExecutorError_exception(self):
with pytest.raises(TemplateExecutorError):
template_executor._get_file_mode(join_paths(
@ -487,8 +414,6 @@ class TestTemplateExecutor:
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
dir_owner = template_executor._get_file_owner(target_directory)
dir_mode = template_executor._get_file_mode(target_directory)
template_executor._create_directory(template_wrapper)
@ -497,11 +422,6 @@ class TestTemplateExecutor:
assert chmod_value == template_executor._get_file_mode(
target_directory)
template_executor._chmod_directory(target_directory,
dir_mode)
if os.getuid() == 0 and "SSH_CONNECTION" not in os.environ:
template_executor._chown_directory(target_directory, dir_owner)
def test_if_the_create_directory_method_input_is_a_template_with_a_target_path_to_an_unexisting_directory_from_an_existing_directory_and_chown_and_chmod_parameters_is_not_set__the_method_creates_one_new_directory_with_a_mode_and_an_owner_of_its_parent_directory(self):
target_directory = join_paths(CHROOT_PATH,
'/etc/create_dir_testfiles/dir_1/subdir')
@ -510,11 +430,6 @@ class TestTemplateExecutor:
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
chmod_value = int(0o777)
parent_owner = template_executor._get_file_owner(os.path.dirname(
target_directory))
parent_mode = template_executor._get_file_mode(os.path.dirname(
target_directory))
template_executor._chown_directory(os.path.dirname(target_directory),
chown_value)
template_executor._chmod_directory(os.path.dirname(target_directory),
@ -533,14 +448,6 @@ class TestTemplateExecutor:
assert template_executor._get_file_owner(target_directory) ==\
chown_value
os.rmdir(target_directory)
assert not os.path.exists(target_directory)
template_executor._chown_file(os.path.dirname(target_directory),
parent_owner)
template_executor._chmod_file(os.path.dirname(target_directory),
parent_mode)
def test_if_the_create_directory_method_input_is_a_template_with_a_target_path_to_an_unexisting_directory_from_an_existing_directory_and_chown_and_chmod_parameters_is_set__the_method_one_new_directory_with_a_mode_and_an_owner_from_the_parameters(self):
target_directory = join_paths(CHROOT_PATH,
'/etc/create_dir_testfiles/dir_1/subdir')
@ -563,9 +470,6 @@ class TestTemplateExecutor:
assert template_executor._get_file_owner(target_directory) ==\
chown_value
os.rmdir(target_directory)
assert not os.path.exists(target_directory)
def test_if_the_create_directory_method_input_is_a_template_with_a_target_path_to_an_unexisting_directory_from_an_unexisting_directory_and_chown_and_chmod_parameters_is_not_set__the_method_creates_new_directory_and_all_its_parents_with_a_mode_and_an_owner_of_its_existing_parent(self):
target_directory = join_paths(
CHROOT_PATH,
@ -577,9 +481,6 @@ class TestTemplateExecutor:
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
chmod_value = int(0o777)
parent_owner = template_executor._get_file_owner(parent_directory)
parent_mode = template_executor._get_file_mode(parent_directory)
template_executor._chown_directory(parent_directory, chown_value)
template_executor._chmod_directory(parent_directory, chmod_value)
@ -600,14 +501,6 @@ class TestTemplateExecutor:
assert template_executor._get_file_owner(
os.path.dirname(target_directory)) == chown_value
shutil.rmtree(os.path.dirname(target_directory))
assert not os.path.exists(os.path.dirname(target_directory))
template_executor._chown_file(parent_directory,
parent_owner)
template_executor._chmod_file(parent_directory,
parent_mode)
def test_if_the_create_directory_method_s_input_is_a_template_with_a_target_path_to_an_unexisting_directory_from_an_unexisting_directory_and_chown_and_chmod_parameters_is_set__the_method_creates_new_directory_and_all_its_parents_with_a_mode_and_an_owner_from_the_parameters(self):
target_directory = join_paths(
CHROOT_PATH,
@ -637,9 +530,6 @@ class TestTemplateExecutor:
assert template_executor._get_file_owner(
os.path.dirname(target_directory)) == chown_value
shutil.rmtree(os.path.dirname(target_directory))
assert not os.path.exists(os.path.dirname(target_directory))
def test_if_the_link_directory_method_s_input_is_a_path_to_an_existing_source_directory_and_a_target_path__the_method_creates_a_link_to_a_source_file(self):
target_path = join_paths(CHROOT_PATH,
'/etc/link_dir_testfiles/link_dir_0')
@ -649,10 +539,6 @@ class TestTemplateExecutor:
assert os.path.exists(target_path)
assert os.path.islink(target_path)
os.unlink(target_path)
assert not os.path.exists(target_path)
def test_if_the_link_directory_method_s_input_is_a_path_to_an_existing_source_file_and_a_target_path__the_method_creates_a_link_to_a_source_file(self):
target_path = join_paths(CHROOT_PATH,
'/etc/link_dir_testfiles/link_dir_1')
@ -662,10 +548,6 @@ class TestTemplateExecutor:
assert os.path.exists(target_path)
assert os.path.islink(target_path)
os.unlink(target_path)
assert not os.path.exists(target_path)
def test_if_the_link_directory_method_s_input_is_a_path_to_an_existing_source_directory_and_a_target_path_to_an_existing_link__the_method_raises_the_TemplateExecutorError_exception(self):
target_path = join_paths(CHROOT_PATH,
'/etc/link_dir_testfiles/link_dir_2')
@ -677,83 +559,24 @@ class TestTemplateExecutor:
def test_if_the_remove_directory_method_s_input_is_a_path_to_an_existing_empty_directory__the_method_will_remove_the_directory(self):
target_path = join_paths(CHROOT_PATH,
'/etc/remove_dir_testfiles/dir_0')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join'})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._remove_directory(target_path)
assert not os.path.exists(target_path)
template_executor._create_directory(template_wrapper)
assert os.path.exists(target_path)
def test_if_the_remove_directory_method_s_input_is_a_path_to_an_existing_directory_that_contains_a_some_files__the_method_will_remove_the_directory(self):
target_path = join_paths(CHROOT_PATH,
'/etc/remove_dir_testfiles/dir_2')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join'})
files_owner = template_executor._get_file_owner(
os.path.join(target_path, 'file_1'))
files_mode = template_executor._get_file_mode(
os.path.join(target_path, 'file_1'))
template_wrapper = TemplateWrapper(
target_path,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._remove_directory(target_path)
assert not os.path.exists(target_path)
template_executor._create_directory(template_wrapper)
assert os.path.exists(target_path)
open(os.path.join(target_path, 'file_1'), 'w')
template_executor._chown_file(os.path.join(target_path, 'file_1'),
files_owner)
template_executor._chmod_file(os.path.join(target_path, 'file_1'),
files_mode)
open(os.path.join(target_path, 'file_2'), 'w')
template_executor._chown_file(os.path.join(target_path, 'file_2'),
files_owner)
template_executor._chmod_file(os.path.join(target_path, 'file_2'),
files_mode)
assert os.path.exists(os.path.join(target_path, 'file_1'))
assert os.path.exists(os.path.join(target_path, 'file_2'))
def test_if_the_remove_directory_method_s_input_is_a_path_to_an_existing_directory_that_contains_directories__the_method_will_remove_the_directory(self):
target_path = join_paths(CHROOT_PATH,
'/etc/remove_dir_testfiles/dir_3')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join'})
template_executor._remove_directory(target_path)
assert not os.path.exists(target_path)
template_wrapper = TemplateWrapper(
os.path.join(target_path, 'subdir_1'),
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._create_directory(template_wrapper)
assert os.path.exists(os.path.join(target_path, 'subdir_1'))
template_wrapper = TemplateWrapper(
os.path.join(target_path, 'subdir_2'),
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._create_directory(template_wrapper)
assert os.path.exists(os.path.join(target_path, 'subdir_2'))
def test_if_the_remove_directory_method_s_input_is_a_path_to_an_existing_link_to_a_directory__the_method_will_remove_the_link_but_not_the_link_s_source_directory(self):
target_path = join_paths(CHROOT_PATH,
'/etc/remove_dir_testfiles/link_dir_1')
@ -764,9 +587,6 @@ class TestTemplateExecutor:
assert not os.path.exists(target_path)
assert os.path.exists(source_path)
template_executor._link_directory(source_path, target_path)
assert os.path.exists(target_path)
def test_if_the_remove_directory_method_s_input_is_a_path_to_an_unexisting_directory__the_method_throws_TemplateExecutorError_exception(self):
target_path = join_paths(CHROOT_PATH,
'/etc/remove_dir_testfiles/dir_4')
@ -792,83 +612,23 @@ class TestTemplateExecutor:
target_path = join_paths(CHROOT_PATH,
'/etc/clear_dir_testfiles/dir_1')
files_owner = template_executor._get_file_owner(
os.path.join(target_path, 'file_1'))
files_mode = template_executor._get_file_mode(
os.path.join(target_path, 'file_1'))
template_executor._clear_directory(target_path)
assert not os.listdir(target_path)
open(os.path.join(target_path, 'file_1'), 'w')
template_executor._chown_file(os.path.join(target_path, 'file_1'),
files_owner)
template_executor._chmod_file(os.path.join(target_path, 'file_1'),
files_mode)
open(os.path.join(target_path, 'file_2'), 'w')
template_executor._chown_file(os.path.join(target_path, 'file_2'),
files_owner)
template_executor._chmod_file(os.path.join(target_path, 'file_2'),
files_mode)
assert os.path.exists(os.path.join(target_path, 'file_1'))
assert os.path.exists(os.path.join(target_path, 'file_2'))
def test_if_the_clear_directory_method_s_input_is_a_path_to_an_existing_directory_that_contains_some_directories__the_method_clears_the_target_directory(self):
target_path = join_paths(CHROOT_PATH,
'/etc/clear_dir_testfiles/dir_2')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join'})
template_executor._clear_directory(target_path)
assert not os.listdir(target_path)
template_wrapper = TemplateWrapper(
os.path.join(target_path, 'subdir_1'),
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._create_directory(template_wrapper)
assert os.path.exists(os.path.join(target_path, 'subdir_1'))
template_wrapper = TemplateWrapper(
os.path.join(target_path, 'subdir_2'),
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._create_directory(template_wrapper)
assert os.path.exists(os.path.join(target_path, 'subdir_2'))
def test_if_the_clear_directory_method_s_input_is_a_path_to_an_existing_directory_that_contains_some_directories_and_files__the_method_clears_the_target_directory(self):
target_path = join_paths(CHROOT_PATH,
'/etc/clear_dir_testfiles/dir_3')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join'})
files_owner = template_executor._get_file_owner(
os.path.join(target_path, 'file'))
files_mode = template_executor._get_file_mode(
os.path.join(target_path, 'file'))
template_executor._clear_directory(target_path)
assert not os.listdir(target_path)
template_wrapper = TemplateWrapper(
os.path.join(target_path, 'subdir'),
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._create_directory(template_wrapper)
assert os.path.exists(os.path.join(target_path, 'subdir'))
open(os.path.join(target_path, 'file'), 'w')
template_executor._chown_file(os.path.join(target_path, 'file'),
files_owner)
template_executor._chmod_file(os.path.join(target_path, 'file'),
files_mode)
assert os.path.exists(os.path.join(target_path, 'file'))
def test_if_the_clear_directory_method_s_input_is_a_path_to_an_unexisting_directory__the_method_raises_TemplateExecutorError_exception(self):
target_path = join_paths(CHROOT_PATH,
'/etc/clear_dir_testfiles/dir_4')
@ -893,10 +653,6 @@ class TestTemplateExecutor:
assert os.path.exists(target_path)
assert os.path.islink(target_path)
os.unlink(target_path)
assert not os.path.exists(target_path)
def test_if_the_link_file_method_s_input_is_a_path_to_an_existing_source_file_and_a_target_path_to_an_existing_file__the_method_creates_a_link_to_a_source_file(self):
target_path = join_paths(CHROOT_PATH,
'/etc/link_file_testfiles/link_file_1')
@ -910,18 +666,9 @@ class TestTemplateExecutor:
target_path = join_paths(CHROOT_PATH,
'/etc/remove_file_testfiles/file_0')
files_owner = template_executor._get_file_owner(target_path)
files_mode = template_executor._get_file_mode(target_path)
template_executor._remove_file(target_path)
assert not os.path.exists(target_path)
open(target_path, 'w')
template_executor._chown_file(target_path, files_owner)
template_executor._chmod_file(target_path, files_mode)
assert os.path.exists(target_path)
def test_if_the_remove_file_method_s_input_is_a_path_to_an_existing_link_to_an_existing_file__the_method_raises_TemplateExecutorError_exception(self):
target_path = join_paths(CHROOT_PATH,
'/etc/remove_file_testfiles/link_file_1')
@ -932,10 +679,6 @@ class TestTemplateExecutor:
assert not os.path.exists(target_path)
assert os.path.exists(source_path)
template_executor._link_file(source_path, target_path)
assert os.path.exists(target_path)
def test_if_the_remove_file_method_s_input_is_a_path_to_an_unexisting_file__the_method_raises_TemplateExecutorError_exception(self):
target_path = join_paths(CHROOT_PATH,
'/etc/remove_file_testfiles/file_2')
@ -968,9 +711,6 @@ class TestTemplateExecutor:
text = target_file.read()
assert not text
with open(target_path, 'w') as target_file:
target_file.write('MATURE CONTENT')
def test_if_clear_file_method_s_input_is_a_path_to_an_unexisting_file__the_method_raises_TemplateExecutorError_exception(self):
target_path = join_paths(CHROOT_PATH,
'/etc/clear_file_testfiles/file_2')
@ -1000,21 +740,12 @@ class TestTemplateExecutor:
try:
template_executor._append_join_directory(template_wrapper)
except Exception as error:
if os.path.exists(target_path):
shutil.rmtree(target_path)
template_wrapper.remove_from_contents()
pytest.fail('Exception: {}'.format(str(error)))
assert os.path.exists(target_path)
assert '/etc/append_join_dir_testfiles/dir_0'\
in template_wrapper.target_package
shutil.rmtree(target_path)
template_wrapper.remove_from_contents()
assert not os.path.exists(target_path)
assert '/etc/append_join_dir_testfiles/dir_0'\
not in template_wrapper.target_package
def test_if_append_join_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_directory_that_does_not_belong_to_any_package__the_method_just_adds_new_directory_to_a_package_contents_file(self):
target_path = join_paths(CHROOT_PATH,
'/etc/append_join_dir_testfiles/dir_1')
@ -1028,17 +759,12 @@ class TestTemplateExecutor:
try:
template_executor._append_join_directory(template_wrapper)
except Exception as error:
template_wrapper.remove_from_contents()
pytest.fail('Exception: {}'.format(str(error)))
assert os.path.exists(target_path)
assert '/etc/append_join_dir_testfiles/dir_1'\
in template_wrapper.target_package
template_wrapper.remove_from_contents()
assert '/etc/append_join_dir_testfiles/dir_1'\
not in template_wrapper.target_package
def 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_does_nothing(self):
target_path = join_paths(CHROOT_PATH,
'/etc/append_join_dir_testfiles/dir_2')
@ -1054,3 +780,76 @@ class TestTemplateExecutor:
assert os.path.exists(target_path)
assert '/etc/append_join_dir_testfiles/dir_2'\
in template_wrapper.target_package
def test_if_append_remove_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_directory_that_belongs_to_the_template_package__the_method_removes_a_target_directory_in_a_filesystem_and_in_a_package_CONTENTS_file(self):
target_path = join_paths(CHROOT_PATH,
'/etc/append_remove_dir_testfiles/dir_0')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'remove'})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_remove_directory(template_wrapper)
assert not os.path.exists(target_path)
assert '/etc/append_remove_dir_testfiles/dir_0/file'\
not in template_wrapper.target_package
assert '/etc/append_remove_dir_testfiles/dir_0'\
not in template_wrapper.target_package
def 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(self):
target_path = join_paths(CHROOT_PATH,
'/etc/append_remove_dir_testfiles/dir_1')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'remove'})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_remove_directory(template_wrapper)
assert '/etc/append_remove_dir_testfiles/dir_1/file'\
not in template_wrapper.target_package
assert '/etc/append_remove_dir_testfiles/dir_1'\
not in template_wrapper.target_package
def 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(self):
target_path = join_paths(CHROOT_PATH,
'/etc/append_remove_dir_testfiles/dir_2')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'remove'})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_remove_directory(template_wrapper)
assert not os.path.exists(target_path)
assert '/etc/append_remove_dir_testfiles/dir_2'\
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_empty_directory_that_belongs_to_the_template_package__the_method_just_removes_all_its_files_from_a_package_CONTENTS_file(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/append_clear_dir_testfiles/dir_0')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join'})
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 os.path.join(target_path, '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_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
def test_to_remove_changed_testfiles(self):
shutil.rmtree(os.path.join(CHROOT_PATH, 'etc'))

@ -1,13 +1,4 @@
dir /etc
obj /etc/other_file.conf 61b82a7891c5233b92a5bde68535a71d 1591343936
dir /etc/dir_0
obj /etc/dir_0/file 84bcceb2c8e6de79849ea5f3304f2411 1591343236
dir /etc/dir_1
obj /etc/dir_1/file 84bcceb2c8e6de79849ea5f3304f2411 1591343236
dir /etc/dir_2
obj /etc/dir_2/file 84bcceb2c8e6de79849ea5f3304f2411 1591343236
dir /not_protected
obj /not_protected/file.conf 687594ba5f93d0673abce62d0bd649ec 1591352448
dir /etc/append_join_dir_testfiles
dir /etc/append_join_dir_testfiles/dir_3
obj /etc/append_join_dir_testfiles/dir_3/file d41d8cd98f00b204e9800998ecf8427e 1592319654

@ -7,3 +7,13 @@ obj /etc/terminfo/info.json 7a374d90a202b969ee338ac4334fb14b 1591354184
dir /etc/append_join_dir_testfiles
dir /etc/append_join_dir_testfiles/dir_2
obj /etc/append_join_dir_testfiles/dir_2/file d41d8cd98f00b204e9800998ecf8427e 1592318164
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

Loading…
Cancel
Save