test_info.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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.INFO
  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.INFO
  14. )
  15. insert_logging_mock(logging.INFO)
  16. module.display_archives_info(repository='repo', storage_config={})
  17. def test_display_archives_info_with_log_debug_calls_borg_with_debug_parameter():
  18. flexmock(module).should_receive('execute_command').with_args(
  19. INFO_COMMAND + ('--debug', '--show-rc'), output_log_level=logging.INFO
  20. )
  21. insert_logging_mock(logging.DEBUG)
  22. module.display_archives_info(repository='repo', storage_config={})
  23. def test_display_archives_info_with_json_calls_borg_with_json_parameter():
  24. flexmock(module).should_receive('execute_command').with_args(
  25. INFO_COMMAND + ('--json',), output_log_level=None
  26. ).and_return('[]')
  27. json_output = module.display_archives_info(repository='repo', storage_config={}, json=True)
  28. assert json_output == '[]'
  29. def test_display_archives_info_with_local_path_calls_borg_via_local_path():
  30. flexmock(module).should_receive('execute_command').with_args(
  31. ('borg1',) + INFO_COMMAND[1:], output_log_level=logging.INFO
  32. )
  33. module.display_archives_info(repository='repo', storage_config={}, local_path='borg1')
  34. def test_display_archives_info_with_remote_path_calls_borg_with_remote_path_parameters():
  35. flexmock(module).should_receive('execute_command').with_args(
  36. INFO_COMMAND + ('--remote-path', 'borg1'), output_log_level=logging.INFO
  37. )
  38. module.display_archives_info(repository='repo', storage_config={}, remote_path='borg1')
  39. def test_display_archives_info_with_lock_wait_calls_borg_with_lock_wait_parameters():
  40. storage_config = {'lock_wait': 5}
  41. flexmock(module).should_receive('execute_command').with_args(
  42. INFO_COMMAND + ('--lock-wait', '5'), output_log_level=logging.INFO
  43. )
  44. module.display_archives_info(repository='repo', storage_config=storage_config)