|
|
|
@ -2,13 +2,16 @@ import pytest
|
|
|
|
|
import os
|
|
|
|
|
from calculate.templates.template_engine import ParametersContainer
|
|
|
|
|
from calculate.templates.template_processor import TemplateWrapper, FILE, DIR,\
|
|
|
|
|
TemplateTypeConflict
|
|
|
|
|
TemplateTypeConflict,\
|
|
|
|
|
TemplateCollisionError
|
|
|
|
|
from calculate.utils.package import PackageAtomName, Version
|
|
|
|
|
from calculate.utils.files import join_paths
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CHROOT_PATH = os.path.join(os.getcwd(), 'tests/templates/testfiles/test_root')
|
|
|
|
|
TemplateWrapper.chroot_path = CHROOT_PATH
|
|
|
|
|
CHROOT_PATH = os.path.join(os.getcwd(),
|
|
|
|
|
'tests/templates/testfiles/test_wrapper_root')
|
|
|
|
|
CONFIG_ARCHIVE_PATH = os.path.join(CHROOT_PATH,
|
|
|
|
|
'/var/lib/calculate/config-archive')
|
|
|
|
|
|
|
|
|
|
test_package_name = PackageAtomName(
|
|
|
|
|
{'pkg_path': os.path.join(
|
|
|
|
@ -23,9 +26,12 @@ class TestTemplateWrapper:
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join',
|
|
|
|
|
'format': 'samba'})
|
|
|
|
|
template_wrapper = TemplateWrapper(join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/file.conf'),
|
|
|
|
|
parameters_object, FILE)
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/file.conf'),
|
|
|
|
|
parameters_object, FILE,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
|
|
|
|
|
assert template_wrapper._protected_is_set
|
|
|
|
|
assert (join_paths(CHROOT_PATH, '/etc') in
|
|
|
|
@ -39,14 +45,479 @@ class TestTemplateWrapper:
|
|
|
|
|
mask_set.add(join_paths(CHROOT_PATH, path))
|
|
|
|
|
assert template_wrapper._unprotected_set == mask_set
|
|
|
|
|
|
|
|
|
|
# Тестируем проверку типов шаблонов и файлов и поиск конфликтов.
|
|
|
|
|
# Тесты типов.
|
|
|
|
|
def test_if_template_type_is_FILE_and_target_file_does_not_exist__the_TemplateWrapper_target_type_is_None(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join',
|
|
|
|
|
'format': 'samba'})
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/none'),
|
|
|
|
|
parameters_object, FILE,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
assert template_wrapper.target_type is None
|
|
|
|
|
assert template_wrapper.target_path == join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/none')
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_DIR_and_target_file_is_DIR__the_TemplateWrapper_target_type_is_DIR(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join'})
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/dir_2'),
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
assert template_wrapper.target_type == DIR
|
|
|
|
|
assert template_wrapper.target_path == join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/dir_2')
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_FILE_and_target_file_is_FILE__the_TemplateWrapper_target_type_is_FILE(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join',
|
|
|
|
|
'format': 'samba'})
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/file.conf'),
|
|
|
|
|
parameters_object, FILE,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
assert template_wrapper.target_type == FILE
|
|
|
|
|
assert template_wrapper.target_path == join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/file.conf')
|
|
|
|
|
|
|
|
|
|
# Тесты проверки конфликтов.
|
|
|
|
|
# Если шаблон -- файл.
|
|
|
|
|
def test_if_template_type_is_FILE_and_target_file_is_FILE_and_force_parameter_is_set__the_TemplateWrapper_target_type_is_FILE_and_target_path_is_same(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join',
|
|
|
|
|
'format': 'samba',
|
|
|
|
|
'force': True})
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/file.conf'),
|
|
|
|
|
parameters_object, FILE,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
assert template_wrapper.target_type == FILE
|
|
|
|
|
assert template_wrapper.target_path == join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/file.conf')
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_FILE_but_target_file_is_DIR_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join',
|
|
|
|
|
'format': 'samba'})
|
|
|
|
|
with pytest.raises(TemplateTypeConflict):
|
|
|
|
|
template_wrapper = TemplateWrapper(join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/dir_2'),
|
|
|
|
|
parameters_object, FILE)
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/dir_2'),
|
|
|
|
|
parameters_object, FILE,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_FILE_but_target_file_is_a_link_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join',
|
|
|
|
|
'format': 'samba'})
|
|
|
|
|
with pytest.raises(TemplateTypeConflict):
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/file_link'),
|
|
|
|
|
parameters_object, FILE,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_FILE_but_target_file_is_DIR_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join',
|
|
|
|
|
'format': 'samba',
|
|
|
|
|
'force': True})
|
|
|
|
|
try:
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/dir_2'),
|
|
|
|
|
parameters_object, FILE,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
pytest.fail("Unexpected exception: {}".format(str(error)))
|
|
|
|
|
|
|
|
|
|
assert template_wrapper.remove_original
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_FILE_but_target_file_is_a_link_to_a_DIR_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join',
|
|
|
|
|
'format': 'samba',
|
|
|
|
|
'force': True})
|
|
|
|
|
try:
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir_link'),
|
|
|
|
|
parameters_object, FILE,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
pytest.fail("Unexpected exception: {}".format(str(error)))
|
|
|
|
|
|
|
|
|
|
assert template_wrapper.remove_original
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_FILE_but_target_file_is_a_link_to_a_FILE_and_force_parameter_is_set__the_TemplateWrapper_changes_its_target_path_to_the_link_source_file(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join',
|
|
|
|
|
'format': 'samba',
|
|
|
|
|
'force': True})
|
|
|
|
|
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/file_link'),
|
|
|
|
|
parameters_object, FILE,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
assert template_wrapper.target_path_is_changed
|
|
|
|
|
assert template_wrapper.target_path == join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/file')
|
|
|
|
|
|
|
|
|
|
# Если шаблон -- директория.
|
|
|
|
|
def test_if_template_type_is_DIR_and_target_file_is_DIR_and_force_parameter_is_set__the_TemplateWrapper_target_type_is_DIR_and_target_path_is_the_same(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join',
|
|
|
|
|
'force': True})
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/dir_2'),
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
assert template_wrapper.target_type == DIR
|
|
|
|
|
assert template_wrapper.target_path == join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/dir_2')
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_DIR_and_target_file_is_a_link_to_a_DIR_and_force_parameter_is_not_set__the_TemplateWrapper_changes_its_target_path_to_the_link_source_file(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join'})
|
|
|
|
|
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir_link'),
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
assert template_wrapper.target_path_is_changed
|
|
|
|
|
assert template_wrapper.target_path == join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/dir_2')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_DIR_but_target_file_is_FILE_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join',
|
|
|
|
|
'format': 'samba'})
|
|
|
|
|
with pytest.raises(TemplateTypeConflict):
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/file.conf'),
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_DIR_and_target_file_is_a_link_to_a_file_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join',
|
|
|
|
|
'format': 'samba'})
|
|
|
|
|
with pytest.raises(TemplateTypeConflict):
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/file_link'),
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_DIR_and_target_file_is_FILE_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join',
|
|
|
|
|
'force': True})
|
|
|
|
|
try:
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/file.conf'),
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
pytest.fail("Unexpected exception: {}".format(str(error)))
|
|
|
|
|
|
|
|
|
|
assert template_wrapper.remove_original
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_DIR_and_target_file_is_the_link_to_a_FILE_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join',
|
|
|
|
|
'force': True})
|
|
|
|
|
try:
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/file_link'),
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
pytest.fail("Unexpected exception: {}".format(str(error)))
|
|
|
|
|
|
|
|
|
|
def test(self):
|
|
|
|
|
assert template_wrapper.remove_original
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_DIR_and_target_file_is_the_link_to_a_DIR_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join',
|
|
|
|
|
'force': True})
|
|
|
|
|
try:
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir_link'),
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
pytest.fail("Unexpected exception: {}".format(str(error)))
|
|
|
|
|
|
|
|
|
|
assert template_wrapper.remove_original
|
|
|
|
|
|
|
|
|
|
# Если шаблон создает ссылку.
|
|
|
|
|
def test_if_template_type_is_FILE_with_the_append_link_parameter_and_target_file_is_the_link_to_a_FILE__the_TemplateWrapper_sets_remove_original_flag(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'link'})
|
|
|
|
|
try:
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/file_link'),
|
|
|
|
|
parameters_object, FILE,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
pytest.fail("Unexpected exception: {}".format(str(error)))
|
|
|
|
|
|
|
|
|
|
assert template_wrapper.remove_original
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_FILE_with_the_append_link_parameter_and_target_file_is_the_link_to_a_DIR__the_TemplateWrapper_sets_remove_original_flag(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'link'})
|
|
|
|
|
try:
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir_link'),
|
|
|
|
|
parameters_object, FILE,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
pytest.fail("Unexpected exception: {}".format(str(error)))
|
|
|
|
|
|
|
|
|
|
assert template_wrapper.remove_original
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_DIR_with_the_append_link_parameter_and_target_file_is_the_link_to_a_FILE__the_TemplateWrapper_sets_remove_original_flag(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'link'})
|
|
|
|
|
try:
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/file_link'),
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
pytest.fail("Unexpected exception: {}".format(str(error)))
|
|
|
|
|
|
|
|
|
|
assert template_wrapper.remove_original
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_DIR_with_the_append_link_parameter_and_target_file_is_the_link_to_a_DIR__the_TemplateWrapper_sets_remove_original_flag(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'link'})
|
|
|
|
|
try:
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir_link'),
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
pytest.fail("Unexpected exception: {}".format(str(error)))
|
|
|
|
|
|
|
|
|
|
assert template_wrapper.remove_original
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_FILE_with_the_append_link_parameter_and_target_file_is_FILE_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'link'})
|
|
|
|
|
with pytest.raises(TemplateTypeConflict):
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/file.conf'),
|
|
|
|
|
parameters_object, FILE,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_FILE_with_the_append_link_parameter_and_target_file_is_DIR_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'link'})
|
|
|
|
|
with pytest.raises(TemplateTypeConflict):
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/dir_2'),
|
|
|
|
|
parameters_object, FILE,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_DIR_with_the_append_link_parameter_and_target_file_is_FILE_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'link'})
|
|
|
|
|
with pytest.raises(TemplateTypeConflict):
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/file.conf'),
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_DIR_with_the_append_link_parameter_and_target_file_is_DIR_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'link'})
|
|
|
|
|
with pytest.raises(TemplateTypeConflict):
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/dir_2'),
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_FILE_with_the_append_link_parameter_and_target_file_is_FILE_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'link',
|
|
|
|
|
'force': True})
|
|
|
|
|
try:
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/file.conf'),
|
|
|
|
|
parameters_object, FILE,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
pytest.fail("Unexpected exception: {}".format(str(error)))
|
|
|
|
|
|
|
|
|
|
assert template_wrapper.remove_original
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_FILE_with_the_append_link_parameter_and_target_file_is_DIR_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'link',
|
|
|
|
|
'force': True})
|
|
|
|
|
try:
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/dir_2'),
|
|
|
|
|
parameters_object, FILE,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
pytest.fail("Unexpected exception: {}".format(str(error)))
|
|
|
|
|
|
|
|
|
|
assert template_wrapper.remove_original
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_DIR_with_the_append_link_parameter_and_target_file_is_FILE_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'link',
|
|
|
|
|
'force': True})
|
|
|
|
|
try:
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/file.conf'),
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
pytest.fail("Unexpected exception: {}".format(str(error)))
|
|
|
|
|
|
|
|
|
|
assert template_wrapper.remove_original
|
|
|
|
|
|
|
|
|
|
def test_if_template_type_is_DIR_with_the_append_link_parameter_and_target_file_is_DIR_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'link',
|
|
|
|
|
'force': True})
|
|
|
|
|
try:
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/dir_2'),
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
pytest.fail("Unexpected exception: {}".format(str(error)))
|
|
|
|
|
|
|
|
|
|
assert template_wrapper.remove_original
|
|
|
|
|
|
|
|
|
|
# Тестируем определитель пакетов и проверку на коллизии.
|
|
|
|
|
def test_if_template_contains_append_parameters_but_does_not_have_package_parameter_and_target_file_does_not_belong_to_any_package__the_TemplateWrapper_throws_TemplateCollisionError_exception(self):
|
|
|
|
|
parameters_object = ParametersContainer({'append': 'join'})
|
|
|
|
|
with pytest.raises(TemplateCollisionError):
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/file'),
|
|
|
|
|
parameters_object, FILE,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
|
|
|
|
|
def test_if_template_contains_package_parameter_and_target_file_does_not_belong_to_any_package__the_TemplateWrapper_uses_package_from_parameter_and_sets_target_without_package_flag(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join'})
|
|
|
|
|
try:
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/file'),
|
|
|
|
|
parameters_object, FILE,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
pytest.fail("Unexpected exception: {}".format(str(error)))
|
|
|
|
|
|
|
|
|
|
assert template_wrapper.target_without_package
|
|
|
|
|
|
|
|
|
|
def test_if_template_does_not_have_package_parameter_but_target_file_belongs_to_the_package__the_TemplateWrapper_uses_package_from_parameter(self):
|
|
|
|
|
parameters_object = ParametersContainer({'append': 'join'})
|
|
|
|
|
try:
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/file.conf'),
|
|
|
|
|
parameters_object, FILE,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
pytest.fail("Unexpected exception: {}".format(str(error)))
|
|
|
|
|
|
|
|
|
|
assert not template_wrapper.target_without_package
|
|
|
|
|
assert template_wrapper.target_package_name == test_package_name
|
|
|
|
|
|
|
|
|
|
def test_if_template_contains_package_parameter_and_target_file_belongs_to_the_package_from_package_parameter__the_TemplateWrapper_uses_package_from_them(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join'})
|
|
|
|
|
try:
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir/file.conf'),
|
|
|
|
|
parameters_object, FILE,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
pytest.fail("Unexpected exception: {}".format(str(error)))
|
|
|
|
|
|
|
|
|
|
assert template_wrapper.target_package_name == test_package_name
|
|
|
|
|
|
|
|
|
|
def test_if_template_contains_package_parameter_but_target_file_belongs_to_the_other_package__the_TemplateWrapper_throws_TemplateCollisionError(self):
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join'})
|
|
|
|
|
with pytest.raises(TemplateCollisionError):
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/other_file.conf'),
|
|
|
|
|
parameters_object, FILE,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
|
|
|
|
|
def test_contents_init(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
# Тестируем проверку наличия пользовательских изменений.
|
|
|
|
|