|
|
@ -45,6 +45,15 @@ other_package_name = PackageAtomName(
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.template_executor
|
|
|
|
@pytest.mark.template_executor
|
|
|
|
class TestTemplateExecutor:
|
|
|
|
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 файлом.
|
|
|
|
# Сначала протестируем класс для работы с /var/lib/calculate/config файлом.
|
|
|
|
def test_if_config_file_does_not_exist__a_CalculateConfigFile_object_will_create_one_while_its_initialization(self):
|
|
|
|
def test_if_config_file_does_not_exist__a_CalculateConfigFile_object_will_create_one_while_its_initialization(self):
|
|
|
|
temporary_chroot = join_paths(
|
|
|
|
temporary_chroot = join_paths(
|
|
|
@ -214,21 +223,6 @@ class TestTemplateExecutor:
|
|
|
|
'/etc/chown_testfiles/dir_0')).\
|
|
|
|
'/etc/chown_testfiles/dir_0')).\
|
|
|
|
st_gid == chown_value['gid']
|
|
|
|
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):
|
|
|
|
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()}
|
|
|
|
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
|
|
|
|
with pytest.raises(TemplateExecutorError):
|
|
|
|
with pytest.raises(TemplateExecutorError):
|
|
|
@ -254,21 +248,6 @@ class TestTemplateExecutor:
|
|
|
|
'/etc/chown_testfiles/file_0')).\
|
|
|
|
'/etc/chown_testfiles/file_0')).\
|
|
|
|
st_gid == chown_value['gid']
|
|
|
|
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):
|
|
|
|
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()}
|
|
|
|
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
|
|
|
|
with pytest.raises(TemplateExecutorError):
|
|
|
|
with pytest.raises(TemplateExecutorError):
|
|
|
@ -294,17 +273,6 @@ class TestTemplateExecutor:
|
|
|
|
|
|
|
|
|
|
|
|
assert result == chmod_value
|
|
|
|
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):
|
|
|
|
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)
|
|
|
|
chmod_value = int(0o777)
|
|
|
|
with pytest.raises(TemplateExecutorError):
|
|
|
|
with pytest.raises(TemplateExecutorError):
|
|
|
@ -329,17 +297,6 @@ class TestTemplateExecutor:
|
|
|
|
|
|
|
|
|
|
|
|
assert result == chmod_value
|
|
|
|
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):
|
|
|
|
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)
|
|
|
|
chmod_value = int(0o777)
|
|
|
|
with pytest.raises(TemplateExecutorError):
|
|
|
|
with pytest.raises(TemplateExecutorError):
|
|
|
@ -364,15 +321,6 @@ class TestTemplateExecutor:
|
|
|
|
'/etc/chown_testfiles/dir_2'))
|
|
|
|
'/etc/chown_testfiles/dir_2'))
|
|
|
|
assert owner == chown_value
|
|
|
|
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):
|
|
|
|
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):
|
|
|
|
with pytest.raises(TemplateExecutorError):
|
|
|
|
template_executor._get_file_owner(join_paths(
|
|
|
|
template_executor._get_file_owner(join_paths(
|
|
|
@ -390,15 +338,6 @@ class TestTemplateExecutor:
|
|
|
|
'/etc/chown_testfiles/file_2'))
|
|
|
|
'/etc/chown_testfiles/file_2'))
|
|
|
|
assert owner == chown_value
|
|
|
|
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):
|
|
|
|
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):
|
|
|
|
with pytest.raises(TemplateExecutorError):
|
|
|
|
template_executor._get_file_owner(join_paths(
|
|
|
|
template_executor._get_file_owner(join_paths(
|
|
|
@ -417,12 +356,6 @@ class TestTemplateExecutor:
|
|
|
|
'/etc/chmod_testfiles/dir_2'))
|
|
|
|
'/etc/chmod_testfiles/dir_2'))
|
|
|
|
assert mode == chmod_value
|
|
|
|
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):
|
|
|
|
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):
|
|
|
|
with pytest.raises(TemplateExecutorError):
|
|
|
|
template_executor._get_file_mode(join_paths(
|
|
|
|
template_executor._get_file_mode(join_paths(
|
|
|
@ -442,12 +375,6 @@ class TestTemplateExecutor:
|
|
|
|
|
|
|
|
|
|
|
|
assert mode == chmod_value
|
|
|
|
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):
|
|
|
|
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):
|
|
|
|
with pytest.raises(TemplateExecutorError):
|
|
|
|
template_executor._get_file_mode(join_paths(
|
|
|
|
template_executor._get_file_mode(join_paths(
|
|
|
@ -487,8 +414,6 @@ class TestTemplateExecutor:
|
|
|
|
parameters_object, DIR,
|
|
|
|
parameters_object, DIR,
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_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)
|
|
|
|
template_executor._create_directory(template_wrapper)
|
|
|
|
|
|
|
|
|
|
|
@ -497,11 +422,6 @@ class TestTemplateExecutor:
|
|
|
|
assert chmod_value == template_executor._get_file_mode(
|
|
|
|
assert chmod_value == template_executor._get_file_mode(
|
|
|
|
target_directory)
|
|
|
|
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):
|
|
|
|
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,
|
|
|
|
target_directory = join_paths(CHROOT_PATH,
|
|
|
|
'/etc/create_dir_testfiles/dir_1/subdir')
|
|
|
|
'/etc/create_dir_testfiles/dir_1/subdir')
|
|
|
@ -510,11 +430,6 @@ class TestTemplateExecutor:
|
|
|
|
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
|
|
|
|
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
|
|
|
|
chmod_value = int(0o777)
|
|
|
|
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),
|
|
|
|
template_executor._chown_directory(os.path.dirname(target_directory),
|
|
|
|
chown_value)
|
|
|
|
chown_value)
|
|
|
|
template_executor._chmod_directory(os.path.dirname(target_directory),
|
|
|
|
template_executor._chmod_directory(os.path.dirname(target_directory),
|
|
|
@ -533,14 +448,6 @@ class TestTemplateExecutor:
|
|
|
|
assert template_executor._get_file_owner(target_directory) ==\
|
|
|
|
assert template_executor._get_file_owner(target_directory) ==\
|
|
|
|
chown_value
|
|
|
|
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):
|
|
|
|
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,
|
|
|
|
target_directory = join_paths(CHROOT_PATH,
|
|
|
|
'/etc/create_dir_testfiles/dir_1/subdir')
|
|
|
|
'/etc/create_dir_testfiles/dir_1/subdir')
|
|
|
@ -563,9 +470,6 @@ class TestTemplateExecutor:
|
|
|
|
assert template_executor._get_file_owner(target_directory) ==\
|
|
|
|
assert template_executor._get_file_owner(target_directory) ==\
|
|
|
|
chown_value
|
|
|
|
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):
|
|
|
|
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(
|
|
|
|
target_directory = join_paths(
|
|
|
|
CHROOT_PATH,
|
|
|
|
CHROOT_PATH,
|
|
|
@ -577,9 +481,6 @@ class TestTemplateExecutor:
|
|
|
|
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
|
|
|
|
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
|
|
|
|
chmod_value = int(0o777)
|
|
|
|
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._chown_directory(parent_directory, chown_value)
|
|
|
|
template_executor._chmod_directory(parent_directory, chmod_value)
|
|
|
|
template_executor._chmod_directory(parent_directory, chmod_value)
|
|
|
|
|
|
|
|
|
|
|
@ -600,14 +501,6 @@ class TestTemplateExecutor:
|
|
|
|
assert template_executor._get_file_owner(
|
|
|
|
assert template_executor._get_file_owner(
|
|
|
|
os.path.dirname(target_directory)) == chown_value
|
|
|
|
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):
|
|
|
|
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(
|
|
|
|
target_directory = join_paths(
|
|
|
|
CHROOT_PATH,
|
|
|
|
CHROOT_PATH,
|
|
|
@ -637,9 +530,6 @@ class TestTemplateExecutor:
|
|
|
|
assert template_executor._get_file_owner(
|
|
|
|
assert template_executor._get_file_owner(
|
|
|
|
os.path.dirname(target_directory)) == chown_value
|
|
|
|
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):
|
|
|
|
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,
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
'/etc/link_dir_testfiles/link_dir_0')
|
|
|
|
'/etc/link_dir_testfiles/link_dir_0')
|
|
|
@ -649,10 +539,6 @@ class TestTemplateExecutor:
|
|
|
|
assert os.path.exists(target_path)
|
|
|
|
assert os.path.exists(target_path)
|
|
|
|
assert os.path.islink(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):
|
|
|
|
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,
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
'/etc/link_dir_testfiles/link_dir_1')
|
|
|
|
'/etc/link_dir_testfiles/link_dir_1')
|
|
|
@ -662,10 +548,6 @@ class TestTemplateExecutor:
|
|
|
|
assert os.path.exists(target_path)
|
|
|
|
assert os.path.exists(target_path)
|
|
|
|
assert os.path.islink(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):
|
|
|
|
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,
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
'/etc/link_dir_testfiles/link_dir_2')
|
|
|
|
'/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):
|
|
|
|
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,
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
'/etc/remove_dir_testfiles/dir_0')
|
|
|
|
'/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)
|
|
|
|
template_executor._remove_directory(target_path)
|
|
|
|
assert not os.path.exists(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):
|
|
|
|
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,
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
'/etc/remove_dir_testfiles/dir_2')
|
|
|
|
'/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)
|
|
|
|
template_executor._remove_directory(target_path)
|
|
|
|
assert not os.path.exists(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):
|
|
|
|
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,
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
'/etc/remove_dir_testfiles/dir_3')
|
|
|
|
'/etc/remove_dir_testfiles/dir_3')
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
|
|
|
'append': 'join'})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template_executor._remove_directory(target_path)
|
|
|
|
template_executor._remove_directory(target_path)
|
|
|
|
assert not os.path.exists(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):
|
|
|
|
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,
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
'/etc/remove_dir_testfiles/link_dir_1')
|
|
|
|
'/etc/remove_dir_testfiles/link_dir_1')
|
|
|
@ -764,9 +587,6 @@ class TestTemplateExecutor:
|
|
|
|
assert not os.path.exists(target_path)
|
|
|
|
assert not os.path.exists(target_path)
|
|
|
|
assert os.path.exists(source_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):
|
|
|
|
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,
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
'/etc/remove_dir_testfiles/dir_4')
|
|
|
|
'/etc/remove_dir_testfiles/dir_4')
|
|
|
@ -792,83 +612,23 @@ class TestTemplateExecutor:
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
'/etc/clear_dir_testfiles/dir_1')
|
|
|
|
'/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)
|
|
|
|
template_executor._clear_directory(target_path)
|
|
|
|
assert not os.listdir(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):
|
|
|
|
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,
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
'/etc/clear_dir_testfiles/dir_2')
|
|
|
|
'/etc/clear_dir_testfiles/dir_2')
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
|
|
|
'append': 'join'})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template_executor._clear_directory(target_path)
|
|
|
|
template_executor._clear_directory(target_path)
|
|
|
|
assert not os.listdir(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):
|
|
|
|
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,
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
'/etc/clear_dir_testfiles/dir_3')
|
|
|
|
'/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)
|
|
|
|
template_executor._clear_directory(target_path)
|
|
|
|
assert not os.listdir(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):
|
|
|
|
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,
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
'/etc/clear_dir_testfiles/dir_4')
|
|
|
|
'/etc/clear_dir_testfiles/dir_4')
|
|
|
@ -893,10 +653,6 @@ class TestTemplateExecutor:
|
|
|
|
assert os.path.exists(target_path)
|
|
|
|
assert os.path.exists(target_path)
|
|
|
|
assert os.path.islink(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):
|
|
|
|
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,
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
'/etc/link_file_testfiles/link_file_1')
|
|
|
|
'/etc/link_file_testfiles/link_file_1')
|
|
|
@ -910,18 +666,9 @@ class TestTemplateExecutor:
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
'/etc/remove_file_testfiles/file_0')
|
|
|
|
'/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)
|
|
|
|
template_executor._remove_file(target_path)
|
|
|
|
assert not os.path.exists(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):
|
|
|
|
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,
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
'/etc/remove_file_testfiles/link_file_1')
|
|
|
|
'/etc/remove_file_testfiles/link_file_1')
|
|
|
@ -932,10 +679,6 @@ class TestTemplateExecutor:
|
|
|
|
assert not os.path.exists(target_path)
|
|
|
|
assert not os.path.exists(target_path)
|
|
|
|
assert os.path.exists(source_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):
|
|
|
|
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,
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
'/etc/remove_file_testfiles/file_2')
|
|
|
|
'/etc/remove_file_testfiles/file_2')
|
|
|
@ -968,9 +711,6 @@ class TestTemplateExecutor:
|
|
|
|
text = target_file.read()
|
|
|
|
text = target_file.read()
|
|
|
|
assert not text
|
|
|
|
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):
|
|
|
|
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,
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
'/etc/clear_file_testfiles/file_2')
|
|
|
|
'/etc/clear_file_testfiles/file_2')
|
|
|
@ -1000,21 +740,12 @@ class TestTemplateExecutor:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
template_executor._append_join_directory(template_wrapper)
|
|
|
|
template_executor._append_join_directory(template_wrapper)
|
|
|
|
except Exception as error:
|
|
|
|
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)))
|
|
|
|
pytest.fail('Exception: {}'.format(str(error)))
|
|
|
|
|
|
|
|
|
|
|
|
assert os.path.exists(target_path)
|
|
|
|
assert os.path.exists(target_path)
|
|
|
|
assert '/etc/append_join_dir_testfiles/dir_0'\
|
|
|
|
assert '/etc/append_join_dir_testfiles/dir_0'\
|
|
|
|
in template_wrapper.target_package
|
|
|
|
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):
|
|
|
|
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,
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
'/etc/append_join_dir_testfiles/dir_1')
|
|
|
|
'/etc/append_join_dir_testfiles/dir_1')
|
|
|
@ -1028,17 +759,12 @@ class TestTemplateExecutor:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
template_executor._append_join_directory(template_wrapper)
|
|
|
|
template_executor._append_join_directory(template_wrapper)
|
|
|
|
except Exception as error:
|
|
|
|
except Exception as error:
|
|
|
|
template_wrapper.remove_from_contents()
|
|
|
|
|
|
|
|
pytest.fail('Exception: {}'.format(str(error)))
|
|
|
|
pytest.fail('Exception: {}'.format(str(error)))
|
|
|
|
|
|
|
|
|
|
|
|
assert os.path.exists(target_path)
|
|
|
|
assert os.path.exists(target_path)
|
|
|
|
assert '/etc/append_join_dir_testfiles/dir_1'\
|
|
|
|
assert '/etc/append_join_dir_testfiles/dir_1'\
|
|
|
|
in template_wrapper.target_package
|
|
|
|
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):
|
|
|
|
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,
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
'/etc/append_join_dir_testfiles/dir_2')
|
|
|
|
'/etc/append_join_dir_testfiles/dir_2')
|
|
|
@ -1054,3 +780,76 @@ class TestTemplateExecutor:
|
|
|
|
assert os.path.exists(target_path)
|
|
|
|
assert os.path.exists(target_path)
|
|
|
|
assert '/etc/append_join_dir_testfiles/dir_2'\
|
|
|
|
assert '/etc/append_join_dir_testfiles/dir_2'\
|
|
|
|
in template_wrapper.target_package
|
|
|
|
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'))
|
|
|
|