test_list.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import logging
  2. from flexmock import flexmock
  3. from borgmatic.borg import list as module
  4. from ..test_verbosity import insert_logging_mock
  5. LIST_COMMAND = ('borg', 'list', 'repo')
  6. def test_list_archives_calls_borg_with_parameters():
  7. flexmock(module).should_receive('execute_command').with_args(
  8. LIST_COMMAND, output_log_level=logging.INFO
  9. )
  10. module.list_archives(repository='repo', storage_config={})
  11. def test_list_archives_with_log_info_calls_borg_with_info_parameter():
  12. flexmock(module).should_receive('execute_command').with_args(
  13. LIST_COMMAND + ('--info',), output_log_level=logging.INFO
  14. )
  15. insert_logging_mock(logging.INFO)
  16. module.list_archives(repository='repo', storage_config={})
  17. def test_list_archives_with_log_debug_calls_borg_with_debug_parameter():
  18. flexmock(module).should_receive('execute_command').with_args(
  19. LIST_COMMAND + ('--debug', '--show-rc'), output_log_level=logging.INFO
  20. )
  21. insert_logging_mock(logging.DEBUG)
  22. module.list_archives(repository='repo', storage_config={})
  23. def test_list_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
  24. storage_config = {'lock_wait': 5}
  25. flexmock(module).should_receive('execute_command').with_args(
  26. LIST_COMMAND + ('--lock-wait', '5'), output_log_level=logging.INFO
  27. )
  28. module.list_archives(repository='repo', storage_config=storage_config)
  29. def test_list_archives_with_archive_calls_borg_with_archive_parameter():
  30. storage_config = {}
  31. flexmock(module).should_receive('execute_command').with_args(
  32. ('borg', 'list', 'repo::archive'), output_log_level=logging.INFO
  33. )
  34. module.list_archives(repository='repo', storage_config=storage_config, archive='archive')
  35. def test_list_archives_with_local_path_calls_borg_via_local_path():
  36. flexmock(module).should_receive('execute_command').with_args(
  37. ('borg1',) + LIST_COMMAND[1:], output_log_level=logging.INFO
  38. )
  39. module.list_archives(repository='repo', storage_config={}, local_path='borg1')
  40. def test_list_archives_with_remote_path_calls_borg_with_remote_path_parameters():
  41. flexmock(module).should_receive('execute_command').with_args(
  42. LIST_COMMAND + ('--remote-path', 'borg1'), output_log_level=logging.INFO
  43. )
  44. module.list_archives(repository='repo', storage_config={}, remote_path='borg1')
  45. def test_list_archives_with_json_calls_borg_with_json_parameter():
  46. flexmock(module).should_receive('execute_command').with_args(
  47. LIST_COMMAND + ('--json',), output_log_level=None
  48. ).and_return('[]')
  49. json_output = module.list_archives(repository='repo', storage_config={}, json=True)
  50. assert json_output == '[]'