Updated existing tests to use new parameters

Signed-off-by: Chirag Aggarwal <thechiragaggarwal@gmail.com>
This commit is contained in:
Chirag Aggarwal 2023-04-24 20:24:41 +05:30
parent 1ee56805f1
commit 96aca4f446
4 changed files with 65 additions and 48 deletions

View file

@ -34,7 +34,7 @@ def mount_archive(
+ flags.make_flags_from_arguments( + flags.make_flags_from_arguments(
mount_arguments, mount_arguments,
excludes=('repository', 'archive', 'mount_point', 'path', 'options'), excludes=('repository', 'archive', 'mount_point', 'paths', 'options'),
) )
+ (('-o', mount_arguments.options) if mount_arguments.options else ()) + (('-o', mount_arguments.options) if mount_arguments.options else ())

View file

@ -78,10 +78,12 @@ def prune_archives(
+ flags.make_flags_from_arguments( + flags.make_flags_from_arguments(
prune_arguments, prune_arguments,
excludes=('repository', 'stats'), excludes=('repository', 'stats', 'list_archives'),
) )
+ (('--list',) if prune_arguments.list_archives else ())
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ()) + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
+ (('--dry-run',) if dry_run else ())
+ (tuple(extra_borg_options.split(' ')) if extra_borg_options else ()) + (tuple(extra_borg_options.split(' ')) if extra_borg_options else ())
+ flags.make_repository_flags(repository_path, local_borg_version) + flags.make_repository_flags(repository_path, local_borg_version)

View file

@ -21,13 +21,11 @@ def test_mount_archive_calls_borg_with_required_flags():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',)) flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg', 'mount', 'repo', '/mnt')) insert_execute_command_mock(('borg', 'mount', 'repo', '/mnt'))
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
module.mount_archive( module.mount_archive(
repository_path='repo', repository_path='repo',
archive=None, archive=None,
mount_point='/mnt', mount_arguments=mount_arguments,
paths=None,
foreground=False,
options=None,
storage_config={}, storage_config={},
local_borg_version='1.2.3', local_borg_version='1.2.3',
) )
@ -45,13 +43,11 @@ def test_mount_archive_with_borg_features_calls_borg_with_repository_and_match_a
('borg', 'mount', '--repo', 'repo', '--match-archives', 'archive', '/mnt') ('borg', 'mount', '--repo', 'repo', '--match-archives', 'archive', '/mnt')
) )
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
module.mount_archive( module.mount_archive(
repository_path='repo', repository_path='repo',
archive='archive', archive='archive',
mount_point='/mnt', mount_arguments=mount_arguments,
paths=None,
foreground=False,
options=None,
storage_config={}, storage_config={},
local_borg_version='1.2.3', local_borg_version='1.2.3',
) )
@ -64,13 +60,11 @@ def test_mount_archive_without_archive_calls_borg_with_repository_flags_only():
) )
insert_execute_command_mock(('borg', 'mount', 'repo::archive', '/mnt')) insert_execute_command_mock(('borg', 'mount', 'repo::archive', '/mnt'))
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
module.mount_archive( module.mount_archive(
repository_path='repo', repository_path='repo',
archive='archive', archive='archive',
mount_point='/mnt', mount_arguments=mount_arguments,
paths=None,
foreground=False,
options=None,
storage_config={}, storage_config={},
local_borg_version='1.2.3', local_borg_version='1.2.3',
) )
@ -83,13 +77,11 @@ def test_mount_archive_calls_borg_with_path_flags():
) )
insert_execute_command_mock(('borg', 'mount', 'repo::archive', '/mnt', 'path1', 'path2')) insert_execute_command_mock(('borg', 'mount', 'repo::archive', '/mnt', 'path1', 'path2'))
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=['path1', 'path2'], foreground=False)
module.mount_archive( module.mount_archive(
repository_path='repo', repository_path='repo',
archive='archive', archive='archive',
mount_point='/mnt', mount_arguments=mount_arguments,
paths=['path1', 'path2'],
foreground=False,
options=None,
storage_config={}, storage_config={},
local_borg_version='1.2.3', local_borg_version='1.2.3',
) )
@ -104,13 +96,11 @@ def test_mount_archive_calls_borg_with_remote_path_flags():
('borg', 'mount', '--remote-path', 'borg1', 'repo::archive', '/mnt') ('borg', 'mount', '--remote-path', 'borg1', 'repo::archive', '/mnt')
) )
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
module.mount_archive( module.mount_archive(
repository_path='repo', repository_path='repo',
archive='archive', archive='archive',
mount_point='/mnt', mount_arguments=mount_arguments,
paths=None,
foreground=False,
options=None,
storage_config={}, storage_config={},
local_borg_version='1.2.3', local_borg_version='1.2.3',
remote_path='borg1', remote_path='borg1',
@ -124,13 +114,11 @@ def test_mount_archive_calls_borg_with_umask_flags():
) )
insert_execute_command_mock(('borg', 'mount', '--umask', '0770', 'repo::archive', '/mnt')) insert_execute_command_mock(('borg', 'mount', '--umask', '0770', 'repo::archive', '/mnt'))
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
module.mount_archive( module.mount_archive(
repository_path='repo', repository_path='repo',
archive='archive', archive='archive',
mount_point='/mnt', mount_arguments=mount_arguments,
paths=None,
foreground=False,
options=None,
storage_config={'umask': '0770'}, storage_config={'umask': '0770'},
local_borg_version='1.2.3', local_borg_version='1.2.3',
) )
@ -143,13 +131,11 @@ def test_mount_archive_calls_borg_with_lock_wait_flags():
) )
insert_execute_command_mock(('borg', 'mount', '--lock-wait', '5', 'repo::archive', '/mnt')) insert_execute_command_mock(('borg', 'mount', '--lock-wait', '5', 'repo::archive', '/mnt'))
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
module.mount_archive( module.mount_archive(
repository_path='repo', repository_path='repo',
archive='archive', archive='archive',
mount_point='/mnt', mount_arguments=mount_arguments,
paths=None,
foreground=False,
options=None,
storage_config={'lock_wait': '5'}, storage_config={'lock_wait': '5'},
local_borg_version='1.2.3', local_borg_version='1.2.3',
) )
@ -163,13 +149,11 @@ def test_mount_archive_with_log_info_calls_borg_with_info_parameter():
insert_execute_command_mock(('borg', 'mount', '--info', 'repo::archive', '/mnt')) insert_execute_command_mock(('borg', 'mount', '--info', 'repo::archive', '/mnt'))
insert_logging_mock(logging.INFO) insert_logging_mock(logging.INFO)
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
module.mount_archive( module.mount_archive(
repository_path='repo', repository_path='repo',
archive='archive', archive='archive',
mount_point='/mnt', mount_arguments=mount_arguments,
paths=None,
foreground=False,
options=None,
storage_config={}, storage_config={},
local_borg_version='1.2.3', local_borg_version='1.2.3',
) )
@ -183,13 +167,11 @@ def test_mount_archive_with_log_debug_calls_borg_with_debug_flags():
insert_execute_command_mock(('borg', 'mount', '--debug', '--show-rc', 'repo::archive', '/mnt')) insert_execute_command_mock(('borg', 'mount', '--debug', '--show-rc', 'repo::archive', '/mnt'))
insert_logging_mock(logging.DEBUG) insert_logging_mock(logging.DEBUG)
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
module.mount_archive( module.mount_archive(
repository_path='repo', repository_path='repo',
archive='archive', archive='archive',
mount_point='/mnt', mount_arguments=mount_arguments,
paths=None,
foreground=False,
options=None,
storage_config={}, storage_config={},
local_borg_version='1.2.3', local_borg_version='1.2.3',
) )
@ -208,13 +190,11 @@ def test_mount_archive_calls_borg_with_foreground_parameter():
extra_environment=None, extra_environment=None,
).once() ).once()
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=True)
module.mount_archive( module.mount_archive(
repository_path='repo', repository_path='repo',
archive='archive', archive='archive',
mount_point='/mnt', mount_arguments=mount_arguments,
paths=None,
foreground=True,
options=None,
storage_config={}, storage_config={},
local_borg_version='1.2.3', local_borg_version='1.2.3',
) )
@ -227,13 +207,11 @@ def test_mount_archive_calls_borg_with_options_flags():
) )
insert_execute_command_mock(('borg', 'mount', '-o', 'super_mount', 'repo::archive', '/mnt')) insert_execute_command_mock(('borg', 'mount', '-o', 'super_mount', 'repo::archive', '/mnt'))
mount_arguments = flexmock(mount_point='/mnt', options='super_mount', paths=None, foreground=False)
module.mount_archive( module.mount_archive(
repository_path='repo', repository_path='repo',
archive='archive', archive='archive',
mount_point='/mnt', mount_arguments=mount_arguments,
paths=None,
foreground=False,
options='super_mount',
storage_config={}, storage_config={},
local_borg_version='1.2.3', local_borg_version='1.2.3',
) )

View file

@ -117,12 +117,14 @@ def test_prune_archives_calls_borg_with_parameters():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',)) flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(PRUNE_COMMAND + ('repo',), logging.INFO) insert_execute_command_mock(PRUNE_COMMAND + ('repo',), logging.INFO)
prune_arguments = flexmock(stats=False, list_archives=False)
module.prune_archives( module.prune_archives(
dry_run=False, dry_run=False,
repository_path='repo', repository_path='repo',
storage_config={}, storage_config={},
retention_config=flexmock(), retention_config=flexmock(),
local_borg_version='1.2.3', local_borg_version='1.2.3',
prune_arguments=prune_arguments,
) )
@ -134,12 +136,14 @@ def test_prune_archives_with_log_info_calls_borg_with_info_parameter():
insert_execute_command_mock(PRUNE_COMMAND + ('--info', 'repo'), logging.INFO) insert_execute_command_mock(PRUNE_COMMAND + ('--info', 'repo'), logging.INFO)
insert_logging_mock(logging.INFO) insert_logging_mock(logging.INFO)
prune_arguments = flexmock(stats=False, list_archives=False)
module.prune_archives( module.prune_archives(
repository_path='repo', repository_path='repo',
storage_config={}, storage_config={},
dry_run=False, dry_run=False,
retention_config=flexmock(), retention_config=flexmock(),
local_borg_version='1.2.3', local_borg_version='1.2.3',
prune_arguments=prune_arguments,
) )
@ -151,15 +155,34 @@ def test_prune_archives_with_log_debug_calls_borg_with_debug_parameter():
insert_execute_command_mock(PRUNE_COMMAND + ('--debug', '--show-rc', 'repo'), logging.INFO) insert_execute_command_mock(PRUNE_COMMAND + ('--debug', '--show-rc', 'repo'), logging.INFO)
insert_logging_mock(logging.DEBUG) insert_logging_mock(logging.DEBUG)
prune_arguments = flexmock(stats=False, list_archives=False)
module.prune_archives( module.prune_archives(
repository_path='repo', repository_path='repo',
storage_config={}, storage_config={},
dry_run=False, dry_run=False,
retention_config=flexmock(), retention_config=flexmock(),
local_borg_version='1.2.3', local_borg_version='1.2.3',
prune_arguments=prune_arguments,
) )
# def test_prune_archives_with_dry_run_calls_borg_with_dry_run_parameter():
# flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
# flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
# flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
# flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
# insert_execute_command_mock(PRUNE_COMMAND + ('--dry-run', 'repo'), logging.INFO)
# prune_arguments = flexmock(stats=False, list_archives=False)
# module.prune_archives(
# repository_path='repo',
# storage_config={},
# dry_run=True,
# retention_config=flexmock(),
# local_borg_version='1.2.3',
# prune_arguments=prune_arguments,
# )
def test_prune_archives_with_dry_run_calls_borg_with_dry_run_parameter(): def test_prune_archives_with_dry_run_calls_borg_with_dry_run_parameter():
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels') flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
@ -167,12 +190,14 @@ def test_prune_archives_with_dry_run_calls_borg_with_dry_run_parameter():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',)) flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(PRUNE_COMMAND + ('--dry-run', 'repo'), logging.INFO) insert_execute_command_mock(PRUNE_COMMAND + ('--dry-run', 'repo'), logging.INFO)
prune_arguments = flexmock(stats=False, list_archives=False)
module.prune_archives( module.prune_archives(
repository_path='repo', repository_path='repo',
storage_config={}, storage_config={},
dry_run=True, dry_run=True,
retention_config=flexmock(), retention_config=flexmock(),
local_borg_version='1.2.3', local_borg_version='1.2.3',
prune_arguments=prune_arguments,
) )
@ -183,6 +208,7 @@ def test_prune_archives_with_local_path_calls_borg_via_local_path():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',)) flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg1',) + PRUNE_COMMAND[1:] + ('repo',), logging.INFO) insert_execute_command_mock(('borg1',) + PRUNE_COMMAND[1:] + ('repo',), logging.INFO)
prune_arguments = flexmock(stats=False, list_archives=False)
module.prune_archives( module.prune_archives(
dry_run=False, dry_run=False,
repository_path='repo', repository_path='repo',
@ -190,6 +216,7 @@ def test_prune_archives_with_local_path_calls_borg_via_local_path():
retention_config=flexmock(), retention_config=flexmock(),
local_borg_version='1.2.3', local_borg_version='1.2.3',
local_path='borg1', local_path='borg1',
prune_arguments=prune_arguments,
) )
@ -200,6 +227,7 @@ def test_prune_archives_with_remote_path_calls_borg_with_remote_path_parameters(
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',)) flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(PRUNE_COMMAND + ('--remote-path', 'borg1', 'repo'), logging.INFO) insert_execute_command_mock(PRUNE_COMMAND + ('--remote-path', 'borg1', 'repo'), logging.INFO)
prune_arguments = flexmock(stats=False, list_archives=False)
module.prune_archives( module.prune_archives(
dry_run=False, dry_run=False,
repository_path='repo', repository_path='repo',
@ -207,6 +235,7 @@ def test_prune_archives_with_remote_path_calls_borg_with_remote_path_parameters(
retention_config=flexmock(), retention_config=flexmock(),
local_borg_version='1.2.3', local_borg_version='1.2.3',
remote_path='borg1', remote_path='borg1',
prune_arguments=prune_arguments,
) )
@ -217,13 +246,14 @@ def test_prune_archives_with_stats_calls_borg_with_stats_parameter_and_answer_ou
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',)) flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(PRUNE_COMMAND + ('--stats', 'repo'), module.borgmatic.logger.ANSWER) insert_execute_command_mock(PRUNE_COMMAND + ('--stats', 'repo'), module.borgmatic.logger.ANSWER)
prune_arguments = flexmock(stats=True, list_archives=False)
module.prune_archives( module.prune_archives(
dry_run=False, dry_run=False,
repository_path='repo', repository_path='repo',
storage_config={}, storage_config={},
retention_config=flexmock(), retention_config=flexmock(),
local_borg_version='1.2.3', local_borg_version='1.2.3',
stats=True, prune_arguments=prune_arguments,
) )
@ -234,13 +264,14 @@ def test_prune_archives_with_files_calls_borg_with_list_parameter_and_answer_out
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',)) flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(PRUNE_COMMAND + ('--list', 'repo'), module.borgmatic.logger.ANSWER) insert_execute_command_mock(PRUNE_COMMAND + ('--list', 'repo'), module.borgmatic.logger.ANSWER)
prune_arguments = flexmock(stats=False, list_archives=True)
module.prune_archives( module.prune_archives(
dry_run=False, dry_run=False,
repository_path='repo', repository_path='repo',
storage_config={}, storage_config={},
retention_config=flexmock(), retention_config=flexmock(),
local_borg_version='1.2.3', local_borg_version='1.2.3',
list_archives=True, prune_arguments=prune_arguments,
) )
@ -252,12 +283,14 @@ def test_prune_archives_with_umask_calls_borg_with_umask_parameters():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',)) flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(PRUNE_COMMAND + ('--umask', '077', 'repo'), logging.INFO) insert_execute_command_mock(PRUNE_COMMAND + ('--umask', '077', 'repo'), logging.INFO)
prune_arguments = flexmock(stats=False, list_archives=False)
module.prune_archives( module.prune_archives(
dry_run=False, dry_run=False,
repository_path='repo', repository_path='repo',
storage_config=storage_config, storage_config=storage_config,
retention_config=flexmock(), retention_config=flexmock(),
local_borg_version='1.2.3', local_borg_version='1.2.3',
prune_arguments=prune_arguments,
) )
@ -269,12 +302,14 @@ def test_prune_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',)) flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(PRUNE_COMMAND + ('--lock-wait', '5', 'repo'), logging.INFO) insert_execute_command_mock(PRUNE_COMMAND + ('--lock-wait', '5', 'repo'), logging.INFO)
prune_arguments = flexmock(stats=False, list_archives=False)
module.prune_archives( module.prune_archives(
dry_run=False, dry_run=False,
repository_path='repo', repository_path='repo',
storage_config=storage_config, storage_config=storage_config,
retention_config=flexmock(), retention_config=flexmock(),
local_borg_version='1.2.3', local_borg_version='1.2.3',
prune_arguments=prune_arguments,
) )
@ -285,10 +320,12 @@ def test_prune_archives_with_extra_borg_options_calls_borg_with_extra_options():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',)) flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(PRUNE_COMMAND + ('--extra', '--options', 'repo'), logging.INFO) insert_execute_command_mock(PRUNE_COMMAND + ('--extra', '--options', 'repo'), logging.INFO)
prune_arguments = flexmock(stats=False, list_archives=False)
module.prune_archives( module.prune_archives(
dry_run=False, dry_run=False,
repository_path='repo', repository_path='repo',
storage_config={'extra_borg_options': {'prune': '--extra --options'}}, storage_config={'extra_borg_options': {'prune': '--extra --options'}},
retention_config=flexmock(), retention_config=flexmock(),
local_borg_version='1.2.3', local_borg_version='1.2.3',
prune_arguments=prune_arguments,
) )