test_info.py 2.3 KB

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