| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396 | 
							- import logging
 
- from flexmock import flexmock
 
- from borgmatic.borg import repo_delete as module
 
- from ..test_verbosity import insert_logging_mock
 
- def test_make_repo_delete_command_with_feature_available_runs_borg_repo_delete():
 
-     flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
 
-         ('repo',)
 
-     )
 
-     command = module.make_repo_delete_command(
 
-         repository={'path': 'repo'},
 
-         config={},
 
-         local_borg_version='1.2.3',
 
-         repo_delete_arguments=flexmock(list_archives=False, force=0),
 
-         global_arguments=flexmock(dry_run=False, log_json=False),
 
-         local_path='borg',
 
-         remote_path=None,
 
-     )
 
-     assert command == ('borg', 'repo-delete', 'repo')
 
- def test_make_repo_delete_command_without_feature_available_runs_borg_delete():
 
-     flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(False)
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
 
-         ('repo',)
 
-     )
 
-     command = module.make_repo_delete_command(
 
-         repository={'path': 'repo'},
 
-         config={},
 
-         local_borg_version='1.2.3',
 
-         repo_delete_arguments=flexmock(list_archives=False, force=0),
 
-         global_arguments=flexmock(dry_run=False, log_json=False),
 
-         local_path='borg',
 
-         remote_path=None,
 
-     )
 
-     assert command == ('borg', 'delete', 'repo')
 
- def test_make_repo_delete_command_includes_log_info():
 
-     insert_logging_mock(logging.INFO)
 
-     flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
 
-         ('repo',)
 
-     )
 
-     command = module.make_repo_delete_command(
 
-         repository={'path': 'repo'},
 
-         config={},
 
-         local_borg_version='1.2.3',
 
-         repo_delete_arguments=flexmock(list_archives=False, force=0),
 
-         global_arguments=flexmock(dry_run=False, log_json=False),
 
-         local_path='borg',
 
-         remote_path=None,
 
-     )
 
-     assert command == ('borg', 'repo-delete', '--info', 'repo')
 
- def test_make_repo_delete_command_includes_log_debug():
 
-     insert_logging_mock(logging.DEBUG)
 
-     flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
 
-         ('repo',)
 
-     )
 
-     command = module.make_repo_delete_command(
 
-         repository={'path': 'repo'},
 
-         config={},
 
-         local_borg_version='1.2.3',
 
-         repo_delete_arguments=flexmock(list_archives=False, force=0),
 
-         global_arguments=flexmock(dry_run=False, log_json=False),
 
-         local_path='borg',
 
-         remote_path=None,
 
-     )
 
-     assert command == ('borg', 'repo-delete', '--debug', '--show-rc', 'repo')
 
- def test_make_repo_delete_command_includes_dry_run():
 
-     flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags').with_args(
 
-         'dry-run', True
 
-     ).and_return(('--dry-run',))
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
 
-         ('repo',)
 
-     )
 
-     command = module.make_repo_delete_command(
 
-         repository={'path': 'repo'},
 
-         config={},
 
-         local_borg_version='1.2.3',
 
-         repo_delete_arguments=flexmock(list_archives=False, force=0),
 
-         global_arguments=flexmock(dry_run=True, log_json=False),
 
-         local_path='borg',
 
-         remote_path=None,
 
-     )
 
-     assert command == ('borg', 'repo-delete', '--dry-run', 'repo')
 
- def test_make_repo_delete_command_includes_remote_path():
 
-     flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags').with_args(
 
-         'remote-path', 'borg1'
 
-     ).and_return(('--remote-path', 'borg1'))
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
 
-         ('repo',)
 
-     )
 
-     command = module.make_repo_delete_command(
 
-         repository={'path': 'repo'},
 
-         config={},
 
-         local_borg_version='1.2.3',
 
-         repo_delete_arguments=flexmock(list_archives=False, force=0),
 
-         global_arguments=flexmock(dry_run=False, log_json=False),
 
-         local_path='borg',
 
-         remote_path='borg1',
 
-     )
 
-     assert command == ('borg', 'repo-delete', '--remote-path', 'borg1', 'repo')
 
- def test_make_repo_delete_command_includes_umask():
 
-     flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags').replace_with(
 
-         lambda name, value: (f'--{name}', value) if value else ()
 
-     )
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
 
-         ('repo',)
 
-     )
 
-     command = module.make_repo_delete_command(
 
-         repository={'path': 'repo'},
 
-         config={'umask': '077'},
 
-         local_borg_version='1.2.3',
 
-         repo_delete_arguments=flexmock(list_archives=False, force=0),
 
-         global_arguments=flexmock(dry_run=False, log_json=False),
 
-         local_path='borg',
 
-         remote_path=None,
 
-     )
 
-     assert command == ('borg', 'repo-delete', '--umask', '077', 'repo')
 
- def test_make_repo_delete_command_includes_log_json():
 
-     flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags').with_args(
 
-         'log-json', True
 
-     ).and_return(('--log-json',))
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
 
-         ('repo',)
 
-     )
 
-     command = module.make_repo_delete_command(
 
-         repository={'path': 'repo'},
 
-         config={},
 
-         local_borg_version='1.2.3',
 
-         repo_delete_arguments=flexmock(list_archives=False, force=0),
 
-         global_arguments=flexmock(dry_run=False, log_json=True),
 
-         local_path='borg',
 
-         remote_path=None,
 
-     )
 
-     assert command == ('borg', 'repo-delete', '--log-json', 'repo')
 
- def test_make_repo_delete_command_includes_lock_wait():
 
-     flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags').with_args(
 
-         'lock-wait', 5
 
-     ).and_return(('--lock-wait', '5'))
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
 
-         ('repo',)
 
-     )
 
-     command = module.make_repo_delete_command(
 
-         repository={'path': 'repo'},
 
-         config={'lock_wait': 5},
 
-         local_borg_version='1.2.3',
 
-         repo_delete_arguments=flexmock(list_archives=False, force=0),
 
-         global_arguments=flexmock(dry_run=False, log_json=False),
 
-         local_path='borg',
 
-         remote_path=None,
 
-     )
 
-     assert command == ('borg', 'repo-delete', '--lock-wait', '5', 'repo')
 
- def test_make_repo_delete_command_includes_list():
 
-     flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags').with_args(
 
-         'list', True
 
-     ).and_return(('--list',))
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
 
-         ('repo',)
 
-     )
 
-     command = module.make_repo_delete_command(
 
-         repository={'path': 'repo'},
 
-         config={},
 
-         local_borg_version='1.2.3',
 
-         repo_delete_arguments=flexmock(list_archives=True, force=0),
 
-         global_arguments=flexmock(dry_run=False, log_json=False),
 
-         local_path='borg',
 
-         remote_path=None,
 
-     )
 
-     assert command == ('borg', 'repo-delete', '--list', 'repo')
 
- def test_make_repo_delete_command_includes_force():
 
-     flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
 
-         ('repo',)
 
-     )
 
-     command = module.make_repo_delete_command(
 
-         repository={'path': 'repo'},
 
-         config={},
 
-         local_borg_version='1.2.3',
 
-         repo_delete_arguments=flexmock(list_archives=False, force=1),
 
-         global_arguments=flexmock(dry_run=False, log_json=False),
 
-         local_path='borg',
 
-         remote_path=None,
 
-     )
 
-     assert command == ('borg', 'repo-delete', '--force', 'repo')
 
- def test_make_repo_delete_command_includes_force_twice():
 
-     flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
 
-     flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
 
-         ('repo',)
 
-     )
 
-     command = module.make_repo_delete_command(
 
-         repository={'path': 'repo'},
 
-         config={},
 
-         local_borg_version='1.2.3',
 
-         repo_delete_arguments=flexmock(list_archives=False, force=2),
 
-         global_arguments=flexmock(dry_run=False, log_json=False),
 
-         local_path='borg',
 
-         remote_path=None,
 
-     )
 
-     assert command == ('borg', 'repo-delete', '--force', '--force', 'repo')
 
- def test_delete_repository_with_defaults_does_not_capture_output():
 
-     flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
 
-     command = flexmock()
 
-     flexmock(module).should_receive('make_repo_delete_command').and_return(command)
 
-     flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return(
 
-         flexmock()
 
-     )
 
-     flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
-     flexmock(module.borgmatic.execute).should_receive('execute_command').with_args(
 
-         command,
 
-         output_log_level=module.logging.ANSWER,
 
-         output_file=module.borgmatic.execute.DO_NOT_CAPTURE,
 
-         environment=object,
 
-         working_directory=None,
 
-         borg_local_path='borg',
 
-         borg_exit_codes=None,
 
-     ).once()
 
-     module.delete_repository(
 
-         repository={'path': 'repo'},
 
-         config={},
 
-         local_borg_version=flexmock(),
 
-         repo_delete_arguments=flexmock(force=False, cache_only=False),
 
-         global_arguments=flexmock(),
 
-         local_path='borg',
 
-         remote_path=None,
 
-     )
 
- def test_delete_repository_with_force_captures_output():
 
-     flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
 
-     command = flexmock()
 
-     flexmock(module).should_receive('make_repo_delete_command').and_return(command)
 
-     flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return(
 
-         flexmock()
 
-     )
 
-     flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
-     flexmock(module.borgmatic.execute).should_receive('execute_command').with_args(
 
-         command,
 
-         output_log_level=module.logging.ANSWER,
 
-         output_file=None,
 
-         environment=object,
 
-         working_directory=None,
 
-         borg_local_path='borg',
 
-         borg_exit_codes=None,
 
-     ).once()
 
-     module.delete_repository(
 
-         repository={'path': 'repo'},
 
-         config={},
 
-         local_borg_version=flexmock(),
 
-         repo_delete_arguments=flexmock(force=True, cache_only=False),
 
-         global_arguments=flexmock(),
 
-         local_path='borg',
 
-         remote_path=None,
 
-     )
 
- def test_delete_repository_with_cache_only_captures_output():
 
-     flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
 
-     command = flexmock()
 
-     flexmock(module).should_receive('make_repo_delete_command').and_return(command)
 
-     flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return(
 
-         flexmock()
 
-     )
 
-     flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
-     flexmock(module.borgmatic.execute).should_receive('execute_command').with_args(
 
-         command,
 
-         output_log_level=module.logging.ANSWER,
 
-         output_file=None,
 
-         environment=object,
 
-         working_directory=None,
 
-         borg_local_path='borg',
 
-         borg_exit_codes=None,
 
-     ).once()
 
-     module.delete_repository(
 
-         repository={'path': 'repo'},
 
-         config={},
 
-         local_borg_version=flexmock(),
 
-         repo_delete_arguments=flexmock(force=False, cache_only=True),
 
-         global_arguments=flexmock(),
 
-         local_path='borg',
 
-         remote_path=None,
 
-     )
 
- def test_delete_repository_calls_borg_with_working_directory():
 
-     flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
 
-     command = flexmock()
 
-     flexmock(module).should_receive('make_repo_delete_command').and_return(command)
 
-     flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return(
 
-         flexmock()
 
-     )
 
-     flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(
 
-         '/working/dir',
 
-     )
 
-     flexmock(module.borgmatic.execute).should_receive('execute_command').with_args(
 
-         command,
 
-         output_log_level=module.logging.ANSWER,
 
-         output_file=module.borgmatic.execute.DO_NOT_CAPTURE,
 
-         environment=object,
 
-         working_directory='/working/dir',
 
-         borg_local_path='borg',
 
-         borg_exit_codes=None,
 
-     ).once()
 
-     module.delete_repository(
 
-         repository={'path': 'repo'},
 
-         config={'working_directory': '/working/dir'},
 
-         local_borg_version=flexmock(),
 
-         repo_delete_arguments=flexmock(force=False, cache_only=False),
 
-         global_arguments=flexmock(),
 
-         local_path='borg',
 
-         remote_path=None,
 
-     )
 
 
  |