test_list.py 2.6 KB

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