You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
calculate-utils-4-lib/tests/templates/test_template_executor.py

1127 lines
66 KiB

import pytest
import os
import stat
import grp
import getpass
import shutil
from calculate.templates.template_processor import TemplateExecutor, DIR,\
FILE, CalculateConfigFile,\
TemplateExecutorError,\
TemplateWrapper,\
TemplateCollisionError
from calculate.templates.template_engine import ParametersContainer
from calculate.utils.package import PackageAtomName, Version
from calculate.utils.files import join_paths
import hashlib
CHROOT_PATH = os.path.join(os.getcwd(),
'tests/templates/testfiles/test_executor_root')
CONFIG_PATH = os.path.join(CHROOT_PATH, 'var/lib/calculate/config')
CONFIG_ARCHIVE_PATH = os.path.join(CHROOT_PATH,
'var/lib/calculate/config-archive')
EXECUTE_ARCHIVE_PATH = os.path.join(CHROOT_PATH,
'var/lib/calculate/.execute')
template_executor = TemplateExecutor(
chroot_path=CHROOT_PATH,
cl_config_archive=CONFIG_ARCHIVE_PATH,
cl_config_path=CONFIG_PATH,
execute_archive_path=EXECUTE_ARCHIVE_PATH)
test_package_name = PackageAtomName(
{'pkg_path': os.path.join(
CHROOT_PATH,
'var/db/pkg/test-category/test-package-1.0'),
'version': Version('1.0')})
other_package_name = PackageAtomName(
{'pkg_path': os.path.join(
CHROOT_PATH,
'var/db/pkg/test-category/other-package-1.1'),
'version': Version('1.1')})
@pytest.mark.template_executor
class TestTemplateExecutor:
def test_function_to_copy_testfiles(self):
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):
temporary_chroot = join_paths(
os.getcwd(),
'tests/templates/testfiles/test_config_root_1')
temporary_config_path = join_paths(temporary_chroot,
'var/lib/calculate/config')
calculate_config_file = CalculateConfigFile(
cl_config_path=temporary_config_path,
cl_chroot_path=temporary_chroot)
assert os.path.exists(calculate_config_file.cl_config_path)
os.remove(calculate_config_file.cl_config_path)
def test_if_config_directory_is_on_the_config_path_instead_of_config_file__a_CalculateConfigFile_object_throws_TemplateExecutorError_exception(self):
temporary_chroot = join_paths(
os.getcwd(),
'tests/templates/testfiles/test_config_root_2')
temporary_config_path = join_paths(temporary_chroot,
'var/lib/calculate/config')
with pytest.raises(TemplateExecutorError):
calculate_config_file = CalculateConfigFile(
cl_config_path=temporary_config_path,
cl_chroot_path=temporary_chroot)
calculate_config_file.save_changes()
def test_if_a_CalculateConfigFile_object_is_initialized__the_object_can_be_used_for_setting_hash_sum_for_the_any_file(self):
calculate_config_file = CalculateConfigFile(
cl_config_path=CONFIG_PATH,
cl_chroot_path=CHROOT_PATH)
md5_value = hashlib.md5(open(join_paths(CHROOT_PATH,
'/etc/file'),
'r').read().encode()).hexdigest()
calculate_config_file.set_files_md5('/etc/file', md5_value)
assert '/etc/file' in calculate_config_file
assert calculate_config_file._config_dictionary['/etc/file'] ==\
md5_value
def test_if_a_CalculateConfigFile_object_is_initialized__the_object_can_be_used_for_removing_any_file_from_config_file(self):
calculate_config_file = CalculateConfigFile(
cl_config_path=CONFIG_PATH,
cl_chroot_path=CHROOT_PATH)
md5_value = hashlib.md5(open(join_paths(CHROOT_PATH,
'/etc/file'),
'r').read().encode()).hexdigest()
calculate_config_file.set_files_md5('/etc/file', md5_value)
assert '/etc/file' in calculate_config_file
calculate_config_file.remove_file('/etc/file')
assert '/etc/file' not in calculate_config_file
def test_if_a_CalculateConfigFile_object_contains_file_with_its_hash_and_the_hash_compared_with_equal_hash__the_compare_md5_method_returns_True(self):
calculate_config_file = CalculateConfigFile(
cl_config_path=CONFIG_PATH,
cl_chroot_path=CHROOT_PATH)
md5_value = hashlib.md5(open(join_paths(CHROOT_PATH,
'/etc/file'),
'r').read().encode()).hexdigest()
calculate_config_file.set_files_md5('/etc/file', md5_value)
assert calculate_config_file.compare_md5('/etc/file', md5_value)
def test_if_a_CalculateConfigFile_object_contains_file_with_its_hash_and_the_hash_compared_with_not_equal_hash__the_compare_md5_method_returns_False(self):
calculate_config_file = CalculateConfigFile(
cl_config_path=CONFIG_PATH,
cl_chroot_path=CHROOT_PATH)
md5_value_1 = hashlib.md5(open(join_paths(CHROOT_PATH,
'/etc/file'),
'r').read().encode()).hexdigest()
calculate_config_file.set_files_md5('/etc/file', md5_value_1)
if os.path.exists(join_paths(CHROOT_PATH,
'/etc/config_testfiles/file.conf')):
print('File exists')
else:
print('File does not exist')
md5_value_2 = hashlib.md5(open(join_paths(
CHROOT_PATH,
'/etc/config_testfiles/file.conf'),
'r').read().encode()).hexdigest()
assert not calculate_config_file.compare_md5('/etc/file', md5_value_2)
def test_if_a_CalculateConfigFile_object_is_used_for_comparing_a_hash_with_a_hash_of_a_file_that_is_not_in_the_config_file__the_compare_md5_method_returns_False(self):
calculate_config_file = CalculateConfigFile(
cl_config_path=CONFIG_PATH,
cl_chroot_path=CHROOT_PATH)
md5_value = hashlib.md5(open(join_paths(CHROOT_PATH,
'/etc/file'),
'r').read().encode()).hexdigest()
assert not calculate_config_file.compare_md5('/etc/file', md5_value)
def test_if_a_CalculateConfigFile_object_was_used_to_make_changes_in_the_config_file__the_save_changes_method_will_save_the_changes(self):
temporary_chroot = join_paths(
os.getcwd(),
'tests/templates/testfiles/test_config_root_1')
temporary_config_path = join_paths(temporary_chroot,
'var/lib/calculate/config')
calculate_config_file = CalculateConfigFile(
cl_config_path=temporary_config_path,
cl_chroot_path=temporary_chroot)
md5_value_1 = hashlib.md5(open(join_paths(temporary_chroot,
'/etc/file'),
'r').read().encode()).hexdigest()
calculate_config_file.set_files_md5('/etc/file', md5_value_1)
md5_value_2 = hashlib.md5(open(join_paths(temporary_chroot,
'/etc/dir/file.conf'),
'r').read().encode()).hexdigest()
calculate_config_file.set_files_md5('/etc/dir/file.conf', md5_value_2)
calculate_config_file.save_changes()
output_text = '/etc/file {}\n/etc/dir/file.conf {}\n'.format(
md5_value_1,
md5_value_2)
assert open(temporary_config_path, 'r').read() == output_text
os.remove(calculate_config_file.cl_config_path)
# Тестируем исполнительный модуль.
# Тестируем сначала кое-какие вспомогательные методы.
def test_if_a_TemplateExecutor_object_is_initialized__the_object_can_return_the_set_of_the_supported_values_of_the_append_parameter(self):
template_executor = TemplateExecutor(
chroot_path=CHROOT_PATH,
cl_config_archive=CONFIG_ARCHIVE_PATH,
cl_config_path=CONFIG_PATH,
execute_archive_path=EXECUTE_ARCHIVE_PATH)
assert template_executor.available_appends
assert 'join' in template_executor.available_appends
assert 'skip' in template_executor.available_appends
assert 'remove' in template_executor.available_appends
def test_if_the_translate_uid_gid_method_s_input_is_uid_and_gid_of_an_existing_user__the_method_returns_user_s_name_and_usser_s_groupname(self):
if os.getuid() == 0 and "SUDO_COMMAND" in os.environ:
chown_value = {'uid': int(os.environ.get('SUDO_UID', 0)),
'gid': int(os.environ.get('SUDO_GID', 0))}
user_name = os.environ.get('SUDO_USER', 0)
group_name = grp.getgrgid(
int(os.environ.get('SUDO_GID', 0))).gr_name
else:
chown_value = {'uid': os.getuid(),
'gid': os.getgid()}
user_name = getpass.getuser()
group_name = grp.getgrgid(int(os.getgid())).gr_name
username_and_group = template_executor._translate_uid_gid(
chown_value['uid'],
chown_value['gid'])
assert username_and_group == "{}:{}".format(user_name, group_name)
# Тестируем методы для работы непосредственно с файловой системой.
# Тестируем методы для изменения владельца файла.
def test_if_the_chown_directory_method_input_is_path_to_the_existing_directory_and_correct_chown_value__the_chown_directory_method_succesfully_changes_directory_owner(self):
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
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):
template_executor._chown_directory(join_paths(
CHROOT_PATH,
'/etc/chown_testfiles/dir_1'),
chown_value)
def test_if_the_chown_directory_method_input_is_a_path_to_the_directory_with_a_fat_filesystem_and_a_correct_chown_value__TemplateExecutor_object_throws_exception(self):
# Для тестирования нужно примонтировать файловую систему с fat32.
pass
def test_if_the_chown_file_method_input_is_a_path_to_an_existing_file_and_the_correct_chown_value__the_chown_file_method_succesfully_changes_file_owner(self):
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
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):
template_executor._chown_file(join_paths(
CHROOT_PATH,
'/etc/chown_testfiles/file_1'),
chown_value)
def test_if_the_chown_file_method_input_is_a_path_to_the_file_from_the_fat_filesystem_and_a_correct_chown_value__TemplateExecutor_object_throws_exception(self):
# Для тестирования нужно примонтировать файловую систему с fat32.
pass
# Тестируем методы для изменения доступа к файлу.
def test_if_the_chmod_directory_method_input_is_path_to_the_existing_directory_and_correct_chmod_value__the_chmod_directory_method_succesfully_changes_directory_mode(self):
chmod_value = int(0o777)
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):
template_executor._chmod_directory(join_paths(
CHROOT_PATH,
'/etc/chmod_testfiles/dir_1'),
chmod_value)
def test_if_the_chmod_directory_method_input_is_a_path_to_the_directory_with_a_fat_filesystem_and_a_correct_chmod_value__TemplateExecutor_object_throws_exception(self):
# Для тестирования нужно примонтировать файловую систему с fat32.
pass
def test_if_the_chmod_file_method_input_is_a_path_to_an_existing_file_and_the_correct_chmod_value__the_chmod_file_method_succesfully_changes_file_owner(self):
chmod_value = int(0o666)
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):
template_executor._chmod_directory(join_paths(
CHROOT_PATH,
'/etc/chmod_testfiles/file_1'),
chmod_value)
def test_if_the_chmod_file_method_input_is_a_path_to_the_file_with_a_fat_filesystem_and_a_correct_chmod_value__TemplateExecutor_object_throws_exception(self):
# Для тестирования нужно примонтировать файловую систему с fat32.
pass
# Тестируем методы для получения информации о владельце файла.
def test_if_the_get_file_owner_method_is_called_with_a_path_to_a_directory_that_exists__the_method_returns_a_dictionary_with_its_owner_s_and_group_s_id(self):
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
template_executor._chown_directory(join_paths(
CHROOT_PATH,
'/etc/chown_testfiles/dir_2'),
chown_value)
owner = template_executor._get_file_owner(join_paths(
CHROOT_PATH,
'/etc/chown_testfiles/dir_2'))
assert owner == 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(
CHROOT_PATH,
'/etc/chown_testfiles/dir_1'))
def test_if_the_get_file_owner_method_is_called_with_a_path_to_a_file_that_exists__the_method_returns_a_dictionary_with_its_owner_s_and_group_s_id(self):
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
template_executor._chown_directory(join_paths(
CHROOT_PATH,
'/etc/chown_testfiles/file_2'),
chown_value)
owner = template_executor._get_file_owner(join_paths(
CHROOT_PATH,
'/etc/chown_testfiles/file_2'))
assert owner == 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(
CHROOT_PATH,
'/etc/chown_testfiles/file_1'))
# Тестируем методы для получения информации о доступе к файлу.
def test_if_the_get_file_mode_method_is_called_with_a_path_to_a_directory_that_exists__the_method_returns_its_mode_value(self):
chmod_value = int(0o777)
template_executor._chmod_directory(join_paths(
CHROOT_PATH,
'/etc/chmod_testfiles/dir_2'),
chmod_value)
mode = template_executor._get_file_mode(join_paths(
CHROOT_PATH,
'/etc/chmod_testfiles/dir_2'))
assert mode == 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(
CHROOT_PATH,
'/etc/chmod_testfiles/dir_1'))
def test_if_the_get_file_mode_method_is_called_with_a_path_to_a_file_that_exists__the_method_returns_its_mode_value(self):
chmod_value = int(0o666)
template_executor._chmod_file(join_paths(
CHROOT_PATH,
'/etc/chmod_testfiles/file_2'),
chmod_value)
mode = template_executor._get_file_mode(
join_paths(
CHROOT_PATH,
'/etc/chmod_testfiles/file_2'))
assert mode == 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(
CHROOT_PATH,
'/etc/chmod_testfiles/file_1'))
# Тесты действий с директориями.
def test_if_the_create_directory_method_input_is_a_template_with_a_target_path_to_an_existing_directory_and_chown_and_chmod_parameters_is_not_set__the_method_does_nothing(self):
target_directory = join_paths(CHROOT_PATH,
'/etc/create_dir_testfiles/dir_0')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join'})
template_wrapper = TemplateWrapper(
target_directory,
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)
assert dir_owner == template_executor._get_file_owner(target_directory)
assert dir_mode == template_executor._get_file_mode(target_directory)
def test_if_the_create_directory_method_input_is_a_template_with_a_target_path_to_an_existing_directory_and_chown_and_chmod_parameters_is_set__the_method_does_nothing(self):
target_directory = join_paths(CHROOT_PATH,
'/etc/create_dir_testfiles/dir_0')
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
chmod_value = int(0o777)
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'chown': chown_value,
'chmod': chmod_value})
template_wrapper = TemplateWrapper(
target_directory,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._create_directory(template_wrapper)
assert chown_value == template_executor._get_file_owner(
target_directory)
assert chmod_value == template_executor._get_file_mode(
target_directory)
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')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join'})
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
chmod_value = int(0o777)
template_executor._chown_directory(os.path.dirname(target_directory),
chown_value)
template_executor._chmod_directory(os.path.dirname(target_directory),
chmod_value)
template_wrapper = TemplateWrapper(
target_directory,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._create_directory(template_wrapper)
assert os.path.exists(target_directory)
assert template_executor._get_file_mode(target_directory) ==\
chmod_value
assert template_executor._get_file_owner(target_directory) ==\
chown_value
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')
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
chmod_value = int(0o777)
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'chown': chown_value,
'chmod': chmod_value})
template_wrapper = TemplateWrapper(
target_directory,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._create_directory(template_wrapper)
assert os.path.exists(target_directory)
assert template_executor._get_file_mode(target_directory) ==\
chmod_value
assert template_executor._get_file_owner(target_directory) ==\
chown_value
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,
'/etc/create_dir_testfiles/dir_2/subdir/subsubdir')
parent_directory = join_paths(CHROOT_PATH,
'/etc/create_dir_testfiles/dir_2')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join'})
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
chmod_value = int(0o777)
template_executor._chown_directory(parent_directory, chown_value)
template_executor._chmod_directory(parent_directory, chmod_value)
template_wrapper = TemplateWrapper(
target_directory,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._create_directory(template_wrapper)
assert os.path.exists(target_directory)
assert template_executor._get_file_mode(target_directory) ==\
chmod_value
assert template_executor._get_file_owner(target_directory) ==\
chown_value
assert template_executor._get_file_mode(
os.path.dirname(target_directory)) == chmod_value
assert template_executor._get_file_owner(
os.path.dirname(target_directory)) == chown_value
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,
'/etc/create_dir_testfiles/dir_2/subdir/subsubdir')
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
chmod_value = int(0o777)
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'chown': chown_value,
'chmod': chmod_value})
template_wrapper = TemplateWrapper(
target_directory,
parameters_object, DIR,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._create_directory(template_wrapper)
assert os.path.exists(target_directory)
assert template_executor._get_file_mode(target_directory) ==\
chmod_value
assert template_executor._get_file_owner(target_directory) ==\
chown_value
assert template_executor._get_file_mode(
os.path.dirname(target_directory)) == chmod_value
assert template_executor._get_file_owner(
os.path.dirname(target_directory)) == chown_value
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')
source_path = join_paths(CHROOT_PATH, '/etc/link_dir_testfiles/dir_0')
template_executor._link_directory(source_path, target_path)
assert os.path.exists(target_path)
assert os.path.islink(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')
source_path = join_paths(CHROOT_PATH, '/etc/link_dir_testfiles/file_1')
template_executor._link_directory(source_path, target_path)
assert os.path.exists(target_path)
assert os.path.islink(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')
source_path = join_paths(CHROOT_PATH, '/etc/link_dir_testfiles/dir_2')
with pytest.raises(TemplateExecutorError):
template_executor._link_directory(source_path, target_path)
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')
template_executor._remove_directory(target_path)
assert not 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')
template_executor._remove_directory(target_path)
assert not os.path.exists(target_path)
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')
template_executor._remove_directory(target_path)
assert not os.path.exists(target_path)
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')
source_path = join_paths(CHROOT_PATH,
'/etc/remove_dir_testfiles/dir_1')
template_executor._remove_directory(target_path)
assert not os.path.exists(target_path)
assert os.path.exists(source_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')
with pytest.raises(TemplateExecutorError):
template_executor._remove_directory(target_path)
def test_if_the_remove_directory_method_s_input_is_a_path_to_a_file__the_method_throws_TemplateExecutorError_exception(self):
target_path = join_paths(CHROOT_PATH,
'/etc/remove_dir_testfiles/file_0')
with pytest.raises(TemplateExecutorError):
template_executor._remove_directory(target_path)
def test_if_the_clear_directory_method_s_input_is_a_path_to_an_existing_empty_directory__the_method_does_nothing(self):
target_path = join_paths(CHROOT_PATH,
'/etc/clear_dir_testfiles/dir_0')
template_executor._clear_directory(target_path)
assert not os.listdir(target_path)
def test_if_the_clear_directory_method_s_input_is_a_path_to_an_existing_directory_that_contains_some_files__the_method_clears_the_target_directory(self):
target_path = join_paths(CHROOT_PATH,
'/etc/clear_dir_testfiles/dir_1')
template_executor._clear_directory(target_path)
assert not os.listdir(target_path)
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')
template_executor._clear_directory(target_path)
assert not os.listdir(target_path)
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')
template_executor._clear_directory(target_path)
assert not os.listdir(target_path)
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')
with pytest.raises(TemplateExecutorError):
template_executor._clear_directory(target_path)
def test_if_the_clear_directory_method_s_input_is_a_path_to_a_file__the_method_raises_TemplateExecutorError_exception(self):
target_path = join_paths(CHROOT_PATH,
'/etc/clear_dir_testfiles/file')
with pytest.raises(TemplateExecutorError):
template_executor._clear_directory(target_path)
def test_if_the_link_file_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_file_testfiles/link_file_0')
source_path = join_paths(CHROOT_PATH,
'/etc/link_file_testfiles/file_0')
template_executor._link_file(source_path, target_path)
assert os.path.exists(target_path)
assert os.path.islink(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')
source_path = join_paths(CHROOT_PATH,
'/etc/link_file_testfiles/file_1')
with pytest.raises(TemplateExecutorError):
template_executor._link_file(source_path, target_path)
def test_if_the_remove_file_method_s_input_is_a_path_to_an_existing_file__the_method_raises_TemplateExecutorError_exception(self):
target_path = join_paths(CHROOT_PATH,
'/etc/remove_file_testfiles/file_0')
template_executor._remove_file(target_path)
assert not 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')
source_path = join_paths(CHROOT_PATH,
'/etc/remove_file_testfiles/file_1')
template_executor._remove_file(target_path)
assert not os.path.exists(target_path)
assert os.path.exists(source_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')
with pytest.raises(TemplateExecutorError):
template_executor._remove_file(target_path)
def test_if_the_remove_file_method_s_input_is_a_path_to_an_existing_directory__the_method_raises_TemplateExecutorError_exception(self):
target_path = join_paths(CHROOT_PATH,
'/etc/remove_file_testfiles/dir_0')
with pytest.raises(TemplateExecutorError):
template_executor._remove_file(target_path)
def test_if_clear_file_method_s_input_is_a_path_to_an_existing_empty_file__the_method_does_nothing(self):
target_path = join_paths(CHROOT_PATH,
'/etc/clear_file_testfiles/file_0')
template_executor._clear_file(target_path)
with open(target_path, 'r') as target_file:
text = target_file.read()
assert not text
def test_if_clear_file_method_s_input_is_a_path_to_an_existing_file_with_any_content__the_method_does_nothing(self):
target_path = join_paths(CHROOT_PATH,
'/etc/clear_file_testfiles/file_1')
template_executor._clear_file(target_path)
with open(target_path, 'r') as target_file:
text = target_file.read()
assert not text
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')
with pytest.raises(TemplateExecutorError):
template_executor._clear_file(target_path)
def test_if_clear_file_method_s_input_is_a_path_to_an_existing_directory__the_method_raises_TemplateExecutorError_exception(self):
target_path = join_paths(CHROOT_PATH,
'/etc/clear_file_testfiles/dir_0')
with pytest.raises(TemplateExecutorError):
template_executor._clear_file(target_path)
# Тестируем поведение исполнительного модуля при различных значениях
# параметра append.
def 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(self):
target_path = join_paths(CHROOT_PATH,
'/etc/append_join_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)
try:
template_executor._append_join_directory(template_wrapper)
except Exception as error:
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
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')
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)
try:
template_executor._append_join_directory(template_wrapper)
except Exception as error:
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
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')
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_join_directory(template_wrapper)
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': '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_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):
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'))