The creation of the ._cfg-files is almost tested.

packages
Иванов Денис 4 years ago
parent f64fd98e38
commit 8344028930

@ -162,6 +162,7 @@
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_for_the_testfiles_backup": true,
"tests/templates/test_template_executor.py::TestTemplateExecutor::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_just_removes_the_directory_and_all_its_files_from_a_package_CONTENTS_file": true,
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_directory_belongs_to_the_template_package__the_method_throws_TemplateCollisionError_error": true,
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file_and_the_chown_and_chmod_parameters_is_set__the_method_creates_a_cfg_file_and_adds_a_target_file_s_path_to_the_config_file": true,
"tests/templates/test_template_executor.py::TestTemplateExecutor::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_and_add_it_to_a_package_CONTENTS_file": true,
"tests/templates/test_template_executor.py::TestTemplateExecutor::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": true,
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_link_directory_method_s_input_is_a_path_to_an_unexisting_source_directory_and_a_target_path__the_method_does_nothing": true,

@ -120,6 +120,15 @@
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_and_its_hash_sum_matches_the_hash_from_a_CONTENTS_file__the_method_joins_an_input_file_with_a_template__changes_its_hash_in_the_CONTENTS__updates_config_archive",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_its_hash_sum_matches_the_hash_from_a_CONTENTS_file_and_a_chown_and_chmod_parameters_are_set__the_method_joins_an_input_file_with_a_template__changes_its_hash_in_the_CONTENTS__updates_config_archive_and_chown_and_chmod_it",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file__the_method_creates_a_cfg_file_and_adds_a_target_file_s_path_to_the_config_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file_and_the_chown_and_chmod_parameters_is_set__the_method_creates_a_cfg_file_and_adds_a_target_file_s_path_to_the_config_file_and_chown_and_chmod_it",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file_and_the_autoupdate_parameter_is_set__the_method_joins_a_target_file_and_a_template__removes_a_path_to_file_from_the_config_file_and_updates_a_package_CONTENTS_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file_and_there_is_some_cfg_files_and_the_autoupdate_parameter_is_set__the_method_joins_a_target_file_and_a_template__removes_a_path_to_file_from_the_config_file__removes_all_cfg_files_and_updates_a_package_CONTENTS_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file_and_there_is_two_cfg_files__the_method_creates_third_cfg_file_and_updates_config_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file_and_there_is_two_cfg_files_and_changes_from_a_template_is_similar_to_the_last_one__the_method_does_nothing",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_unprotected_for_file_without_changes",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_unprotected_for_file_with_changes",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_unbound_for_file_without_changes",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_unbound_for_file_with_changes",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_to_remove_changed_testfiles",
"tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_the_TemplateWrapper_object_has_already_been_created__it_contains_the_correct_list_of_protected_and_unprotected_paths",
"tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_template_type_is_FILE_and_target_file_does_not_exist__the_TemplateWrapper_target_type_is_None",

@ -244,16 +244,6 @@ class TemplateWrapper:
self.check_package_collision()
# Если целью является файл -- проверяем наличие ._cfg0000_filename
# файлов.
if self.target_type is FILE:
self._cfg_pattern = os.path.join(
os.path.dirname(self.target_path),
"._cfg????_{}".format(
os.path.basename(self.target_path)))
self.cfg_list = glob.glob(self._cfg_pattern)
self.check_user_changes()
def check_type_conflicts(self):
@ -397,6 +387,7 @@ class TemplateWrapper:
"._cfg????_{}".format(
os.path.basename(self.target_path)))
self.cfg_list = glob.glob(cfg_pattern)
self.cfg_list.sort()
# Путь к архивной версии файла.
self.archive_path = self._get_archive_path(self.target_path)
@ -439,6 +430,8 @@ class TemplateWrapper:
# Приоритет отдаем пути из параметра source.
if self.parameters.source:
self.input_path = self.parameters.source
elif self.cfg_list:
self.input_path = self.archive_path
else:
self.input_path = self.target_path
@ -884,6 +877,7 @@ class TemplateExecutor:
if not self.calculate_config_file.compare_md5(
template_object.target_path,
output_text_md5):
print('compare_md5 == False')
if not os.path.exists(os.path.dirname(output_path)):
self._create_directory(
template_object,
@ -904,6 +898,7 @@ class TemplateExecutor:
output_text_md5)
else:
# Действия если CL совпало. Пока ничего не делаем.
print('compare_md5 == True')
pass
# Обновляем CONTENTS.

@ -1377,12 +1377,201 @@ class TestTemplateExecutor:
assert os.path.exists(target_path)
assert os.path.exists(output_path)
assert os.path.exists(join_paths(
CONFIG_ARCHIVE_PATH,
'/etc/append_join_file_testfiles/file_7'))
assert '/etc/append_join_file_testfiles/file_7'\
in template_executor.calculate_config_file
with open(template_wrapper.output_path, 'r') as output_file:
assert output_file.read() == output_text
def test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file_and_the_chown_and_chmod_parameters_is_set__the_method_creates_a_cfg_file_and_adds_a_target_file_s_path_to_the_config_file_and_chown_and_chmod_it(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/append_join_file_testfiles/file_8')
output_path = os.path.join(os.path.dirname(target_path),
'._cfg0001_file_8')
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
chmod_value = int(0o777)
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'bind',
'chown': chown_value,
'chmod': chmod_value})
template_text = 'section-name { parameter-2 no; }'
output_text =\
'section-name {\n parameter-1 yes;\n parameter-2 no;\n};\n'
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
template_text=template_text,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_join_file(template_wrapper)
assert os.path.exists(target_path)
assert os.path.exists(output_path)
assert template_executor._get_file_owner(output_path) == chown_value
assert template_executor._get_file_mode(output_path) == chmod_value
assert '/etc/append_join_file_testfiles/file_8'\
in template_executor.calculate_config_file
with open(template_wrapper.output_path, 'r') as output_file:
assert output_file.read() == output_text
def test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file_and_the_autoupdate_parameter_is_set__the_method_joins_a_target_file_and_a_template__removes_a_path_to_file_from_the_config_file_and_updates_a_package_CONTENTS_file(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/append_join_file_testfiles/file_9')
cfg_path = os.path.join(os.path.dirname(target_path),
'._cfg0001_file_9')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'bind',
'autoupdate': True})
template_text = 'section-name { parameter-2 no; }'
output_text =\
'section-name {\n parameter-1 no;\n parameter-2 no;\n};\n'
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
template_text=template_text,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_join_file(template_wrapper)
assert os.path.exists(target_path)
assert not os.path.exists(cfg_path)
assert '/etc/append_join_file_testfiles/file_9'\
not in template_executor.calculate_config_file
assert '/etc/append_join_file_testfiles/file_9'\
in template_wrapper.target_package
with open(template_wrapper.output_path, 'r') as output_file:
assert output_file.read() == output_text
def test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file_and_there_is_some_cfg_files_and_the_autoupdate_parameter_is_set__the_method_joins_a_target_file_and_a_template__removes_a_path_to_file_from_the_config_file__removes_all_cfg_files_and_updates_a_package_CONTENTS_file(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/append_join_file_testfiles/file_10')
cfg_path_1 = os.path.join(os.path.dirname(target_path),
'._cfg0001_file_10')
cfg_path_2 = os.path.join(os.path.dirname(target_path),
'._cfg0002_file_10')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'bind',
'autoupdate': True})
template_text = 'section-name { parameter-4 yes; }'
output_text =\
'section-name {\n parameter-1 yes;\n parameter-4 yes;\n};\n'
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
template_text=template_text,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_join_file(template_wrapper)
print('input path = {}'.format(template_wrapper.input_path))
assert os.path.exists(target_path)
assert not os.path.exists(cfg_path_1)
assert not os.path.exists(cfg_path_2)
assert '/etc/append_join_file_testfiles/file_10'\
not in template_executor.calculate_config_file
assert '/etc/append_join_file_testfiles/file_10'\
in template_wrapper.target_package
with open(template_wrapper.output_path, 'r') as output_file:
output_file_text = output_file.read()
print('Output:\n{}'.format(output_file_text))
assert output_file_text == output_text
def test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file_and_there_is_two_cfg_files__the_method_creates_third_cfg_file_and_updates_config_file(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/append_join_file_testfiles/file_11')
cfg_path_1 = os.path.join(os.path.dirname(target_path),
'._cfg0001_file_11')
cfg_path_2 = os.path.join(os.path.dirname(target_path),
'._cfg0002_file_11')
cfg_path_3 = os.path.join(os.path.dirname(target_path),
'._cfg0003_file_11')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'bind'})
template_text = 'section-name { parameter-4 yes; }'
output_text =\
'section-name {\n parameter-1 yes;\n parameter-4 yes;\n};\n'
output_md5 = hashlib.md5(output_text.encode()).hexdigest()
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
template_text=template_text,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_join_file(template_wrapper)
print('output_path = {}'.format(template_wrapper.output_path))
assert os.path.exists(target_path)
assert os.path.exists(cfg_path_1)
assert os.path.exists(cfg_path_2)
assert os.path.exists(cfg_path_3)
assert '/etc/append_join_file_testfiles/file_11'\
in template_executor.calculate_config_file
assert template_executor.calculate_config_file.compare_md5(
'/etc/append_join_file_testfiles/file_11', output_md5)
with open(template_wrapper.output_path, 'r') as output_file:
output_file_text = output_file.read()
print('Output:\n{}'.format(output_file_text))
assert output_file_text == output_text
def test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file_and_there_is_two_cfg_files_and_changes_from_a_template_is_similar_to_the_last_one__the_method_does_nothing(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/append_join_file_testfiles/file_12')
cfg_path_2 = os.path.join(os.path.dirname(target_path),
'._cfg0002_file_12')
cfg_path_3 = os.path.join(os.path.dirname(target_path),
'._cfg0003_file_12')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'bind'})
template_text = 'section-name { parameter-3 10; }'
output_text =\
'section-name {\n parameter-1 yes;\n parameter-3 10;\n};\n'
output_md5 = hashlib.md5(output_text.encode()).hexdigest()
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
template_text=template_text,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_join_file(template_wrapper)
assert os.path.exists(target_path)
assert os.path.exists(cfg_path_2)
assert not os.path.exists(cfg_path_3)
assert '/etc/append_join_file_testfiles/file_12'\
in template_executor.calculate_config_file
assert template_executor.calculate_config_file.compare_md5(
'/etc/append_join_file_testfiles/file_12', output_md5)
with open(cfg_path_2, 'r') as output_file:
output_file_text = output_file.read()
assert output_file_text == output_text
def test_unprotected_for_file_without_changes(self):
pass
def test_unprotected_for_file_with_changes(self):
pass
def test_unbound_for_file_without_changes(self):
pass
def test_unbound_for_file_with_changes(self):
pass
def test_to_remove_changed_testfiles(self):
shutil.rmtree(os.path.join(CHROOT_PATH, 'etc'))
shutil.rmtree(os.path.join(CHROOT_PATH,

@ -49,3 +49,7 @@ obj /etc/append_join_file_testfiles/file_4 ee090b452dbf92d697124eb424f5de5b 1592
obj /etc/append_join_file_testfiles/file_5 ee090b452dbf92d697124eb424f5de5b 1592574626
obj /etc/append_join_file_testfiles/file_6 ee090b452dbf92d697124eb424f5de5b 1592574626
obj /etc/append_join_file_testfiles/file_7 ee090b452dbf92d697124eb424f5de5b 1592574626
obj /etc/append_join_file_testfiles/file_8 ee090b452dbf92d697124eb424f5de5b 1592574626
obj /etc/append_join_file_testfiles/file_9 ee090b452dbf92d697124eb424f5de5b 1592574626
obj /etc/append_join_file_testfiles/file_10 ee090b452dbf92d697124eb424f5de5b 1592574626
obj /etc/append_join_file_testfiles/file_11 ee090b452dbf92d697124eb424f5de5b 1592574626

@ -0,0 +1,3 @@
/etc/append_join_file_testfiles/file_10 1668d31fd2a8e3f2c9ecedc5335d8f67
/etc/append_join_file_testfiles/file_11 1668d31fd2a8e3f2c9ecedc5335d8f67
/etc/append_join_file_testfiles/file_12 1668d31fd2a8e3f2c9ecedc5335d8f67
Loading…
Cancel
Save