From 322685ae1cbd18bca03bfc9060732400a1f7119f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=81?= Date: Wed, 10 Jun 2020 18:06:44 +0300 Subject: [PATCH] TemplateExecutor methods for mode and owner information is tested and improved. Testing methods for working with a filesystem is started. --- .pytest_cache/v/cache/lastfailed | 255 +--------------- .pytest_cache/v/cache/nodeids | 53 ++-- =5.0 | 11 - calculate/templates/template_engine.py | 55 ++-- calculate/templates/template_processor.py | 85 +++++- calculate/utils/files.py | 2 +- tests/templates/test_parameters_processor.py | 64 ++-- tests/templates/test_template_executor.py | 282 +++++++++++++++--- tests/templates/test_template_wrapper.py | 6 +- .../etc/chmod_testfiles/file_2} | 0 .../etc/chown_testfiles/file_2 | 0 .../etc/dir/dir_1/config.json | 17 -- .../test_executor_root/etc/dir/file.conf | 5 - .../etc/dir/subdir/config.json | 17 -- .../test_executor_root/etc/dir/subdir/file | 6 - .../testfiles/test_executor_root/etc/group | 66 ++++ .../testfiles/test_executor_root/etc/passwd | 42 +++ .../etc/dir/file.conf | 0 .../test_parameters_processor_root/etc/group | 66 ++++ .../test_parameters_processor_root/etc/passwd | 42 +++ .../test_dir_1/file.test} | 0 .../test_root/var/lib/calculate/config | 0 22 files changed, 643 insertions(+), 431 deletions(-) delete mode 100644 =5.0 rename tests/templates/testfiles/{test_dir_1/file.test => test_executor_root/etc/chmod_testfiles/file_2} (100%) mode change 100755 => 100644 tests/templates/testfiles/test_executor_root/etc/chown_testfiles/file_2 delete mode 100644 tests/templates/testfiles/test_executor_root/etc/dir/dir_1/config.json delete mode 100644 tests/templates/testfiles/test_executor_root/etc/dir/file.conf delete mode 100644 tests/templates/testfiles/test_executor_root/etc/dir/subdir/config.json delete mode 100644 tests/templates/testfiles/test_executor_root/etc/dir/subdir/file create mode 100644 tests/templates/testfiles/test_executor_root/etc/group create mode 100644 tests/templates/testfiles/test_executor_root/etc/passwd rename tests/templates/testfiles/{ => test_parameters_processor_root}/etc/dir/file.conf (100%) create mode 100644 tests/templates/testfiles/test_parameters_processor_root/etc/group create mode 100644 tests/templates/testfiles/test_parameters_processor_root/etc/passwd rename tests/templates/testfiles/{test_executor_root/etc/chown_testfiles/file_1 => test_parameters_processor_root/test_dir_1/file.test} (100%) create mode 100644 tests/templates/testfiles/test_parameters_processor_root/test_root/var/lib/calculate/config diff --git a/.pytest_cache/v/cache/lastfailed b/.pytest_cache/v/cache/lastfailed index 9c24247..059b3f4 100644 --- a/.pytest_cache/v/cache/lastfailed +++ b/.pytest_cache/v/cache/lastfailed @@ -1,257 +1,10 @@ { - "tests/templates/format/test_base.py::TestJoinMethod::test_if_input_dictionaries_have_no_sections_and_have_only_parameter_lines__it_will_be_processed_correctly": true, - "tests/templates/format/test_base.py::TestJoinMethod::test_if_input_template_dictionary_has_delete_mark_for_parameter__parameter_will_be_deleted": true, - "tests/templates/format/test_base.py::TestJoinMethod::test_if_input_template_dictionary_has_delete_mark_for_section__section_will_be_deleted": true, - "tests/templates/format/test_base.py::TestJoinMethod::test_if_input_template_dictionary_has_replace_mark_for_section__section_will_be_deleted": true, - "tests/templates/format/test_base.py::TestJoinMethod::test_if_inputs_are_dictionaries_with_parameters_with_same_name_in_same_section__parameters_values_in_original_dictionary_changed_to_values_from_template": true, - "tests/templates/format/test_base.py::TestJoinMethod::test_if_inputs_are_dictionaries_with_same_sections_which_contain_different_parameters__a_section_from_the_template_added_to_the_same_section_of_original_dictionary": true, - "tests/templates/format/test_base.py::TestJoinMethod::test_if_inputs_are_dictionaries_with_string_keys_without_any_action_marks__the_dictionaties_just_merged": true, - "tests/templates/format/test_base.py::TestJoinMethod::test_if_inputs_are_dictionaries_with_tuple_keys_without_any_action_marks_as_their_keys__the_dictionaries_just_merged": true, - "tests/templates/format/test_base.py::TestLogicLinesMethod::test_if_input_is_text_document_the_method_returns_list_of_its_lines": true, - "tests/templates/format/test_base.py::TestLogicLinesMethod::test_if_lines_in_document_divided_using_backslash_as_continuation_symbol__method_returns_list_of_full_lines": true, "tests/templates/format/test_bind.py::TestParsingMethods::test_if_comment_parameter_is_set_for_template__format_object_will_parse_comments_with_comment_symbol_from_this_parameter": true, - "tests/templates/format/test_bind.py::TestParsingMethods::test_if_input_document_contains_blocks_and_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element": true, - "tests/templates/format/test_bind.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true, - "tests/templates/format/test_bind.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_values_or_with_empty_block__the_document_object_contains_dictionary_with_item_to_delete": true, - "tests/templates/format/test_bind.py::TestParsingMethods::test_if_input_document_contains_some_block_of_parameters__the_initialised_object_contains_correct_dictionary": true, - "tests/templates/format/test_bind.py::TestParsingMethods::test_if_input_document_contains_some_blocks_with_similar_names__the_blocks_join_recursively": true, - "tests/templates/format/test_bind.py::TestParsingMethods::test_if_parameters_and_blocks_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value_or_with_special_key_in_block_dictionary": true, - "tests/templates/format/test_bind.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments": true, - "tests/templates/format/test_bind.py::TestParsingMethods::test_joining_documents_1": true, - "tests/templates/format/test_bind.py::TestParsingMethods::test_make_template": true, - "tests/templates/format/test_compiz.py::TestParsingMethods::test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary": true, - "tests/templates/format/test_compiz.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true, - "tests/templates/format/test_compiz.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values_and_sections_to_delete__the_document_object_contains_dictionary_with_item_to_delete": true, - "tests/templates/format/test_compiz.py::TestParsingMethods::test_if_input_document_contains_sections_with_different_names_but_different_parameters__the_parameters_merged_in_one_section": true, - "tests/templates/format/test_compiz.py::TestParsingMethods::test_if_input_document_contains_sections_with_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element": true, - "tests/templates/format/test_compiz.py::TestParsingMethods::test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value": true, - "tests/templates/format/test_compiz.py::TestParsingMethods::test_if_the_ignore_comments_flag_is_set__the_parser_ignores_all_comments": true, - "tests/templates/format/test_compiz.py::TestParsingMethods::test_joining_documents_1": true, - "tests/templates/format/test_compiz.py::TestParsingMethods::test_make_template": true, - "tests/templates/format/test_contents.py::TestParsingMethods::test_if_input_document_contains_a_few_lines_with_some_action_symbols__the_initialised_object_contains_correct_dictionary": true, - "tests/templates/format/test_contents.py::TestParsingMethods::test_if_input_document_contains_a_few_lines_without_any_action_symbols__the_initialised_object_contains_correct_dictionary": true, - "tests/templates/format/test_contents.py::TestParsingMethods::test_if_template_parser_flag_is_set_False__the_initialized_object_contains_correct_dictionary_for_contents_util_module": true, - "tests/templates/format/test_contents.py::TestParsingMethods::test_joining_documents_1": true, - "tests/templates/format/test_diff.py::TestExecuteMethods::test_if_diff_patch_used_for_patching_of_directories__it_changes_files_in_directories_and_adds_ones": true, - "tests/templates/format/test_diff.py::TestExecuteMethods::test_if_diff_patch_used_for_patching_of_several_files__it_changes_patched_file_correctly": true, - "tests/templates/format/test_dovecot.py::TestParsingMethods::test_if_input_document_contains_blocks_and_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element": true, - "tests/templates/format/test_dovecot.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true, - "tests/templates/format/test_dovecot.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_values_or_with_empty_block__the_document_object_contains_dictionary_with_item_to_delete": true, - "tests/templates/format/test_dovecot.py::TestParsingMethods::test_if_input_document_contains_some_block_of_parameters__the_initialised_object_contains_correct_dictionary": true, - "tests/templates/format/test_dovecot.py::TestParsingMethods::test_if_input_document_contains_some_blocks_with_similar_names__the_blocks_join_recursively": true, - "tests/templates/format/test_dovecot.py::TestParsingMethods::test_if_parameters_and_blocks_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value_or_with_special_key_in_block_dictionary": true, - "tests/templates/format/test_dovecot.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments": true, - "tests/templates/format/test_dovecot.py::TestParsingMethods::test_joining_documents_1": true, - "tests/templates/format/test_dovecot.py::TestParsingMethods::test_make_template": true, - "tests/templates/format/test_json.py::TestParsingMethods::test_if_input_document_contains_just_few_parameters_and_parameter_blocks__the_initialised_object_contains_correct_dictionary": true, - "tests/templates/format/test_json.py::TestParsingMethods::test_joining_documents_1": true, - "tests/templates/format/test_json.py::TestParsingMethods::test_make_template": true, - "tests/templates/format/test_kde.py::TestParsingMethods::test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary": true, - "tests/templates/format/test_kde.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true, - "tests/templates/format/test_kde.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values_and_sections_to_delete__the_document_object_contains_dictionary_with_item_to_delete": true, - "tests/templates/format/test_kde.py::TestParsingMethods::test_if_input_document_contains_parameters_with_values_with_unicode_symbols__the_initialized_object_contains_correct_dictionary": true, - "tests/templates/format/test_kde.py::TestParsingMethods::test_if_input_document_contains_sections_with_different_names_but_different_parameters__the_parameters_merged_in_one_section": true, - "tests/templates/format/test_kde.py::TestParsingMethods::test_if_input_document_contains_sections_with_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element": true, - "tests/templates/format/test_kde.py::TestParsingMethods::test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value": true, - "tests/templates/format/test_kde.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments": true, - "tests/templates/format/test_kde.py::TestParsingMethods::test_joining_documents_1": true, - "tests/templates/format/test_kde.py::TestParsingMethods::test_make_template": true, - "tests/templates/format/test_kernel.py::TestParsingMethods::test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary": true, - "tests/templates/format/test_kernel.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true, - "tests/templates/format/test_kernel.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values__the_document_object_contains_dictionary_with_item_to_delete": true, - "tests/templates/format/test_kernel.py::TestParsingMethods::test_if_input_document_contains_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element": true, - "tests/templates/format/test_kernel.py::TestParsingMethods::test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value": true, - "tests/templates/format/test_kernel.py::TestParsingMethods::test_joining_documents_1": true, - "tests/templates/format/test_kernel.py::TestParsingMethods::test_make_template": true, - "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_input_doc_contains_some_type_sections_with_plain_directives__object_dictionary_contains_correct_dictionary_with_directives_values_and_comments": true, - "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_input_doc_contains_some_type_sections_with_plain_directives_and_action_marks__object_dictionary_contains_correct_dictionary_with_directives_values_and_comments": true, - "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_input_document_contains_access_to_directive__the_object_s_dictionary_contains_correct_dictionary_with_list_of_access_to_parameters_and_comments": true, - "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_input_document_contains_comments_to_type_sections__the_object_s_dictionary_collect_them": true, - "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_input_document_contains_index_directives__the_object_s_dictionary_contains_correct_dictionary_with_index_elements_and_comments": true, - "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_input_document_contains_syncrepl_and_access_to_constructions_with_action_marks__object_dictionary_contains_correct_dictionary_with_action_marks": true, - "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_input_document_contains_syncrepl_directive__the_object_s_dictionary_contains_correct_dictionary_with_list_of_syncrepl_parameters_and_comments": true, - "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_logiclines_method_takes_text_with_lines_that_starts_whit_space_symbols__it_returns_joined_lines": true, - "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_template_text_contains_some_access_to_constuctions_with_same_what_value_and_without_action_marks_for_whole_constructions__they_join_in_one_access_to_construction": true, - "tests/templates/format/test_ldap.py::TestParsingMethods::test_joining_documents_1": true, - "tests/templates/format/test_openrc.py::TestParsingMethods::test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary": true, - "tests/templates/format/test_openrc.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true, - "tests/templates/format/test_openrc.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values__the_document_object_contains_dictionary_with_item_to_delete": true, - "tests/templates/format/test_openrc.py::TestParsingMethods::test_if_input_document_contains_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element": true, - "tests/templates/format/test_openrc.py::TestParsingMethods::test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value": true, - "tests/templates/format/test_openrc.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments": true, - "tests/templates/format/test_openrc.py::TestParsingMethods::test_joining_documents_1": true, - "tests/templates/format/test_openrc.py::TestParsingMethods::test_make_template": true, - "tests/templates/format/test_postfix.py::TestParsingMethods::test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary": true, - "tests/templates/format/test_postfix.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true, - "tests/templates/format/test_postfix.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values__the_document_object_contains_dictionary_with_item_to_delete": true, - "tests/templates/format/test_postfix.py::TestParsingMethods::test_if_input_document_contains_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element": true, - "tests/templates/format/test_postfix.py::TestParsingMethods::test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value": true, - "tests/templates/format/test_postfix.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments": true, - "tests/templates/format/test_postfix.py::TestParsingMethods::test_joining_documents_1": true, - "tests/templates/format/test_postfix.py::TestParsingMethods::test_make_template": true, - "tests/templates/format/test_procmail.py::TestParsingMethods::test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary": true, - "tests/templates/format/test_procmail.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true, - "tests/templates/format/test_procmail.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values__the_document_object_contains_dictionary_with_item_to_delete": true, - "tests/templates/format/test_procmail.py::TestParsingMethods::test_if_input_document_contains_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element": true, - "tests/templates/format/test_procmail.py::TestParsingMethods::test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value": true, - "tests/templates/format/test_procmail.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments": true, - "tests/templates/format/test_procmail.py::TestParsingMethods::test_joining_documents_1": true, - "tests/templates/format/test_procmail.py::TestParsingMethods::test_make_template": true, - "tests/templates/format/test_proftpd.py::TestParsingMethods::test_if_input_document_contains_blocks_and_parameters_with_action_marks__the_key_tuples_of_parameters_s_have_it_as_its_first_element_inherited": true, - "tests/templates/format/test_proftpd.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true, - "tests/templates/format/test_proftpd.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_any_values_the_document_object_contains_dictionary_with_this_items_to_delete": true, - "tests/templates/format/test_proftpd.py::TestParsingMethods::test_if_input_document_contains_some_block_of_parameters__the_initialised_object_contains_correct_dictionary": true, - "tests/templates/format/test_proftpd.py::TestParsingMethods::test_if_parameters_and_blocks_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value_or_with_special_key_in_block_dictionary": true, - "tests/templates/format/test_proftpd.py::TestParsingMethods::test_if_the_ignoreComments_flag_is_set__the_parser_ignores_all_comments": true, - "tests/templates/format/test_proftpd.py::TestParsingMethods::test_joining_documents_1": true, - "tests/templates/format/test_regex.py::TestParsingMethods::test_if_input_patch_document_contains_only_regular_expressions_without_any_regex_flags__it_correctly_patches_input_document": true, - "tests/templates/format/test_regex.py::TestParsingMethods::test_if_input_patch_document_contains_regular_expressions_with_global_regex_flags_and_flags_as_attributes__it_correctly_patches_input_document_using_regex_flags": true, - "tests/templates/format/test_samba.py::TestParsingMethods::test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary": true, - "tests/templates/format/test_samba.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true, - "tests/templates/format/test_samba.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values_and_sections_to_delete__the_document_object_contains_dictionary_with_item_to_delete": true, - "tests/templates/format/test_samba.py::TestParsingMethods::test_if_input_document_contains_sections_with_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element": true, - "tests/templates/format/test_samba.py::TestParsingMethods::test_if_input_document_contains_sections_with_similar_names_but_different_parameters__the_parameters_merged_in_one_section": true, - "tests/templates/format/test_samba.py::TestParsingMethods::test_if_input_document_parameters_contains_upper_case_symbols__it_becomes_lower_case": true, - "tests/templates/format/test_samba.py::TestParsingMethods::test_if_joinBefore_flag_is_set__the_document_object_contains_dictionary_with_sections_added_in_the_top_of_it": true, - "tests/templates/format/test_samba.py::TestParsingMethods::test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value": true, - "tests/templates/format/test_samba.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments": true, - "tests/templates/format/test_samba.py::TestParsingMethods::test_joining_documents_1": true, - "tests/templates/format/test_samba.py::TestParsingMethods::test_make_template": true, - "tests/templates/format/test_xml_gconf.py::TestParsingMethods::test_if_input_document_is_simple_gconf__the_format_object_contains_correct_dictionary": true, - "tests/templates/format/test_xml_gconf.py::TestParsingMethods::test_if_input_document_is_simple_gconf_tree__the_format_object_contains_correct_dictionary": true, - "tests/templates/format/test_xml_gconf.py::TestParsingMethods::test_joining_documents_1": true, - "tests/templates/format/test_xml_xfce.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true, - "tests/templates/format/test_xml_xfce.py::TestParsingMethods::test_joining_documents_1": true, - "tests/templates/test_directory_processor.py::TestDirectoryProcessor::test_just_for_debug_with_package_value": true, - "tests/templates/test_directory_processor.py::TestDirectoryProcessor::test_just_for_debug_without_package_value": true, - "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_initialized_accoding_to_dictionary_of_correct_template_parameters__the_TemplateParameters_object_contains_processed_parameters_as_its_attributes_including_default_values": true, - "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_as_dir_parameters_object_using_correct_source_parameter_with_append_link__the_object_will_be_initialized_successfully": true, - "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_as_dir_parameters_object_using_source_parameter_but_without_append_link__the_initialization_of_the_object_will_be_failed": true, - "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_append_parameter__a_value_of_the_parameter_will_be_checked": true, - "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_autoupdate_parameter__a_value_of_the_parameter_will_be_checked": true, - "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chmod_parameter__the_object_will_be_initialized_successfully": true, - "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chmod_parameter_in_its_digital_form__the_object_will_be_initialized_successfully": true, - "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chown_parameter__the_object_will_be_initialized_successfully": true, - "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chown_parameter_in_its_digital_form__the_object_will_be_initialized_successfully": true, - "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_force_parameter__the_object_will_be_initialized_successfully": true, - "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_source_parameter__the_object_will_be_initialized_successfully": true, - "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_incorrect_autoupdate_parameter__the_initialization_of_the_object_will_be_failed": true, - "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_incorrect_chown_parameter__the_initialization_of_the_object_will_be_failed": true, - "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_incorrect_force_parameter__the_initialization_of_the_object_will_be_failed": true, - "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_source_parameter_with_unexisting_file_path__the_initialization_of_the_object_will_be_failed": true, + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_bla_bla": true, + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_initialized_using_": true, "tests/templates/test_template_action.py": true, "tests/templates/test_template_action.py::TestTemplateAction::test_create_directory": true, - "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_binded_with_datavars_module__variables_available_in_a_template": true, - "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_calculate_tag_contains_pkg_function_with_an_existing_package_in_its_argument__the_pkg_function_returns_version_value_of_the_package_from_package_parameter_without_any_exceptions": true, - "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_calculate_tag_with_some_parameters__the_template_engine_object_will_collect_its_parameters": true, - "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_condition_and_it_is_True__the_template_engine_object_will_be_initialized_without_any_exceptions": true, - "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_env_parameter_in_which_module_name_is_assigned__the_variables_from_this_module_can_be_used_in_template_without_determining_of_their_module": true, - "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_pkg_function_with_existing_package_as_its_argument__it_works_correctly_and_pkg_function_returns_version_value": true, - "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_pkg_function_with_package_that_does_not_exist_in_its_argument__it_works_correctly_and_pkg_function_returns_empty_version_value": true, - "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_pkg_function_without_any_arguments_and_without_package_parameter_in_calculate_tag__the_pkg_function_returns_empty_version_value": true, - "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_pkg_function_without_any_arguments_but_with_package_parameter_in_calculate_tag__the_pkg_function_returns_version_value_of_the_package_from_package_parameter": true, - "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_several_calculate_tags__the_template_engine_will_parse_them_all_and_will_contain_all_parameters_and_result_of_all_conditions": true, - "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_several_conditions_and_it_is_False__the_template_engine_raises_ConditionFailed_exception": true, - "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_variables_in_its_text__the_rendered_text_will_contain_values_of_this_variables": true, - "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_value_of_variable_is_set_using_save_tag__the_new_value_of_variable_can_be_used_in_template": true, + "tests/templates/test_template_executor.py::TestTemplateAction": true, "tests/templates/test_template_executor.py::TestTemplateAction::test_if_chown_value_is_not_correct__a_TemplateExecutor_object_throws_TemplateExecutorError_exception": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_TemplateWrapper_object_contains_package_value__the_wrapper_can_use_Package_object_for_changing_CONTENTS_file_of_the_package": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_TemplateWrapper_object_successfully_initialized__the_object_can_be_used_for_a_removing_current_file_from_its_package": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_TemplateWrapper_object_successfully_initialized__the_object_can_be_used_for_an_adding_any_files_to_its_package_and_hash_will_be_calculated_automatically": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_TemplateWrapper_object_successfully_initialized__the_object_can_be_used_for_changing_CONTENTS_using_list_of_changed_files": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_TemplateWrapper_object_successfully_initialized_as_DIR__the_object_can_be_used_for_a_removing_current_directory_and_all_its_contents_from_its_package": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_TemplateWrapper_object_successfully_initialized_as_FILE__the_object_can_be_used_for_an_adding_the_current_file_to_its_package_and_hash_will_be_calculated_automatically": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_TemplateWrapper_object_successfully_initialized_as_FILE__the_object_can_be_used_for_an_adding_the_current_file_to_its_package_with_specified_hash": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_TemplateWrapper_object_successfully_initialized_with_DIR_type__the_object_can_be_used_for_a_removing_all_directory_files_from_its_package": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_TemplateWrapper_was_used_to_change_CONTENTS__it_should_be_saved_using_save_changes_method": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_target_file_directory_contains_no_cfg_files_but_it_is_necessary_to_create_one__the_first_cfg_file_should_be_named_cfg0001_file": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_target_file_directory_contains_some_cfg_files_but_some_of_them_are_missed__the_next_cfg_file_should_be_named_with_the_number_following_the_number_of_the_last_one": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_target_file_directory_contains_some_cfg_files_including_the_first_one__the_next_cfg_file_should_be_named_with_the_number_following_the_number_of_the_last_one": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_target_file_does_not_belong_to_any_package__the_TemplateWrapper_object_sets_the_md5_matching_flag_as_False": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_target_file_does_not_exist_and_CONTENTS_file_of_the_file_s_package_does_not_contain_this_file__the_TemplateWrapper_sets_the_md5_matching_flag_as_True": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_target_file_is_located_in_a_directory_from_the_protected_mask__the_TemplateWrapper_object_sets_the_protected_flag_as_False": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_target_file_is_located_in_a_directory_that_is_not_protected__the_TemplateWrapper_object_sets_the_protected_flag_as_False": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_target_file_is_located_in_a_protected_directory__the_TemplateWrapper_object_sets_the_protected_flag_as_True": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_target_file_is_not_protected__the_TemplateWrapper_sets_the_md5_matching_flag_as_True": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_target_file_s_hash_does_not_match_the_hash_from_the_package_s_CONTENTS_file__the_TemplateWrapper_object_sets_the_md5_matching_flag_as_False": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_target_file_s_hash_matches_the_hash_from_the_package_s_CONTENTS_file__the_TemplateWrapper_object_sets_the_md5_matching_flag_as_True": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_target_file_was_deleted_by_a_user__the_TemplateWrapper_object_sets_the_md5_matching_flag_as_False": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_target_path_is_DIR_and_a_template_is_executable__the_target_path_is_the_same_and_there_is_no_package_type_conflicts_and_other_checks": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_target_path_is_FILE_and_a_template_is_executable__the_target_path_is_replaced_with_the_path_to_the_cwd_directory_and_there_is_no_package_type_conflicts_and_other_checks": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_template_contains_the_autoupdate_parameter__the_TemplateWrapper_sets_the_md5_matching_flag_as_True": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_template_contains_the_autoupdate_parameter_and_a_target_file_does_not_belong_to_any_package__the_TemplateWrapper_sets_the_md5_matching_flag_as_True": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_template_contains_the_unbound_parameter__the_TemplateWrapper_sets_the_md5_matching_flag_as_True": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_template_is_executable_and_contains_package_parameter__the_template_updates_the_CONTENTS_file_for_package_from_parameter": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_after_removing_some_files_thought_TemplateWrapper_some_directories_become_empty__empty_directories_will_be_removed_saving_changes": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_after_the_target_file_check_md5_matching_flag_is_set_as_False_and_a_template_contains_source_parameter__the_output_path_is_the_cfg_file_path_and_the_input_path_is_the_calculate_archive_path": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_after_the_target_file_check_md5_matching_flag_is_set_as_False_and_a_template_does_not_contain_source_parameter__the_output_path_is_the_cfg_file_path_and_the_input_path_is_the_calculate_archive_path": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_after_the_target_file_check_md5_matching_flag_is_set_as_True_and_a_template_contains_source_parameter__the_output_and_the_input_paths_for_the_TemplateExecutor_is_the_same_and_it_is_target_path": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_after_the_target_file_check_md5_matching_flag_is_set_as_True_and_a_template_does_not_contain_source_parameter__the_output_and_the_input_paths_for_the_TemplateExecutor_is_the_same_and_it_is_target_path": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_exec_parameter_is_set_for_template__no_checks_are_carried_out_while_TemplateWrapper_object_initialization": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_get_archive_path_method_has_the_file_path_as_its_argument__it_returns_the_path_to_the_archive_version_of_the_input_file": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_mirror_parameter_is_set_and_file_from_the_source_parameter_does_not_exist__a_TemplateWrapper_object_sets_remove_original_flag_as_True": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_mirror_parameter_is_set_and_target_file_does_not_exist__a_TemplateWrapper_object_throws_TemplateExecutorError": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_run_parameter_is_set_for_template__no_checks_are_carried_out_while_TemplateWrapper_object_initialization": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::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": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_template_contains_package_parameter_and_target_file_belongs_to_the_package_from_package_parameter__the_TemplateWrapper_uses_package_from_them": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::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": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_template_contains_package_parameter_but_target_file_belongs_to_the_other_package__the_TemplateWrapper_throws_TemplateCollisionError": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_template_does_not_have_package_parameter_but_target_file_belongs_to_the_package__the_TemplateWrapper_uses_package_from_parameter": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_template_type_is_DIR_and_target_file_is_DIR__the_TemplateWrapper_target_type_is_DIR": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::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": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_template_type_is_DIR_and_target_file_is_FILE_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::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": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::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": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::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": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::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": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_template_type_is_DIR_but_target_file_is_FILE_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::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": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::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": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::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": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::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": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::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": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::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": true, - "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": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_template_type_is_FILE_and_target_file_is_FILE__the_TemplateWrapper_target_type_is_FILE": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::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": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_template_type_is_FILE_but_target_file_is_DIR_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_template_type_is_FILE_but_target_file_is_DIR_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_template_type_is_FILE_but_target_file_is_a_link_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::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": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::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": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::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": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::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": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::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": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::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": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::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": true, - "tests/templates/test_template_wrapper.py::TestTemplateWrapper::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": true, - "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": true, - "tests/utils/test_files.py::TestUtils::test_if_a_pipe_Process_object_uses_for_several_writes__it_successfully_executes_even_after_read": true, - "tests/utils/test_files.py::TestUtils::test_if_a_pipe_Process_object_uses_for_several_writes_without_readings__it_successfully_executes": true, - "tests/utils/test_files.py::TestUtils::test_if_pipe_is_executed_using_Process_object__it_has_successfully_executed": true, - "tests/utils/test_files.py::TestUtils::test_if_single_correct_command_executed_using_Process_object__it_successfully_executes": true, - "tests/utils/test_package.py::TestContents::test_if_PackageContents_object_contains_contents_dictionary__it_renders_CONTENTS_file_correctly": true, - "tests/utils/test_package.py::TestContents::test_if_PackageContents_object_initialized_by_existing_package__it_contains_dictionary_of_items_from_contents_file": true, - "tests/utils/test_package.py::TestContents::test_if_new_directory_is_added_in_contents_file_using_add_dir_method__the_PackageContents_object_renders_the_contents_file_with_new_dir": true, - "tests/utils/test_package.py::TestContents::test_if_new_link_is_added_in_contents_file_using_add_sym_method__the_PackageContents_object_renders_the_contents_file_with_new_sym": true, - "tests/utils/test_package.py::TestContents::test_if_new_object_is_added_in_contents_file_using_add_obj_method__the_PackageContents_object_renders_the_contents_file_with_new_obj": true, - "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_parsed_a_correct_package_atom_name_but_without_a_slot_and_use_flags__the_PackageAtom_object_returns_atom_name_of_package": true, - "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_parsed_a_correct_package_atom_name_with_a_slot_value__the_PackageAtom_returns_atom_name_of_package_with_this_slot": true, - "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_parsed_a_correct_package_atom_name_with_a_uses_value__the_PackageAtom_object_returns_atom_name_of_package_with_this_use_flags": true, - "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_parsed_a_correct_package_atom_name_with_an_empty_slot_value__the_PackageAtom_object_returns_atom_name_of_package": true, - "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_parses_a_correct_package_atom_name_without_version_value_but_with_slot_value__the_PackageAtom_object_looks_for_package_with_assigned_slot_value": true, - "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_parses_a_correct_package_atom_name_without_version_value_but_with_use_flags_value__the_PackageAtom_object_looks_for_package_with_assigned_use_flags": true, - "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_tried_to_parse_an_correct_package_atom_name_that_matches_multiple_packages__the_PackageAtom_object_gets_info_for_package_with_older_version": true, - "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_tried_to_parse_an_incorrect_package_atom_name__the_PackageAtom_object_throws_the_PackageAtomError_exception": true, - "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_tried_to_parse_an_package_atom_name_with_incorrect_use_flags__the_PackageAtom_object_throws_the_PackageAtomError_exception": true, - "tests/utils/test_package.py::TestContents::test_if_the_get_file_package_method_of_the_PackageAtom_object_is_called_with_a_name_of_a_file_that_belongs_to_any_package__the_PackageAtom_object_contains_dictionary_with_an_owner_package": true, - "tests/utils/test_package.py::TestContents::test_if_the_get_file_package_method_of_the_PackageAtom_object_is_called_with_a_name_of_a_file_that_does_not_belong_to_any_package__the_PackageAtom_object_throws_the_PackageAtomError_exception": true, - "tests/utils/test_package.py::TestContents::test_if_two_Version_objects_compared_using_eq_operation_and_the_left_version_value_is_less_than_or_equal_to_the_right_version__the_result_of_the_comparing_would_be_True": true, - "tests/utils/test_package.py::TestContents::test_if_two_Version_objects_compared_using_ge_operation_and_the_left_version_value_is_less_than_or_equal_to_the_right_version__the_result_of_the_comparing_would_be_True": true, - "tests/utils/test_package.py::TestContents::test_if_two_Version_objects_compared_using_gt_operation_and_the_left_version_value_is_less_than_the_right_version__the_result_of_the_comparing_would_be_True": true, - "tests/utils/test_package.py::TestContents::test_if_two_Version_objects_compared_using_le_operation_and_the_left_version_value_is_less_than_or_equal_to_the_right_version__the_result_of_the_comparing_would_be_True": true, - "tests/utils/test_package.py::TestContents::test_if_two_Version_objects_compared_using_lt_operation_and_the_left_version_value_is_less_than_the_right_version__the_result_of_the_comparing_would_be_True": true, - "tests/utils/test_package.py::TestContents::test_if_two_Version_objects_compared_using_ne_operation_and_the_left_version_value_is_less_than_or_equal_to_the_right_version__the_result_of_the_comparing_would_be_True": true, - "tests/vars/test_namespace.py::TestNamespace::test_init_default_path": true, - "tests/vars/test_namespace.py::TestNamespace::test_init_empty_namespace": true + "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_a_TemplateWrapper_object_successfully_initialized__the_object_can_be_used_for_an_adding_any_files_to_its_package_and_hash_will_be_calculated_automatically": true } \ No newline at end of file diff --git a/.pytest_cache/v/cache/nodeids b/.pytest_cache/v/cache/nodeids index 24b0a97..b33f405 100644 --- a/.pytest_cache/v/cache/nodeids +++ b/.pytest_cache/v/cache/nodeids @@ -12,6 +12,7 @@ "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_autoupdate_parameter__a_value_of_the_parameter_will_be_checked", "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_incorrect_autoupdate_parameter__the_initialization_of_the_object_will_be_failed", "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chown_parameter__the_object_will_be_initialized_successfully", + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_initialized_using_dictionary_with_correct_chown_parameter_and_new_chroot_path__the_object_will_be_initialized_successfully", "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chown_parameter_in_its_digital_form__the_object_will_be_initialized_successfully", "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_incorrect_chown_parameter__the_initialization_of_the_object_will_be_failed", "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chmod_parameter__the_object_will_be_initialized_successfully", @@ -29,26 +30,38 @@ "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_pkg_function_without_any_arguments_but_with_package_parameter_in_calculate_tag__the_pkg_function_returns_version_value_of_the_package_from_package_parameter", "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_pkg_function_without_any_arguments_and_without_package_parameter_in_calculate_tag__the_pkg_function_returns_empty_version_value", "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_calculate_tag_contains_pkg_function_with_an_existing_package_in_its_argument__the_pkg_function_returns_version_value_of_the_package_from_package_parameter_without_any_exceptions", - "tests/templates/test_template_executor.py::TestTemplateAction::test_if_config_file_does_not_exist__a_CalculateConfigFile_object_will_create_one_while_its_initialization", - "tests/templates/test_template_executor.py::TestTemplateAction::test_if_config_directory_is_on_the_config_path_instead_of_config_file__a_CalculateConfigFile_object_throws_TemplateExecutorError_exception", - "tests/templates/test_template_executor.py::TestTemplateAction::test_if_a_CalculateConfigFile_object_is_initialized__the_object_can_be_used_for_setting_hash_sum_for_the_any_file", - "tests/templates/test_template_executor.py::TestTemplateAction::test_if_a_CalculateConfigFile_object_is_initialized__the_object_can_be_used_for_removing_any_file_from_config_file", - "tests/templates/test_template_executor.py::TestTemplateAction::test_if_a_CalculateConfigFile_object_contains_file_with_its_hash_and_the_hash_compared_with_equal_hash__the_compare_md5_method_returns_True", - "tests/templates/test_template_executor.py::TestTemplateAction::test_if_a_CalculateConfigFile_object_contains_file_with_its_hash_and_the_hash_compared_with_not_equal_hash__the_compare_md5_method_returns_False", - "tests/templates/test_template_executor.py::TestTemplateAction::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", - "tests/templates/test_template_executor.py::TestTemplateAction::test_if_a_CalculateConfigFile_object_was_used_to_make_changes_in_the_config_file__the_save_changes_method_will_save_the_changes", - "tests/templates/test_template_executor.py::TestTemplateAction::test_if_a_TemplateExecutor_object_is_initialized__the_object_can_return_the_set_of_the_supported_values_of_the_append_parameter", - "tests/templates/test_template_executor.py::TestTemplateAction::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", - "tests/templates/test_template_executor.py::TestTemplateAction::test_if_the_chown_directory_method_input_is_path_to_the_unexisting_directory_and_correct_chown_value__the_chown_directory_method_does_nothing", - "tests/templates/test_template_executor.py::TestTemplateAction::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", - "tests/templates/test_template_executor.py::TestTemplateAction::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", - "tests/templates/test_template_executor.py::TestTemplateAction::test_if_the_chown_file_method_input_is_path_to_the_unexisting_file_and_correct_chown_value__the_chown_directory_method_does_nothing", - "tests/templates/test_template_executor.py::TestTemplateAction::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", - "tests/templates/test_template_executor.py::TestTemplateAction::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", - "tests/templates/test_template_executor.py::TestTemplateAction::test_if_the_chmod_directory_method_input_is_path_to_the_unexisting_directory_and_correct_chmod_value__the_chmod_directory_method_does_nothing", - "tests/templates/test_template_executor.py::TestTemplateAction::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", - "tests/templates/test_template_executor.py::TestTemplateAction::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", - "tests/templates/test_template_executor.py::TestTemplateAction::test_create_directory", + "tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_config_file_does_not_exist__a_CalculateConfigFile_object_will_create_one_while_its_initialization", + "tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_config_directory_is_on_the_config_path_instead_of_config_file__a_CalculateConfigFile_object_throws_TemplateExecutorError_exception", + "tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_a_CalculateConfigFile_object_is_initialized__the_object_can_be_used_for_setting_hash_sum_for_the_any_file", + "tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_a_CalculateConfigFile_object_is_initialized__the_object_can_be_used_for_removing_any_file_from_config_file", + "tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_a_CalculateConfigFile_object_contains_file_with_its_hash_and_the_hash_compared_with_equal_hash__the_compare_md5_method_returns_True", + "tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_a_CalculateConfigFile_object_contains_file_with_its_hash_and_the_hash_compared_with_not_equal_hash__the_compare_md5_method_returns_False", + "tests/templates/test_template_executor.py::TestTemplateExecutor::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", + "tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_a_CalculateConfigFile_object_was_used_to_make_changes_in_the_config_file__the_save_changes_method_will_save_the_changes", + "tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_a_TemplateExecutor_object_is_initialized__the_object_can_return_the_set_of_the_supported_values_of_the_append_parameter", + "tests/templates/test_template_executor.py::TestTemplateExecutor::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", + "tests/templates/test_template_executor.py::TestTemplateExecutor::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", + "tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_chown_directory_method_input_is_path_to_the_unexisting_directory_and_correct_chown_value__the_chown_directory_method_does_nothing", + "tests/templates/test_template_executor.py::TestTemplateExecutor::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", + "tests/templates/test_template_executor.py::TestTemplateExecutor::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", + "tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_chown_file_method_input_is_path_to_the_unexisting_file_and_correct_chown_value__the_chown_directory_method_does_nothing", + "tests/templates/test_template_executor.py::TestTemplateExecutor::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", + "tests/templates/test_template_executor.py::TestTemplateExecutor::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", + "tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_chmod_directory_method_input_is_path_to_the_unexisting_directory_and_correct_chmod_value__the_chmod_directory_method_does_nothing", + "tests/templates/test_template_executor.py::TestTemplateExecutor::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", + "tests/templates/test_template_executor.py::TestTemplateExecutor::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", + "tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_chmod_file_method_input_is_path_to_the_unexisting_file_and_correct_chmod_value__the_chmod_file_method_does_nothing", + "tests/templates/test_template_executor.py::TestTemplateExecutor::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", + "tests/templates/test_template_executor.py::TestTemplateExecutor::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", + "tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_get_file_owner_method_is_called_with_a_path_to_a_directory_that_does_not_exists__the_method_throws_TemplateExecutorError_exception", + "tests/templates/test_template_executor.py::TestTemplateExecutor::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", + "tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_get_file_owner_method_is_called_with_a_path_to_a_file_that_does_not_exists__the_method_throws_TemplateExecutorError_exception", + "tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_get_file_mode_method_is_called_with_a_path_to_a_directory_that_exists__the_method_returns_its_mode_value", + "tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_get_file_mode_method_is_called_with_a_path_to_a_directory_that_does_not_exists__the_method_throws_TemplateExecutorError_exception", + "tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_get_file_mode_method_is_called_with_a_path_to_a_file_that_exists__the_method_returns_its_mode_value", + "tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_get_file_mode_method_is_called_with_a_path_to_a_file_that_does_not_exists__the_method_throws_TemplateExecutorError_exception", + "tests/templates/test_template_executor.py::TestTemplateExecutor::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", + "tests/templates/test_template_executor.py::TestTemplateExecutor::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", "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", "tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_template_type_is_DIR_and_target_file_is_DIR__the_TemplateWrapper_target_type_is_DIR", diff --git a/=5.0 b/=5.0 deleted file mode 100644 index 5102d30..0000000 --- a/=5.0 +++ /dev/null @@ -1,11 +0,0 @@ -Requirement already up-to-date: pytest in /root/.local/lib64/python3.6/site-packages (5.4.3) -Requirement already satisfied, skipping upgrade: importlib-metadata>=0.12; python_version < "3.8" in /root/.local/lib64/python3.6/site-packages (from pytest) (1.1.0) -Requirement already satisfied, skipping upgrade: attrs>=17.4.0 in /root/.local/lib64/python3.6/site-packages (from pytest) (19.3.0) -Requirement already satisfied, skipping upgrade: py>=1.5.0 in /root/.local/lib64/python3.6/site-packages (from pytest) (1.8.0) -Requirement already satisfied, skipping upgrade: packaging in /root/.local/lib64/python3.6/site-packages (from pytest) (19.2) -Requirement already satisfied, skipping upgrade: more-itertools>=4.0.0 in /root/.local/lib64/python3.6/site-packages (from pytest) (8.0.0) -Requirement already satisfied, skipping upgrade: pluggy<1.0,>=0.12 in /root/.local/lib64/python3.6/site-packages (from pytest) (0.13.1) -Requirement already satisfied, skipping upgrade: wcwidth in /root/.local/lib64/python3.6/site-packages (from pytest) (0.1.7) -Requirement already satisfied, skipping upgrade: zipp>=0.5 in /root/.local/lib64/python3.6/site-packages (from importlib-metadata>=0.12; python_version < "3.8"->pytest) (0.6.0) -Requirement already satisfied, skipping upgrade: six in /usr/lib64/python3.6/site-packages (from packaging->pytest) (1.12.0) -Requirement already satisfied, skipping upgrade: pyparsing>=2.0.2 in /root/.local/lib64/python3.6/site-packages (from packaging->pytest) (2.4.5) diff --git a/calculate/templates/template_engine.py b/calculate/templates/template_engine.py index 062aee4..3e5b260 100644 --- a/calculate/templates/template_engine.py +++ b/calculate/templates/template_engine.py @@ -483,13 +483,11 @@ class ParametersProcessor: uid = pwd.getpwnam(user_name).pw_uid else: uid = self.get_uid_from_passwd(user_name) - except (KeyError, TypeError): - self.output.set_error( - format(user_name)) + except (FilesError, KeyError, TypeError) as error: raise IncorrectParameter( - ("'chown' value '{0}' is not correct:" - "no such user in the system: {1}"). - format(chown, user_name)) + "'chown = {}' parameter check is failed: {}". + format(chown, str(error))) + if group_name.isdigit(): gid = int(group_name) else: @@ -498,21 +496,22 @@ class ParametersProcessor: if self.chroot_path == '/': gid = grp.getgrnam(group_name).gr_gid else: + print("using get_gid_from_group") gid = self.get_gid_from_group(group_name) - except (KeyError, TypeError): + except (FilesError, KeyError, TypeError) as error: raise IncorrectParameter( - ("'chown' value '{0}' is not correct:" - "no such group in the system: {1}"). - format(chown, group_name)) + "'chown = {}' parameter check is failed: {}". + format(chown, str(error))) + return {'uid': uid, 'gid': gid} else: raise IncorrectParameter("'chown' value '{0}' is not correct". format(chown, self.template_path)) def get_uid_from_passwd(self, user_name: str): - """Взять uid из chroot passwd файла.""" + """Функция для получения uid из chroot passwd файла.""" passwd_file_path = os.path.join(self.chroot_path, 'etc/passwd') - passwd_dictionary = [] + passwd_dictionary = dict() if os.path.exists(passwd_file_path): with open(passwd_file_path, 'r') as passwd_file: @@ -522,20 +521,22 @@ class ParametersProcessor: passwd_item = tuple(line.split(':')[0:3:2]) - if (len(passwd_item) > 1 and passwd_item[0] - and passwd_item[0]): - passwd_dictionary.append(passwd_item) + if (len(passwd_item) > 1 and passwd_item[0]): + passwd_dictionary[passwd_item[0]] = passwd_item[1] - passwd_dictionary = dict(passwd_dictionary) - return int(passwd_dictionary[user_name]) + if user_name in passwd_dictionary: + return int(passwd_dictionary[user_name]) + else: + raise FilesError("'{0}' uid was not found in {1}". + format(user_name, passwd_file_path)) else: - IncorrectParameter("passwd file was not found in {}". - format(passwd_file_path)) + raise FilesError("passwd file was not found in {}". + format(passwd_file_path)) def get_gid_from_group(self, group_name: str): - """Взять gid из chroot group файла.""" + """Функция для получения gid из chroot group файла.""" group_file_path = os.path.join(self.chroot_path, 'etc/group') - group_dictionary = [] + group_dictionary = dict() if os.path.exists(group_file_path): with open(group_file_path, 'r') as group_file: @@ -546,18 +547,16 @@ class ParametersProcessor: group_item = tuple(line.split(':')[0:3:2]) if len(group_item) > 1 and group_item[0] and group_item[1]: - group_dictionary.append(group_item) - - group_dictionary = dict(group_dictionary) + group_dictionary[group_item[0]] = group_item[1] if group_name in group_dictionary: return int(group_dictionary[group_name]) else: - IncorrectParameter("'{0}' gid was not found in {1}". - format(group_name, group_file_path)) + raise FilesError("'{0}' gid was not found in {1}". + format(group_name, group_file_path)) else: - IncorrectParameter("group file was not found in {}". - format(group_file_path)) + raise FilesError("group file was not found in {}". + format(group_file_path)) @classmethod def _inspect_formats_package(cls): diff --git a/calculate/templates/template_processor.py b/calculate/templates/template_processor.py index 1d82d58..4b9d871 100644 --- a/calculate/templates/template_processor.py +++ b/calculate/templates/template_processor.py @@ -133,12 +133,15 @@ class TemplateWrapper: def __new__(cls, *args, **kwargs): if not cls._protected_is_set: + print('protected is not set') # Устанавливаем значения PROTECTED, если не заданы. if 'chroot_path' in kwargs: chroot_path = kwargs['chroot_path'] else: chroot_path = '/' cls._set_protected(chroot_path) + else: + print('protected is already set') return super().__new__(cls) def __init__(self, target_file_path, @@ -522,10 +525,9 @@ class TemplateWrapper: @classmethod def _set_protected(cls, chroot_path): '''Метод для получения множества защищенных директорий.''' - if cls._protected_is_set: - return - cls._protected_set = set() + cls._unprotected_set = set() + cls._protected_set.add(join_paths(chroot_path, '/etc')) config_protect_env = os.environ.get('CONFIG_PROTECT', False) @@ -1195,6 +1197,10 @@ class TemplateExecutor: try: if os.path.exists(target_path): os.chown(target_path, chown_value['uid'], chown_value['gid']) + else: + raise TemplateExecutorError( + 'The target directory does not exist: {0}'. + format(target_path)) except (OSError, Exception) as error: if not self._check_os_error(error, target_path): raise TemplateExecutorError( @@ -1208,11 +1214,11 @@ class TemplateExecutor: '''Метод для смены прав доступа к директории.''' try: if os.path.exists(target_path): - print('directory exists') - print('chmod_value = {}'.format(oct(chmod_value))) os.chmod(target_path, chmod_value) else: - print('directory does not exist') + raise TemplateExecutorError( + 'The target directory does not exist: {0}'. + format(target_path)) except (OSError, Exception) as error: if not self._check_os_error(error, target_path): raise TemplateExecutorError( @@ -1224,6 +1230,10 @@ class TemplateExecutor: try: if os.path.exists(target_path): os.lchown(target_path, chown_value['uid'], chown_value['gid']) + else: + raise TemplateExecutorError( + 'The target file does not exist: {0}'. + format(target_path)) except (OSError, Exception) as error: if not self._check_os_error(error, target_path): raise TemplateExecutorError( @@ -1236,8 +1246,11 @@ class TemplateExecutor: def _chmod_file(self, target_path, chmod_value): '''Метод для смены прав доступа к директории.''' try: - if os.path.exists(target_path): - os.chmod(target_path, chmod_value) + if not os.path.exists(target_path): + raise TemplateExecutorError( + 'The target file does not exist: {0}'. + format(target_path)) + os.chmod(target_path, chmod_value) except (OSError, Exception) as error: if not self._check_os_error(error, target_path): raise TemplateExecutorError( @@ -1246,12 +1259,20 @@ class TemplateExecutor: def _get_file_mode(self, file_path): '''Метод для получения прав доступа для указанного файла.''' + if not os.path.exists(file_path): + raise TemplateExecutorError( + 'The file to get mode does not exist: {0}'. + format(file_path)) file_stat = os.stat(file_path) return stat.S_IMODE(file_stat.st_mode) def _get_file_owner(self, file_path): '''Метод для получения uid и gid значений для владельца указанного файла.''' + if not os.path.exists(file_path): + raise TemplateExecutorError( + 'The file to get owner does not exist: {0}'. + format(file_path)) file_stat = os.stat(file_path) return {'uid': file_stat.st_uid, 'gid': file_stat.st_gid} @@ -1265,7 +1286,7 @@ class TemplateExecutor: if self.chroot_path == '/': user_name = pwd.getpwuid(uid).pw_name else: - user_name = str(uid) + user_name = self._get_user_name_form_uid(uid) except (TypeError, KeyError): user_name = str(uid) @@ -1273,12 +1294,56 @@ class TemplateExecutor: if self.chroot_path == '/': group_name = grp.getgrgid(gid).gr_name else: - group_name = str(gid) + group_name = self._get_group_name_form_gid(gid) except (TypeError, KeyError): group_name = str(gid) return '{0}:{1}'.format(user_name, group_name) + def _get_user_name_form_uid(self, uid): + '''Метод для получения имени пользователя по его uid.''' + passwd_file_path = os.path.join(self.chroot_path, 'etc/passwd') + passwd_dictionary = dict() + if os.path.exists(passwd_file_path): + with open(passwd_file_path, 'r') as passwd_file: + for line in passwd_file: + if line.startswith('#'): + continue + + passwd_line = line.split(':') + line_uid = int(passwd_line[2]) + line_username = passwd_line[0] + + if line_uid and line_username: + passwd_dictionary[line_uid] = line_username + + if uid in passwd_dictionary: + return passwd_dictionary[uid] + else: + return str(uid) + + def _get_group_name_form_gid(self, gid): + '''Метод для получения названия группы по его gid.''' + group_file_path = os.path.join(self.chroot_path, 'etc/group') + group_dictionary = dict() + if os.path.exists(group_file_path): + with open(group_file_path, 'r') as group_file: + for line in group_file: + if line.startswith('#'): + continue + + group_line = line.split(':') + line_gid = int(group_line[2]) + line_group = group_line[0] + + if line_gid and line_group: + group_dictionary[line_gid] = line_group + + if gid in group_dictionary: + return group_dictionary[gid] + else: + return str(gid) + def _check_os_error(self, error, path_to_check): '''Метод для проверки причины, по которой не удалось изменить владельца или права доступа файла.''' diff --git a/calculate/utils/files.py b/calculate/utils/files.py index 276d2fa..6d5f5b2 100644 --- a/calculate/utils/files.py +++ b/calculate/utils/files.py @@ -425,7 +425,7 @@ def make_directory(directory_path, force=False): def check_directory_link(link_path, chroot_path='/'): - '''Метод для проверки наличия зацикливающихся ссылок и их корректности в + '''Функция для проверки наличия зацикливающихся ссылок и их корректности в целом. В случае успешной проверки возвращает целевой путь ссылки.''' link_target = read_link(link_path) link_target = get_target_from_link(link_path, link_target, diff --git a/tests/templates/test_parameters_processor.py b/tests/templates/test_parameters_processor.py index d819b72..74ca6f2 100644 --- a/tests/templates/test_parameters_processor.py +++ b/tests/templates/test_parameters_processor.py @@ -7,10 +7,12 @@ from calculate.templates.template_processor import TemplateExecutor from calculate.utils.files import join_paths -CHROOT_PATH = os.path.join(os.getcwd(), 'tests/templates/testfiles') +CHROOT_PATH = os.path.join( + os.getcwd(), + 'tests/templates/testfiles/test_parameters_processor_root') -parameters_processor = ParametersProcessor() +parameters_processor = ParametersProcessor(chroot_path=CHROOT_PATH) parameters_processor.available_appends = TemplateExecutor( cl_config_path=join_paths( CHROOT_PATH, @@ -49,38 +51,36 @@ class TestTemplateParameters: parameter_value, FILE, 1) parameters_processor.check_postparse_parameters() - assert parameters_object.append == 'join' except Exception as error: pytest.fail('Unexpected exception: {0}'. format(str(error))) + assert parameters_object.append == 'join' + def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_source_parameter__the_object_will_be_initialized_successfully(self): parameters = {'source': '/test_dir_1/file.test'} parameters_object = ParametersContainer() parameters_processor.set_parameters_container(parameters_object) - parameters_processor.chroot_path = CHROOT_PATH try: for parameter_name, parameter_value in parameters.items(): parameters_processor.check_template_parameter(parameter_name, parameter_value, FILE, 1) parameters_processor.check_postparse_parameters() - assert parameters_object.source == join_paths( - CHROOT_PATH, - '/test_dir_1/file.test') except Exception as error: pytest.fail('Unexpected exception: {0}'. format(str(error))) - finally: - parameters_processor.chroot_path = '/' + + assert parameters_object.source == join_paths( + CHROOT_PATH, + '/test_dir_1/file.test') def test_if_TemplateParameters_object_is_intialized_as_dir_parameters_object_using_correct_source_parameter_with_append_link__the_object_will_be_initialized_successfully(self): parameters = {'append': 'link', 'source': '/test_dir_1'} parameters_object = ParametersContainer() parameters_processor.set_parameters_container(parameters_object) - parameters_processor.chroot_path = CHROOT_PATH try: for parameter_name, parameter_value in parameters.items(): parameters_processor.check_template_parameter(parameter_name, @@ -88,13 +88,12 @@ class TestTemplateParameters: DIR, 1) parameters_processor.check_postparse_parameters() - assert parameters_processor.source == join_paths(CHROOT_PATH, - '/test_dir_1') except Exception as error: pytest.fail('Unexpected exception: {0}'. format(str(error))) - finally: - parameters_processor.chroot_path = '/' + + assert parameters_object.source == join_paths(CHROOT_PATH, + '/test_dir_1') def test_if_TemplateParameters_object_is_intialized_using_source_parameter_with_unexisting_file_path__the_initialization_of_the_object_will_be_failed(self): parameters = {'source': '/test_dir_1/unexisted_file.test'} @@ -112,7 +111,6 @@ class TestTemplateParameters: parameters = {'source': '/test_dir_1/file.test'} parameters_object = ParametersContainer() parameters_processor.set_parameters_container(parameters_object) - parameters_processor.chroot_path = CHROOT_PATH with pytest.raises(IncorrectParameter): for parameter_name, parameter_value in parameters.items(): @@ -125,7 +123,6 @@ class TestTemplateParameters: parameters = {'force': True} parameters_object = ParametersContainer() parameters_processor.set_parameters_container(parameters_object) - parameters_processor.chroot_path = '/' try: for parameter_name, parameter_value in parameters.items(): @@ -133,11 +130,12 @@ class TestTemplateParameters: parameter_value, DIR, 1) parameters_processor.check_postparse_parameters() - assert parameters_processor.force except Exception as error: pytest.fail('Unexpected exception: {0}'. format(str(error))) + assert parameters_object.force + def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_incorrect_force_parameter__the_initialization_of_the_object_will_be_failed(self): parameters = {'force': 'value'} parameters_object = ParametersContainer() @@ -161,11 +159,12 @@ class TestTemplateParameters: parameter_value, FILE, 1) parameters_processor.check_postparse_parameters() - assert parameters_processor.autoupdate except Exception as error: pytest.fail('Unexpected exception: {0}'. format(str(error))) + assert parameters_object.autoupdate + def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_incorrect_autoupdate_parameter__the_initialization_of_the_object_will_be_failed(self): parameters = {'autoupdate': 'value'} parameters_object = ParametersContainer() @@ -189,11 +188,29 @@ class TestTemplateParameters: parameter_value, FILE, 1) parameters_processor.check_postparse_parameters() - assert parameters_processor.chown == {'uid': 0, 'gid': 0} except Exception as error: pytest.fail('Unexpected exception: {0}'. format(str(error))) + assert parameters_object.chown == {'uid': 0, 'gid': 0} + + def test_if_TemplateParameters_object_is_initialized_using_dictionary_with_correct_chown_parameter_and_new_chroot_path__the_object_will_be_initialized_successfully(self): + parameters = {'chown': 'divanov:guest'} + parameters_object = ParametersContainer() + parameters_processor.set_parameters_container(parameters_object) + + try: + for parameter_name, parameter_value in parameters.items(): + parameters_processor.check_template_parameter(parameter_name, + parameter_value, + FILE, 1) + parameters_processor.check_postparse_parameters() + except Exception as error: + pytest.fail('Unexpected exception: {0}'. + format(str(error))) + + assert parameters_object.chown == {'uid': 666, 'gid': 1000} + def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chown_parameter_in_its_digital_form__the_object_will_be_initialized_successfully(self): uid = os.getuid() gid = os.getgid() @@ -207,11 +224,12 @@ class TestTemplateParameters: parameter_value, FILE, 1) parameters_processor.check_postparse_parameters() - assert parameters_processor.chown == {'uid': uid, 'gid': gid} except Exception as error: pytest.fail('Unexpected exception: {0}'. format(str(error))) + assert parameters_object.chown == {'uid': uid, 'gid': gid} + def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_incorrect_chown_parameter__the_initialization_of_the_object_will_be_failed(self): parameters = {'chown': 'wrong_user_name:wrong_group_name'} parameters_object = ParametersContainer() @@ -235,11 +253,12 @@ class TestTemplateParameters: parameter_value, FILE, 1) parameters_processor.check_postparse_parameters() - assert parameters_processor.chmod == 0o644 except Exception as error: pytest.fail('Unexpected exception: {0}'. format(str(error))) + assert parameters_object.chmod == 0o644 + def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chmod_parameter_in_its_digital_form__the_object_will_be_initialized_successfully(self): parameters = {'chmod': '600'} parameters_object = ParametersContainer() @@ -251,7 +270,8 @@ class TestTemplateParameters: parameter_value, FILE, 1) parameters_processor.check_postparse_parameters() - assert parameters_processor.chmod == 0o600 except Exception as error: pytest.fail('Unexpected exception: {0}'. format(str(error))) + + assert parameters_object.chmod == 0o600 diff --git a/tests/templates/test_template_executor.py b/tests/templates/test_template_executor.py index ade5503..10270d1 100644 --- a/tests/templates/test_template_executor.py +++ b/tests/templates/test_template_executor.py @@ -1,32 +1,42 @@ import pytest import os import stat +import grp +import getpass from calculate.templates.template_processor import TemplateExecutor, DIR,\ FILE, CalculateConfigFile,\ - TemplateExecutorError + TemplateExecutorError,\ + TemplateWrapper 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') -CL_CONFIG_PATH = os.path.join(CHROOT_PATH, 'var/lib/calculate/config') -CL_CONFIG_ARCHIVE_PATH = os.path.join(CHROOT_PATH, - 'var/lib/calculate/config-archive') -CL_EXECUTE_ARCHIVE_PATH = os.path.join(CHROOT_PATH, - 'var/lib/calculate/.execute') +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=CL_CONFIG_ARCHIVE_PATH, - cl_config_path=CL_CONFIG_PATH, - execute_archive_path=CL_EXECUTE_ARCHIVE_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')}) @pytest.mark.template_executor -class TestTemplateAction: +class TestTemplateExecutor: # Сначала протестируем класс для работы с /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( @@ -52,10 +62,11 @@ class TestTemplateAction: 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=CL_CONFIG_PATH, + cl_config_path=CONFIG_PATH, cl_chroot_path=CHROOT_PATH) md5_value = hashlib.md5(open(join_paths(CHROOT_PATH, '/etc/file'), @@ -67,7 +78,7 @@ class TestTemplateAction: 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=CL_CONFIG_PATH, + cl_config_path=CONFIG_PATH, cl_chroot_path=CHROOT_PATH) md5_value = hashlib.md5(open(join_paths(CHROOT_PATH, '/etc/file'), @@ -80,7 +91,7 @@ class TestTemplateAction: 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=CL_CONFIG_PATH, + cl_config_path=CONFIG_PATH, cl_chroot_path=CHROOT_PATH) md5_value = hashlib.md5(open(join_paths(CHROOT_PATH, '/etc/file'), @@ -91,7 +102,7 @@ class TestTemplateAction: 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=CL_CONFIG_PATH, + cl_config_path=CONFIG_PATH, cl_chroot_path=CHROOT_PATH) md5_value_1 = hashlib.md5(open(join_paths(CHROOT_PATH, '/etc/file'), @@ -105,7 +116,7 @@ class TestTemplateAction: 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=CL_CONFIG_PATH, + cl_config_path=CONFIG_PATH, cl_chroot_path=CHROOT_PATH) md5_value = hashlib.md5(open(join_paths(CHROOT_PATH, '/etc/file'), @@ -145,9 +156,9 @@ class TestTemplateAction: 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=CL_CONFIG_ARCHIVE_PATH, - cl_config_path=CL_CONFIG_PATH, - execute_archive_path=CL_EXECUTE_ARCHIVE_PATH) + cl_config_archive=CONFIG_ARCHIVE_PATH, + cl_config_path=CONFIG_PATH, + execute_archive_path=EXECUTE_ARCHIVE_PATH) assert template_executor.available_appends @@ -155,8 +166,27 @@ class TestTemplateAction: 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) + # Тестируем методы для работы непосредственно с файловой системой. - # Тестируем методы для chown и chmod. + # Тестируем методы для изменения владельца файла. 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( @@ -187,10 +217,11 @@ class TestTemplateAction: 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()} - template_executor._chown_directory(join_paths( - CHROOT_PATH, - '/etc/chown_testfiles/file_2'), - chown_value) + 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. @@ -209,7 +240,7 @@ class TestTemplateAction: '/etc/chown_testfiles/file_0')).\ st_gid == chown_value['gid'] - if os.getuid() == 0 and "SSH_connection" not in os.environ: + 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'])} @@ -226,15 +257,17 @@ class TestTemplateAction: 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()} - template_executor._chown_file(join_paths( + with pytest.raises(TemplateExecutorError): + template_executor._chown_file(join_paths( CHROOT_PATH, - '/etc/chown_testfiles/file_2'), - chown_value) + '/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( @@ -260,36 +293,201 @@ class TestTemplateAction: 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) - template_executor._chmod_directory(join_paths( - CHROOT_PATH, - '/etc/chown_testfiles/file_2'), - chmod_value) + 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(0o777) - template_executor._chmod_file(join_paths(CHROOT_PATH, - '/etc/chmod_testfiles/dir_0'), + 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/dir_0')).st_mode) + CHROOT_PATH, + '/etc/chmod_testfiles/file_0')).st_mode) assert result == chmod_value - chmod_value = int(0o755) - template_executor._chmod_file(join_paths(CHROOT_PATH, - '/etc/chmod_testfiles/dir_0'), + 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/dir_0')).st_mode) + 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 + + 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): + 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 + + 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): + 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 + + 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): + 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 + + 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): + with pytest.raises(TemplateExecutorError): + template_executor._get_file_mode(join_paths( + CHROOT_PATH, + '/etc/chmod_testfiles/file_1')) + # Тесты действий с директориями. - def test_create_directory(self): + 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/dir') + 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/dir') + 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) + 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 chown_value == template_executor._get_file_owner( + target_directory) + assert chmod_value == template_executor._get_file_mode( + 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(join_paths( + CHROOT_PATH, + '/etc/chown_testfiles/file_0'), + dir_owner) + + def test_if_the_create_directory_method_input_is_a_template_with_a_target_path_to_an_unexisting_directory_and_chown_and_chmod_parameters_is_not_set__the_method_creates(self): pass diff --git a/tests/templates/test_template_wrapper.py b/tests/templates/test_template_wrapper.py index cf5933c..e9194fb 100644 --- a/tests/templates/test_template_wrapper.py +++ b/tests/templates/test_template_wrapper.py @@ -13,7 +13,7 @@ import hashlib 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') + 'var/lib/calculate/config-archive') test_package_name = PackageAtomName( {'pkg_path': os.path.join( @@ -28,6 +28,8 @@ class TestTemplateWrapper: parameters_object = ParametersContainer({'package': test_package_name, 'append': 'join', 'format': 'samba'}) + TemplateWrapper._protected_is_set = False + template_wrapper = TemplateWrapper( join_paths(CHROOT_PATH, '/etc/dir/file.conf'), @@ -848,6 +850,8 @@ class TestTemplateWrapper: parameters_object, FILE, chroot_path=CHROOT_PATH, config_archive_path=CONFIG_ARCHIVE_PATH) + for protected_path in template_wrapper._protected_set: + print(protected_path) except Exception as error: pytest.fail("Unexpected exception: {}".format(str(error))) assert template_wrapper.input_path == source diff --git a/tests/templates/testfiles/test_dir_1/file.test b/tests/templates/testfiles/test_executor_root/etc/chmod_testfiles/file_2 similarity index 100% rename from tests/templates/testfiles/test_dir_1/file.test rename to tests/templates/testfiles/test_executor_root/etc/chmod_testfiles/file_2 diff --git a/tests/templates/testfiles/test_executor_root/etc/chown_testfiles/file_2 b/tests/templates/testfiles/test_executor_root/etc/chown_testfiles/file_2 old mode 100755 new mode 100644 diff --git a/tests/templates/testfiles/test_executor_root/etc/dir/dir_1/config.json b/tests/templates/testfiles/test_executor_root/etc/dir/dir_1/config.json deleted file mode 100644 index 7e271be..0000000 --- a/tests/templates/testfiles/test_executor_root/etc/dir/dir_1/config.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "languageserver": { - "clangd": { - "command": "clangd", - "rootPatterns": [ - "compile_flags.txt", - "compile_commands.json" - ], - "filetypes": [ - "c", - "cpp", - "objc", - "objcpp" - ] - } - } -} \ No newline at end of file diff --git a/tests/templates/testfiles/test_executor_root/etc/dir/file.conf b/tests/templates/testfiles/test_executor_root/etc/dir/file.conf deleted file mode 100644 index afd6900..0000000 --- a/tests/templates/testfiles/test_executor_root/etc/dir/file.conf +++ /dev/null @@ -1,5 +0,0 @@ -[section one] - parameter_1 = value - parameter_2 = value_2 -[section two] - other_parameter = other_value diff --git a/tests/templates/testfiles/test_executor_root/etc/dir/subdir/config.json b/tests/templates/testfiles/test_executor_root/etc/dir/subdir/config.json deleted file mode 100644 index 7e271be..0000000 --- a/tests/templates/testfiles/test_executor_root/etc/dir/subdir/config.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "languageserver": { - "clangd": { - "command": "clangd", - "rootPatterns": [ - "compile_flags.txt", - "compile_commands.json" - ], - "filetypes": [ - "c", - "cpp", - "objc", - "objcpp" - ] - } - } -} \ No newline at end of file diff --git a/tests/templates/testfiles/test_executor_root/etc/dir/subdir/file b/tests/templates/testfiles/test_executor_root/etc/dir/subdir/file deleted file mode 100644 index 71d6666..0000000 --- a/tests/templates/testfiles/test_executor_root/etc/dir/subdir/file +++ /dev/null @@ -1,6 +0,0 @@ -options { - parameter_1 no; - parameter_2 yes; - - user_change "blah"; -}; diff --git a/tests/templates/testfiles/test_executor_root/etc/group b/tests/templates/testfiles/test_executor_root/etc/group new file mode 100644 index 0000000..a81c003 --- /dev/null +++ b/tests/templates/testfiles/test_executor_root/etc/group @@ -0,0 +1,66 @@ +root::0:root +bin::1:root,bin,daemon +daemon::2:root,bin,daemon +sys::3:root,bin,adm +adm::4:root,adm,daemon +tty::5: +disk::6:root,adm,haldaemon +lp::7:lp,guest +mem::8: +kmem::9: +wheel::10:root,guest +floppy::11:root,haldaemon +mail::12:mail +news::13:news +uucp::14:uucp,guest +man::15:man +console::17: +audio::18:guest +cdrom::19:haldaemon,guest +dialout::20:root +tape::26:root +video::27:root,guest +cdrw::80:haldaemon,guest +usb::85:haldaemon,guest +users::100:games,guest +nofiles:x:200: +smmsp:x:209:smmsp +portage::250:portage +utmp:x:406: +nogroup::65533: +nobody::65534: +sshd:x:22: +games:x:35:guest +plugdev:x:440:haldaemon,usbmux,guest +scanner:x:441:guest +ldap:x:439: +messagebus:x:199: +lpadmin:x:106: +polkituser:x:105: +cron:x:16: +ntp:x:123: +rpc:x:111: +fingerprint:x:104: +ssmtp:x:103: +crontab:x:102: +gdm:x:101: +haldaemon:x:999:haldaemon +openvpn:x:998: +vnstat:x:997: +dnsmasq:x:996: +polkitd:x:995: +locate:x:994: +input:x:993: +dhcp:x:992: +mysql:x:60: +netdev:x:991: +avahi:x:990: +avahi-autoipd:x:989: +nm-openvpn:x:988: +deluge:x:987: +postgres:x:70: +nullmail:x:88: +sudo:x:443: +kvm:x:78: +render:x:28: +guest:!:1000: diff --git a/tests/templates/testfiles/test_executor_root/etc/passwd b/tests/templates/testfiles/test_executor_root/etc/passwd new file mode 100644 index 0000000..395d569 --- /dev/null +++ b/tests/templates/testfiles/test_executor_root/etc/passwd @@ -0,0 +1,42 @@ +root:x:0:0:root:/root:/bin/bash +bin:x:1:1:bin:/bin:/bin/false +daemon:x:2:2:daemon:/sbin:/bin/false +adm:x:3:4:adm:/var/adm:/bin/false +lp:x:4:7:lp:/var/spool/lpd:/bin/false +sync:x:5:0:sync:/sbin:/bin/sync +shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown +halt:x:7:0:halt:/sbin:/sbin/halt +mail:x:8:12:Mail program user:/var/spool/mail:/sbin/nologin +news:x:9:13:news:/usr/lib/news:/bin/false +uucp:x:10:14:uucp:/var/spool/uucppublic:/bin/false +operator:x:11:0:operator:/root:/bin/bash +man:x:13:15:man:/usr/share/man:/bin/false +postmaster:x:14:12:Postmaster user:/var/spool/mail:/sbin/nologin +portage:x:250:250:portage:/var/tmp/portage:/bin/false +nobody:x:65534:65534:nobody:/:/bin/false +sshd:x:22:22:added by portage for openssh:/var/empty:/sbin/nologin +ldap:x:439:439:added by portage for openldap:/usr/lib64/openldap:/sbin/nologin +messagebus:x:101:199:System user; messagebus:/dev/null:/sbin/nologin +polkituser:x:102:105:added by portage for polkit:/dev/null:/sbin/nologin +cron:x:16:16:added by portage for cronbase:/var/spool/cron:/sbin/nologin +ntp:x:123:123:added by portage for ntp:/dev/null:/sbin/nologin +rpc:x:111:111:added by portage for portmap:/dev/null:/sbin/nologin +gdm:x:103:101:added by portage for gdm:/var/lib/gdm:/sbin/nologin +haldaemon:x:104:999:added by portage for hal:/dev/null:/sbin/nologin +openvpn:x:105:998:added by portage for openvpn:/dev/null:/sbin/nologin +usbmux:x:106:85:added by portage for usbmuxd:/dev/null:/sbin/nologin +vnstat:x:107:997:added by portage for vnstat:/dev/null:/sbin/nologin +dnsmasq:x:108:996:added by portage for dnsmasq:/dev/null:/sbin/nologin +polkitd:x:109:995:added by portage for polkit:/var/lib/polkit-1:/sbin/nologin +saned:x:110:441:added by portage for sane-backends:/dev/null:/sbin/nologin +dhcp:x:112:992:added by portage for dhcp:/var/lib/dhcp:/sbin/nologin +mysql:x:60:60:added by portage for mysql:/dev/null:/sbin/nologin +avahi:x:113:990:added by portage for avahi:/dev/null:/sbin/nologin +avahi-autoipd:x:114:989:added by portage for avahi:/dev/null:/sbin/nologin +nm-openvpn:x:115:988:added by portage for networkmanager-openvpn:/dev/null:/sbin/nologin +games:x:36:35:added by portage for games-envd:/usr/games:/bin/bash +deluge:x:116:987:added by portage for deluge:/var/lib/deluge:/sbin/nologin +postgres:x:70:70:added by portage for postgresql:/var/lib/postgresql:/bin/sh +nullmail:x:88:88:added by portage for nullmailer:/var/nullmailer:/sbin/nologin +divanov:x:1427:1000::/home/divanov:/bin/bash +guest:x:1000:1000::/home/guest:/bin/bash diff --git a/tests/templates/testfiles/etc/dir/file.conf b/tests/templates/testfiles/test_parameters_processor_root/etc/dir/file.conf similarity index 100% rename from tests/templates/testfiles/etc/dir/file.conf rename to tests/templates/testfiles/test_parameters_processor_root/etc/dir/file.conf diff --git a/tests/templates/testfiles/test_parameters_processor_root/etc/group b/tests/templates/testfiles/test_parameters_processor_root/etc/group new file mode 100644 index 0000000..a81c003 --- /dev/null +++ b/tests/templates/testfiles/test_parameters_processor_root/etc/group @@ -0,0 +1,66 @@ +root::0:root +bin::1:root,bin,daemon +daemon::2:root,bin,daemon +sys::3:root,bin,adm +adm::4:root,adm,daemon +tty::5: +disk::6:root,adm,haldaemon +lp::7:lp,guest +mem::8: +kmem::9: +wheel::10:root,guest +floppy::11:root,haldaemon +mail::12:mail +news::13:news +uucp::14:uucp,guest +man::15:man +console::17: +audio::18:guest +cdrom::19:haldaemon,guest +dialout::20:root +tape::26:root +video::27:root,guest +cdrw::80:haldaemon,guest +usb::85:haldaemon,guest +users::100:games,guest +nofiles:x:200: +smmsp:x:209:smmsp +portage::250:portage +utmp:x:406: +nogroup::65533: +nobody::65534: +sshd:x:22: +games:x:35:guest +plugdev:x:440:haldaemon,usbmux,guest +scanner:x:441:guest +ldap:x:439: +messagebus:x:199: +lpadmin:x:106: +polkituser:x:105: +cron:x:16: +ntp:x:123: +rpc:x:111: +fingerprint:x:104: +ssmtp:x:103: +crontab:x:102: +gdm:x:101: +haldaemon:x:999:haldaemon +openvpn:x:998: +vnstat:x:997: +dnsmasq:x:996: +polkitd:x:995: +locate:x:994: +input:x:993: +dhcp:x:992: +mysql:x:60: +netdev:x:991: +avahi:x:990: +avahi-autoipd:x:989: +nm-openvpn:x:988: +deluge:x:987: +postgres:x:70: +nullmail:x:88: +sudo:x:443: +kvm:x:78: +render:x:28: +guest:!:1000: diff --git a/tests/templates/testfiles/test_parameters_processor_root/etc/passwd b/tests/templates/testfiles/test_parameters_processor_root/etc/passwd new file mode 100644 index 0000000..25b0df1 --- /dev/null +++ b/tests/templates/testfiles/test_parameters_processor_root/etc/passwd @@ -0,0 +1,42 @@ +root:x:0:0:root:/root:/bin/bash +bin:x:1:1:bin:/bin:/bin/false +daemon:x:2:2:daemon:/sbin:/bin/false +adm:x:3:4:adm:/var/adm:/bin/false +lp:x:4:7:lp:/var/spool/lpd:/bin/false +sync:x:5:0:sync:/sbin:/bin/sync +shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown +halt:x:7:0:halt:/sbin:/sbin/halt +mail:x:8:12:Mail program user:/var/spool/mail:/sbin/nologin +news:x:9:13:news:/usr/lib/news:/bin/false +uucp:x:10:14:uucp:/var/spool/uucppublic:/bin/false +operator:x:11:0:operator:/root:/bin/bash +man:x:13:15:man:/usr/share/man:/bin/false +postmaster:x:14:12:Postmaster user:/var/spool/mail:/sbin/nologin +portage:x:250:250:portage:/var/tmp/portage:/bin/false +nobody:x:65534:65534:nobody:/:/bin/false +sshd:x:22:22:added by portage for openssh:/var/empty:/sbin/nologin +ldap:x:439:439:added by portage for openldap:/usr/lib64/openldap:/sbin/nologin +messagebus:x:101:199:System user; messagebus:/dev/null:/sbin/nologin +polkituser:x:102:105:added by portage for polkit:/dev/null:/sbin/nologin +cron:x:16:16:added by portage for cronbase:/var/spool/cron:/sbin/nologin +ntp:x:123:123:added by portage for ntp:/dev/null:/sbin/nologin +rpc:x:111:111:added by portage for portmap:/dev/null:/sbin/nologin +gdm:x:103:101:added by portage for gdm:/var/lib/gdm:/sbin/nologin +haldaemon:x:104:999:added by portage for hal:/dev/null:/sbin/nologin +openvpn:x:105:998:added by portage for openvpn:/dev/null:/sbin/nologin +usbmux:x:106:85:added by portage for usbmuxd:/dev/null:/sbin/nologin +vnstat:x:107:997:added by portage for vnstat:/dev/null:/sbin/nologin +dnsmasq:x:108:996:added by portage for dnsmasq:/dev/null:/sbin/nologin +polkitd:x:109:995:added by portage for polkit:/var/lib/polkit-1:/sbin/nologin +saned:x:110:441:added by portage for sane-backends:/dev/null:/sbin/nologin +dhcp:x:112:992:added by portage for dhcp:/var/lib/dhcp:/sbin/nologin +mysql:x:60:60:added by portage for mysql:/dev/null:/sbin/nologin +avahi:x:113:990:added by portage for avahi:/dev/null:/sbin/nologin +avahi-autoipd:x:114:989:added by portage for avahi:/dev/null:/sbin/nologin +nm-openvpn:x:115:988:added by portage for networkmanager-openvpn:/dev/null:/sbin/nologin +games:x:36:35:added by portage for games-envd:/usr/games:/bin/bash +deluge:x:116:987:added by portage for deluge:/var/lib/deluge:/sbin/nologin +postgres:x:70:70:added by portage for postgresql:/var/lib/postgresql:/bin/sh +nullmail:x:88:88:added by portage for nullmailer:/var/nullmailer:/sbin/nologin +divanov:x:666:1000::/home/divanov:/bin/bash +guest:x:1000:1000::/home/guest:/bin/bash diff --git a/tests/templates/testfiles/test_executor_root/etc/chown_testfiles/file_1 b/tests/templates/testfiles/test_parameters_processor_root/test_dir_1/file.test similarity index 100% rename from tests/templates/testfiles/test_executor_root/etc/chown_testfiles/file_1 rename to tests/templates/testfiles/test_parameters_processor_root/test_dir_1/file.test diff --git a/tests/templates/testfiles/test_parameters_processor_root/test_root/var/lib/calculate/config b/tests/templates/testfiles/test_parameters_processor_root/test_root/var/lib/calculate/config new file mode 100644 index 0000000..e69de29