test_info.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import logging
  2. from flexmock import flexmock
  3. from borgmatic.borg import info as module
  4. from ..test_verbosity import insert_logging_mock
  5. INFO_COMMAND = ('borg', 'info', 'repo')
  6. def test_display_archives_info_calls_borg_with_parameters():
  7. flexmock(module).should_receive('execute_command').with_args(
  8. INFO_COMMAND, output_log_level=logging.WARNING
  9. )
  10. module.display_archives_info(repository='repo', storage_config={})
  11. def test_display_archives_info_with_log_info_calls_borg_with_info_parameter():
  12. flexmock(module).should_receive('execute_command').with_args(
  13. INFO_COMMAND + ('--info',), output_log_level=logging.WARNING
  14. )
  15. insert_logging_mock(logging.INFO)
  16. module.display_archives_info(repository='repo', storage_config={})
  17. def test_display_archives_info_with_log_info_and_json_suppresses_most_borg_output():
  18. flexmock(module).should_receive('execute_command').with_args(
  19. INFO_COMMAND + ('--json',), output_log_level=None
  20. ).and_return('[]')
  21. insert_logging_mock(logging.INFO)
  22. json_output = module.display_archives_info(repository='repo', storage_config={}, json=True)
  23. assert json_output == '[]'
  24. def test_display_archives_info_with_log_debug_calls_borg_with_debug_parameter():
  25. flexmock(module).should_receive('execute_command').with_args(
  26. INFO_COMMAND + ('--debug', '--show-rc'), output_log_level=logging.WARNING
  27. )
  28. insert_logging_mock(logging.DEBUG)
  29. module.display_archives_info(repository='repo', storage_config={})
  30. def test_display_archives_info_with_log_debug_and_json_suppresses_most_borg_output():
  31. flexmock(module).should_receive('execute_command').with_args(
  32. INFO_COMMAND + ('--json',), output_log_level=None
  33. ).and_return('[]')
  34. insert_logging_mock(logging.DEBUG)
  35. json_output = module.display_archives_info(repository='repo', storage_config={}, json=True)
  36. assert json_output == '[]'
  37. def test_display_archives_info_with_json_calls_borg_with_json_parameter():
  38. flexmock(module).should_receive('execute_command').with_args(
  39. INFO_COMMAND + ('--json',), output_log_level=None
  40. ).and_return('[]')
  41. json_output = module.display_archives_info(repository='repo', storage_config={}, json=True)
  42. assert json_output == '[]'
  43. def test_display_archives_info_with_local_path_calls_borg_via_local_path():
  44. flexmock(module).should_receive('execute_command').with_args(
  45. ('borg1',) + INFO_COMMAND[1:], output_log_level=logging.WARNING
  46. )
  47. module.display_archives_info(repository='repo', storage_config={}, local_path='borg1')
  48. def test_display_archives_info_with_remote_path_calls_borg_with_remote_path_parameters():
  49. flexmock(module).should_receive('execute_command').with_args(
  50. INFO_COMMAND + ('--remote-path', 'borg1'), output_log_level=logging.WARNING
  51. )
  52. module.display_archives_info(repository='repo', storage_config={}, remote_path='borg1')
  53. def test_display_archives_info_with_lock_wait_calls_borg_with_lock_wait_parameters():
  54. storage_config = {'lock_wait': 5}
  55. flexmock(module).should_receive('execute_command').with_args(
  56. INFO_COMMAND + ('--lock-wait', '5'), output_log_level=logging.WARNING
  57. )
  58. module.display_archives_info(repository='repo', storage_config=storage_config)