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.
53 lines
2.4 KiB
53 lines
2.4 KiB
import pytest
|
|
import os
|
|
from calculate.templates.template_engine import ParametersContainer
|
|
from calculate.templates.template_processor import TemplateWrapper, FILE, DIR,\
|
|
TemplateTypeConflict
|
|
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
|
|
|
|
test_package_name = PackageAtomName(
|
|
{'pkg_path': os.path.join(
|
|
CHROOT_PATH,
|
|
'var/db/pkg/test-category/test-package-1.0'),
|
|
'version': Version('1.0')})
|
|
|
|
|
|
@pytest.mark.template_wrapper
|
|
class TestTemplateWrapper:
|
|
def test_if_the_TemplateWrapper_object_has_already_been_created__it_contains_the_correct_list_of_protected_and_unprotected_paths(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)
|
|
|
|
assert template_wrapper._protected_is_set
|
|
assert (join_paths(CHROOT_PATH, '/etc') in
|
|
template_wrapper._protected_set)
|
|
|
|
mask_paths = os.environ.get('CONFIG_PROTECT_MASK', False)
|
|
|
|
if mask_paths:
|
|
mask_set = set()
|
|
for path in mask_paths.split():
|
|
mask_set.add(join_paths(CHROOT_PATH, path))
|
|
assert template_wrapper._unprotected_set == mask_set
|
|
|
|
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)
|
|
|
|
def test(self):
|
|
pass
|