test_info.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import logging
  2. import pytest
  3. from flexmock import flexmock
  4. from borgmatic.borg import info as module
  5. from ..test_verbosity import insert_logging_mock
  6. def test_display_archives_info_calls_borg_with_parameters():
  7. flexmock(module).should_receive('execute_command').with_args(
  8. ('borg', 'info', 'repo'), output_log_level=logging.WARNING, error_on_warnings=False
  9. )
  10. module.display_archives_info(
  11. repository='repo', storage_config={}, info_arguments=flexmock(archive=None, json=False)
  12. )
  13. def test_display_archives_info_with_log_info_calls_borg_with_info_parameter():
  14. flexmock(module).should_receive('execute_command').with_args(
  15. ('borg', 'info', '--info', 'repo'),
  16. output_log_level=logging.WARNING,
  17. error_on_warnings=False,
  18. )
  19. insert_logging_mock(logging.INFO)
  20. module.display_archives_info(
  21. repository='repo', storage_config={}, info_arguments=flexmock(archive=None, json=False)
  22. )
  23. def test_display_archives_info_with_log_info_and_json_suppresses_most_borg_output():
  24. flexmock(module).should_receive('execute_command').with_args(
  25. ('borg', 'info', '--json', 'repo'), output_log_level=None, error_on_warnings=False
  26. ).and_return('[]')
  27. insert_logging_mock(logging.INFO)
  28. json_output = module.display_archives_info(
  29. repository='repo', storage_config={}, info_arguments=flexmock(archive=None, json=True)
  30. )
  31. assert json_output == '[]'
  32. def test_display_archives_info_with_log_debug_calls_borg_with_debug_parameter():
  33. flexmock(module).should_receive('execute_command').with_args(
  34. ('borg', 'info', '--debug', '--show-rc', 'repo'),
  35. output_log_level=logging.WARNING,
  36. error_on_warnings=False,
  37. )
  38. insert_logging_mock(logging.DEBUG)
  39. module.display_archives_info(
  40. repository='repo', storage_config={}, info_arguments=flexmock(archive=None, json=False)
  41. )
  42. def test_display_archives_info_with_log_debug_and_json_suppresses_most_borg_output():
  43. flexmock(module).should_receive('execute_command').with_args(
  44. ('borg', 'info', '--json', 'repo'), output_log_level=None, error_on_warnings=False
  45. ).and_return('[]')
  46. insert_logging_mock(logging.DEBUG)
  47. json_output = module.display_archives_info(
  48. repository='repo', storage_config={}, info_arguments=flexmock(archive=None, json=True)
  49. )
  50. assert json_output == '[]'
  51. def test_display_archives_info_with_json_calls_borg_with_json_parameter():
  52. flexmock(module).should_receive('execute_command').with_args(
  53. ('borg', 'info', '--json', 'repo'), output_log_level=None, error_on_warnings=False
  54. ).and_return('[]')
  55. json_output = module.display_archives_info(
  56. repository='repo', storage_config={}, info_arguments=flexmock(archive=None, json=True)
  57. )
  58. assert json_output == '[]'
  59. def test_display_archives_info_with_archive_calls_borg_with_archive_parameter():
  60. flexmock(module).should_receive('execute_command').with_args(
  61. ('borg', 'info', 'repo::archive'), output_log_level=logging.WARNING, error_on_warnings=False
  62. )
  63. module.display_archives_info(
  64. repository='repo', storage_config={}, info_arguments=flexmock(archive='archive', json=False)
  65. )
  66. def test_display_archives_info_with_local_path_calls_borg_via_local_path():
  67. flexmock(module).should_receive('execute_command').with_args(
  68. ('borg1', 'info', 'repo'), output_log_level=logging.WARNING, error_on_warnings=False
  69. )
  70. module.display_archives_info(
  71. repository='repo',
  72. storage_config={},
  73. info_arguments=flexmock(archive=None, json=False),
  74. local_path='borg1',
  75. )
  76. def test_display_archives_info_with_remote_path_calls_borg_with_remote_path_parameters():
  77. flexmock(module).should_receive('execute_command').with_args(
  78. ('borg', 'info', '--remote-path', 'borg1', 'repo'),
  79. output_log_level=logging.WARNING,
  80. error_on_warnings=False,
  81. )
  82. module.display_archives_info(
  83. repository='repo',
  84. storage_config={},
  85. info_arguments=flexmock(archive=None, json=False),
  86. remote_path='borg1',
  87. )
  88. def test_display_archives_info_with_lock_wait_calls_borg_with_lock_wait_parameters():
  89. storage_config = {'lock_wait': 5}
  90. flexmock(module).should_receive('execute_command').with_args(
  91. ('borg', 'info', '--lock-wait', '5', 'repo'),
  92. output_log_level=logging.WARNING,
  93. error_on_warnings=False,
  94. )
  95. module.display_archives_info(
  96. repository='repo',
  97. storage_config=storage_config,
  98. info_arguments=flexmock(archive=None, json=False),
  99. )
  100. @pytest.mark.parametrize('argument_name', ('prefix', 'glob_archives', 'sort_by', 'first', 'last'))
  101. def test_display_archives_info_passes_through_arguments_to_borg(argument_name):
  102. flexmock(module).should_receive('execute_command').with_args(
  103. ('borg', 'info', '--' + argument_name.replace('_', '-'), 'value', 'repo'),
  104. output_log_level=logging.WARNING,
  105. error_on_warnings=False,
  106. )
  107. module.display_archives_info(
  108. repository='repo',
  109. storage_config={},
  110. info_arguments=flexmock(archive=None, json=False, **{argument_name: 'value'}),
  111. )