@ -49,6 +49,9 @@ class TestTemplateExecutor:
shutil . copytree ( os . path . join ( CHROOT_PATH , ' etc.backup ' ) ,
os . path . join ( CHROOT_PATH , ' etc ' ) ,
symlinks = True )
shutil . copytree ( os . path . join ( CHROOT_PATH , ' unprotected.backup ' ) ,
os . path . join ( CHROOT_PATH , ' unprotected ' ) ,
symlinks = True )
shutil . copytree ( os . path . join (
CHROOT_PATH ,
' var/lib/calculate/config-archive.backup ' ) ,
@ -1272,23 +1275,6 @@ class TestTemplateExecutor:
with open ( template_wrapper . output_path , ' r ' ) as output_file :
assert output_file . read ( ) == output_text
def test_add_to_contents ( self ) :
if False :
target_path = join_paths (
CHROOT_PATH ,
' /etc/append_join_file_testfiles/file_5 ' )
parameters_object = ParametersContainer (
{ ' package ' : test_package_name ,
' append ' : ' join ' } )
template_wrapper = TemplateWrapper (
target_path ,
parameters_object , FILE ,
chroot_path = CHROOT_PATH ,
config_archive_path = CONFIG_ARCHIVE_PATH )
template_wrapper . add_to_contents ( )
template_wrapper . save_changes ( )
assert True
def test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_and_its_hash_sum_matches_the_hash_from_a_CONTENTS_file__the_method_joins_an_input_file_with_a_template__changes_its_hash_in_the_CONTENTS__updates_config_archive ( self ) :
target_path = join_paths (
CHROOT_PATH ,
@ -1560,19 +1546,371 @@ class TestTemplateExecutor:
output_file_text = output_file . read ( )
assert output_file_text == output_text
def test_unprotected_for_file_without_changes ( self ) :
pass
def test_if_append_join_file_method_s_input_is_a_template_with_an_unprotected_target_path_to_an_existing_file_that_belongs_to_the_template_package__the_method_just_joins_a_template_to_a_target_file_without_updating_a_CONTENTS_file_and_creating_an_archive_file ( self ) :
target_path = join_paths (
CHROOT_PATH ,
' /unprotected/append_join_file_testfiles/file_0 ' )
def test_unprotected_for_file_with_changes ( self ) :
pass
parameters_object = ParametersContainer ( { ' package ' : test_package_name ,
' append ' : ' join ' ,
' format ' : ' bind ' } )
template_text = ' section-name { parameter-2 no; } '
output_text = \
' section-name { \n parameter-1 yes; \n parameter-2 no; \n }; \n '
template_wrapper = TemplateWrapper (
target_path ,
parameters_object , FILE ,
template_text = template_text ,
chroot_path = CHROOT_PATH ,
config_archive_path = CONFIG_ARCHIVE_PATH )
template_executor . _append_join_file ( template_wrapper )
assert not template_wrapper . protected
assert os . path . exists ( target_path )
assert not os . path . exists ( join_paths (
CONFIG_ARCHIVE_PATH ,
' /unprotected/append_join_file_testfiles/file_0 ' ) )
assert ' /unprotected/append_join_file_testfiles/file_0 ' \
in template_wrapper . target_package
with open ( template_wrapper . output_path , ' r ' ) as output_file :
output_file_text = output_file . read ( )
assert output_file_text == output_text
assert hashlib . md5 ( output_file_text . encode ( ) ) . hexdigest != \
template_wrapper . target_package . get_md5 ( target_path )
def test_unbound_for_file_without_changes ( self ) :
pass
def test_if_append_join_file_method_s_input_is_a_template_with_an_unprotected_target_path_to_an_existing_file_that_belongs_to_the_template_package_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file__the_method_just_joins_a_template_to_a_target_file_without_updating_a_package_CONTENTS_and_the_config_files_and_creating_an_archive_file ( self ) :
target_path = join_paths (
CHROOT_PATH ,
' /unprotected/append_join_file_testfiles/file_1 ' )
cfg_path_1 = os . path . join ( os . path . dirname ( target_path ) ,
' ._cfg0001_file_1 ' )
def test_unbound_for_file_with_changes ( self ) :
pass
parameters_object = ParametersContainer ( { ' package ' : test_package_name ,
' append ' : ' join ' ,
' format ' : ' bind ' } )
template_text = ' section-name { parameter-2 no; } '
output_text = \
' section-name { \n parameter-1 no; \n parameter-2 no; \n }; \n '
template_wrapper = TemplateWrapper (
target_path ,
parameters_object , FILE ,
template_text = template_text ,
chroot_path = CHROOT_PATH ,
config_archive_path = CONFIG_ARCHIVE_PATH )
template_executor . _append_join_file ( template_wrapper )
assert not template_wrapper . protected
assert os . path . exists ( target_path )
assert not os . path . exists ( cfg_path_1 )
assert not os . path . exists ( join_paths (
CONFIG_ARCHIVE_PATH ,
' /unprotected/append_join_file_testfiles/file_1 ' ) )
assert ' /unprotected/append_join_file_testfiles/file_1 ' \
not in template_executor . calculate_config_file
assert ' /unprotected/append_join_file_testfiles/file_1 ' \
in template_wrapper . target_package
with open ( template_wrapper . output_path , ' r ' ) as output_file :
output_file_text = output_file . read ( )
assert output_file_text == output_text
assert hashlib . md5 ( output_file_text . encode ( ) ) . hexdigest != \
template_wrapper . target_package . get_md5 ( target_path )
def test_if_append_join_file_method_s_input_is_a_template_with_an_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_and_the_unbound_parameter_is_set__the_method_joins_template_and_removes_a_target_file_path_from_a_package_CONTENTS_file ( self ) :
target_path = join_paths (
CHROOT_PATH ,
' /etc/append_join_file_testfiles/file_13 ' )
parameters_object = ParametersContainer ( { ' package ' : test_package_name ,
' append ' : ' join ' ,
' format ' : ' bind ' ,
' unbound ' : True } )
template_text = ' section-name { parameter-2 no; } '
output_text = \
' section-name { \n parameter-1 yes; \n parameter-2 no; \n }; \n '
template_wrapper = TemplateWrapper (
target_path ,
parameters_object , FILE ,
template_text = template_text ,
chroot_path = CHROOT_PATH ,
config_archive_path = CONFIG_ARCHIVE_PATH )
template_executor . _append_join_file ( template_wrapper )
assert os . path . exists ( target_path )
assert os . path . exists ( join_paths (
CONFIG_ARCHIVE_PATH ,
' /etc/append_join_file_testfiles/file_13 ' ) )
assert ' /etc/append_join_file_testfiles/file_13 ' \
not in template_wrapper . target_package
with open ( template_wrapper . output_path , ' r ' ) as output_file :
output_file_text = output_file . read ( )
assert output_file_text == output_text
def test_if_append_join_file_method_s_input_is_a_template_with_an_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_and_the_unbound_parameter_is_set_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file__the_method_joins_template__removes_a_target_file_path_from_a_package_CONTENTS_file ( self ) :
target_path = join_paths (
CHROOT_PATH ,
' /etc/append_join_file_testfiles/file_14 ' )
cfg_path_1 = os . path . join ( os . path . dirname ( target_path ) ,
' ._cfg0001_file_14 ' )
parameters_object = ParametersContainer ( { ' package ' : test_package_name ,
' append ' : ' join ' ,
' format ' : ' bind ' ,
' unbound ' : True } )
template_text = ' section-name { parameter-2 no; } '
output_text = \
' section-name { \n parameter-1 no; \n parameter-2 no; \n }; \n '
template_wrapper = TemplateWrapper (
target_path ,
parameters_object , FILE ,
template_text = template_text ,
chroot_path = CHROOT_PATH ,
config_archive_path = CONFIG_ARCHIVE_PATH )
template_executor . _append_join_file ( template_wrapper )
assert os . path . exists ( target_path )
assert not os . path . exists ( cfg_path_1 )
assert os . path . exists ( join_paths (
CONFIG_ARCHIVE_PATH ,
' /etc/append_join_file_testfiles/file_14 ' ) )
assert ' /etc/append_join_file_testfiles/file_14 ' \
not in template_wrapper . target_package
assert ' /etc/append_join_file_testfiles/file_14 ' \
not in template_executor . calculate_config_file
with open ( template_wrapper . output_path , ' r ' ) as output_file :
output_file_text = output_file . read ( )
assert output_file_text == output_text
def test_if_append_join_file_method_s_input_is_a_template_with_an_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_and_the_unbound_parameter_is_set_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file_and_there_are_some_cfg_file__the_method_joins_template__removes_a_target_file_path_from_a_package_CONTENTS_file_and_the_config_file ( self ) :
target_path = join_paths (
CHROOT_PATH ,
' /etc/append_join_file_testfiles/file_15 ' )
cfg_path_1 = os . path . join ( os . path . dirname ( target_path ) ,
' ._cfg0001_file_15 ' )
cfg_path_2 = os . path . join ( os . path . dirname ( target_path ) ,
' ._cfg0002_file_15 ' )
cfg_path_3 = os . path . join ( os . path . dirname ( target_path ) ,
' ._cfg0003_file_15 ' )
parameters_object = ParametersContainer ( { ' package ' : test_package_name ,
' append ' : ' join ' ,
' format ' : ' bind ' ,
' unbound ' : True } )
template_text = ' section-name { parameter-2 no; } '
output_text = \
' section-name { \n parameter-1 no; \n parameter-2 no; \n }; \n '
template_wrapper = TemplateWrapper (
target_path ,
parameters_object , FILE ,
template_text = template_text ,
chroot_path = CHROOT_PATH ,
config_archive_path = CONFIG_ARCHIVE_PATH )
template_executor . _append_join_file ( template_wrapper )
assert os . path . exists ( target_path )
assert not os . path . exists ( cfg_path_1 )
assert not os . path . exists ( cfg_path_2 )
assert not os . path . exists ( cfg_path_3 )
assert os . path . exists ( join_paths (
CONFIG_ARCHIVE_PATH ,
' /etc/append_join_file_testfiles/file_15 ' ) )
assert ' /etc/append_join_file_testfiles/file_15 ' \
not in template_wrapper . target_package
assert ' /etc/append_join_file_testfiles/file_15 ' \
not in template_executor . calculate_config_file
with open ( template_wrapper . output_path , ' r ' ) as output_file :
output_file_text = output_file . read ( )
assert output_file_text == output_text
def test_if_the_append_after_file_method_s_input_is_a_not_empty_template__the_template_s_text_and_sections_joins_after_the_text_of_the_target_file ( self ) :
target_path = join_paths (
CHROOT_PATH ,
' /etc/append_after_file_testfiles/file_0 ' )
parameters_object = ParametersContainer ( { ' package ' : test_package_name ,
' append ' : ' after ' ,
' format ' : ' bind ' } )
template_text = ' section-1 { parameter-2 no; } section-2 { parameter-1 10; } '
output_text = \
' section-1 { \n parameter-1 yes; \n parameter-2 no; \n }; \n \n section-2 { \n parameter-1 10; \n }; \n '
template_wrapper = TemplateWrapper (
target_path ,
parameters_object , FILE ,
template_text = template_text ,
chroot_path = CHROOT_PATH ,
config_archive_path = CONFIG_ARCHIVE_PATH )
template_executor . _append_after_file ( template_wrapper )
assert os . path . exists ( target_path )
assert ' /etc/append_after_file_testfiles/file_0 ' \
in template_wrapper . target_package
with open ( template_wrapper . output_path , ' r ' ) as output_file :
output_file_text = output_file . read ( )
assert output_file_text == output_text
def test_if_the_append_before_file_method_s_input_is_a_not_empty_template__the_template_s_text_and_sections_joins_before_the_text_of_the_target_file ( self ) :
target_path = join_paths (
CHROOT_PATH ,
' /etc/append_before_file_testfiles/file_0 ' )
parameters_object = ParametersContainer ( { ' package ' : test_package_name ,
' append ' : ' before ' ,
' format ' : ' bind ' } )
template_text = ' section-1 { parameter-1 no; } section-2 { parameter-2 10; } '
output_text = \
' section-1 { \n parameter-1 no; \n }; \n \n section-2 { \n parameter-1 yes; \n parameter-2 10; \n }; \n '
template_wrapper = TemplateWrapper (
target_path ,
parameters_object , FILE ,
template_text = template_text ,
chroot_path = CHROOT_PATH ,
config_archive_path = CONFIG_ARCHIVE_PATH )
template_executor . _append_before_file ( template_wrapper )
assert os . path . exists ( target_path )
assert ' /etc/append_after_file_testfiles/file_0 ' \
in template_wrapper . target_package
with open ( template_wrapper . output_path , ' r ' ) as output_file :
output_file_text = output_file . read ( )
print ( ' output text: \n {} \n ' . format ( output_file_text ) )
assert output_file_text == output_text
def test_if_the_append_replace_file_method_s_input_is_a_not_empty_template_with_a_target_path_to_an_existing_file__the_method_joins_a_template_with_the_empty_text_and_replaces_the_target_file_with_the_template_join_result ( self ) :
target_path = join_paths (
CHROOT_PATH ,
' /etc/append_replace_file_testfiles/file_0 ' )
parameters_object = ParametersContainer ( { ' package ' : test_package_name ,
' append ' : ' replace ' ,
' format ' : ' bind ' } )
template_text = ' section-1 { parameter-1 no; }; section-2 { parameter-1 10; } '
output_text = \
' section-1 { \n parameter-1 no; \n }; \n \n section-2 { \n parameter-1 10; \n }; \n '
template_wrapper = TemplateWrapper (
target_path ,
parameters_object , FILE ,
template_text = template_text ,
chroot_path = CHROOT_PATH ,
config_archive_path = CONFIG_ARCHIVE_PATH )
template_executor . _append_replace_file ( template_wrapper )
assert os . path . exists ( target_path )
assert ' /etc/append_after_file_testfiles/file_0 ' \
in template_wrapper . target_package
with open ( template_wrapper . output_path , ' r ' ) as output_file :
output_file_text = output_file . read ( )
output_md5 = hashlib . md5 ( output_file_text . encode ( ) ) . hexdigest ( )
print ( ' output text: \n {} \n ' . format ( output_file_text ) )
assert output_file_text == output_text
assert template_wrapper . target_package . get_md5 ( target_path ) == \
output_md5
def test_if_the_append_remove_file_method_s_input_is_a_template_with_a_target_path_to_an_existing_file_that_belongs_to_the_template_package__the_method_removes_a_target_file_in_a_filesystem_and_in_a_package_CONTENTS_file ( self ) :
target_path = join_paths ( CHROOT_PATH ,
' /etc/append_remove_file_testfiles/file_0 ' )
parameters_object = ParametersContainer ( { ' package ' : test_package_name ,
' append ' : ' remove ' } )
template_wrapper = TemplateWrapper (
target_path ,
parameters_object , FILE ,
chroot_path = CHROOT_PATH ,
config_archive_path = CONFIG_ARCHIVE_PATH )
template_executor . _append_remove_file ( template_wrapper )
assert not os . path . exists ( target_path )
assert ' /etc/append_remove_file_testfiles/file_0 ' \
not in template_wrapper . target_package
def test_if_the_append_remove_file_method_s_input_is_a_template_with_a_target_path_to_an_unexisting_file_that_belongs_to_the_template_package__the_method_removes_a_target_file_in_a_package_CONTENTS_file ( self ) :
target_path = join_paths ( CHROOT_PATH ,
' /etc/append_remove_file_testfiles/file_1 ' )
parameters_object = ParametersContainer ( { ' package ' : test_package_name ,
' append ' : ' remove ' } )
template_wrapper = TemplateWrapper (
target_path ,
parameters_object , FILE ,
chroot_path = CHROOT_PATH ,
config_archive_path = CONFIG_ARCHIVE_PATH )
template_executor . _append_remove_file ( template_wrapper )
assert ' /etc/append_remove_file_testfiles/file_1 ' \
not in template_wrapper . target_package
def test_if_the_append_remove_file_method_s_input_is_a_template_with_a_target_path_to_an_existing_file_that_does_not_belong_to_any_package__the_method_removes_a_target_file_in_a_package_CONTENTS_file ( self ) :
target_path = join_paths ( CHROOT_PATH ,
' /etc/append_remove_file_testfiles/file_2 ' )
parameters_object = ParametersContainer ( { ' package ' : test_package_name ,
' append ' : ' remove ' } )
template_wrapper = TemplateWrapper (
target_path ,
parameters_object , FILE ,
chroot_path = CHROOT_PATH ,
config_archive_path = CONFIG_ARCHIVE_PATH )
template_executor . _append_remove_file ( template_wrapper )
assert not os . path . exists ( target_path )
assert ' /etc/append_remove_file_testfiles/file_2 ' \
not in template_wrapper . target_package
def test_if_the_append_clear_file_method_s_input_is_a_template_with_a_target_path_to_an_existing_empty_file_that_belongs_to_the_template_package__the_method_just_updates_a_package_CONTENTS_file ( self ) :
target_path = join_paths (
CHROOT_PATH ,
' /etc/append_clear_file_testfiles/file_0 ' )
parameters_object = ParametersContainer ( { ' package ' : test_package_name ,
' append ' : ' clear ' } )
template_wrapper = TemplateWrapper (
target_path ,
parameters_object , FILE ,
chroot_path = CHROOT_PATH ,
config_archive_path = CONFIG_ARCHIVE_PATH )
template_executor . _append_clear_file ( template_wrapper )
with open ( template_wrapper . output_path , ' r ' ) as output_file :
output_file_text = output_file . read ( )
assert not output_file_text
assert template_wrapper . target_package . get_md5 ( target_path ) == \
hashlib . md5 ( ' ' . encode ( ) ) . hexdigest ( )
def test_if_the_append_clear_file_method_s_input_is_a_template_with_a_target_path_to_an_existing_not_empty_file_that_belongs_to_the_template_package__the_method_clears_a_target_file_and_updates_a_package_CONTENTS_file ( self ) :
target_path = join_paths (
CHROOT_PATH ,
' /etc/append_clear_file_testfiles/file_1 ' )
parameters_object = ParametersContainer ( { ' package ' : test_package_name ,
' append ' : ' clear ' } )
template_wrapper = TemplateWrapper (
target_path ,
parameters_object , FILE ,
chroot_path = CHROOT_PATH ,
config_archive_path = CONFIG_ARCHIVE_PATH )
template_executor . _append_clear_file ( template_wrapper )
with open ( template_wrapper . output_path , ' r ' ) as output_file :
output_file_text = output_file . read ( )
assert not output_file_text
assert template_wrapper . target_package . get_md5 ( target_path ) == \
hashlib . md5 ( ' ' . encode ( ) ) . hexdigest ( )
def test_if_the_append_clear_file_method_s_input_is_a_template_with_a_target_path_to_an_existing_not_empty_file_that_belongs_to_the_template_package_and_the_chown_and_chmod_parameters_are_set__the_method_clears_a_target_file_and_updates_a_package_CONTENTS_file ( self ) :
target_path = join_paths (
CHROOT_PATH ,
' /etc/append_clear_file_testfiles/file_2 ' )
chown_value = { ' uid ' : os . getuid ( ) , ' gid ' : os . getgid ( ) }
chmod_value = int ( 0o777 )
parameters_object = ParametersContainer ( { ' package ' : test_package_name ,
' append ' : ' clear ' ,
' chown ' : chown_value ,
' chmod ' : chmod_value } )
template_wrapper = TemplateWrapper (
target_path ,
parameters_object , FILE ,
chroot_path = CHROOT_PATH ,
config_archive_path = CONFIG_ARCHIVE_PATH )
template_executor . _append_clear_file ( template_wrapper )
with open ( template_wrapper . output_path , ' r ' ) as output_file :
output_file_text = output_file . read ( )
assert not output_file_text
assert template_wrapper . target_package . get_md5 ( target_path ) == \
hashlib . md5 ( ' ' . encode ( ) ) . hexdigest ( )
assert template_executor . _get_file_owner ( target_path ) == \
chown_value
assert template_executor . _get_file_mode ( target_path ) == \
chmod_value
def test_to_remove_changed_testfiles ( self ) :
shutil . rmtree ( os . path . join ( CHROOT_PATH , ' etc ' ) )
shutil . rmtree ( os . path . join ( CHROOT_PATH , ' unprotected ' ) )
shutil . rmtree ( os . path . join ( CHROOT_PATH ,
' var/lib/calculate/config-archive ' ) )