test_info.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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.environment).should_receive('make_environment')
  8. flexmock(module).should_receive('execute_command').with_args(
  9. ('borg', 'info', 'repo'),
  10. output_log_level=logging.WARNING,
  11. borg_local_path='borg',
  12. extra_environment=None,
  13. )
  14. module.display_archives_info(
  15. repository='repo', storage_config={}, info_arguments=flexmock(archive=None, json=False)
  16. )
  17. def test_display_archives_info_with_log_info_calls_borg_with_info_parameter():
  18. flexmock(module.environment).should_receive('make_environment')
  19. flexmock(module).should_receive('execute_command').with_args(
  20. ('borg', 'info', '--info', 'repo'),
  21. output_log_level=logging.WARNING,
  22. borg_local_path='borg',
  23. extra_environment=None,
  24. )
  25. insert_logging_mock(logging.INFO)
  26. module.display_archives_info(
  27. repository='repo', storage_config={}, info_arguments=flexmock(archive=None, json=False)
  28. )
  29. def test_display_archives_info_with_log_info_and_json_suppresses_most_borg_output():
  30. flexmock(module.environment).should_receive('make_environment')
  31. flexmock(module).should_receive('execute_command').with_args(
  32. ('borg', 'info', '--json', 'repo'),
  33. output_log_level=None,
  34. borg_local_path='borg',
  35. extra_environment=None,
  36. ).and_return('[]')
  37. insert_logging_mock(logging.INFO)
  38. json_output = module.display_archives_info(
  39. repository='repo', storage_config={}, info_arguments=flexmock(archive=None, json=True)
  40. )
  41. assert json_output == '[]'
  42. def test_display_archives_info_with_log_debug_calls_borg_with_debug_parameter():
  43. flexmock(module.environment).should_receive('make_environment')
  44. flexmock(module).should_receive('execute_command').with_args(
  45. ('borg', 'info', '--debug', '--show-rc', 'repo'),
  46. output_log_level=logging.WARNING,
  47. borg_local_path='borg',
  48. extra_environment=None,
  49. )
  50. insert_logging_mock(logging.DEBUG)
  51. module.display_archives_info(
  52. repository='repo', storage_config={}, info_arguments=flexmock(archive=None, json=False)
  53. )
  54. def test_display_archives_info_with_log_debug_and_json_suppresses_most_borg_output():
  55. flexmock(module.environment).should_receive('make_environment')
  56. flexmock(module).should_receive('execute_command').with_args(
  57. ('borg', 'info', '--json', 'repo'),
  58. output_log_level=None,
  59. borg_local_path='borg',
  60. extra_environment=None,
  61. ).and_return('[]')
  62. insert_logging_mock(logging.DEBUG)
  63. json_output = module.display_archives_info(
  64. repository='repo', storage_config={}, info_arguments=flexmock(archive=None, json=True)
  65. )
  66. assert json_output == '[]'
  67. def test_display_archives_info_with_json_calls_borg_with_json_parameter():
  68. flexmock(module.environment).should_receive('make_environment')
  69. flexmock(module).should_receive('execute_command').with_args(
  70. ('borg', 'info', '--json', 'repo'),
  71. output_log_level=None,
  72. borg_local_path='borg',
  73. extra_environment=None,
  74. ).and_return('[]')
  75. json_output = module.display_archives_info(
  76. repository='repo', storage_config={}, info_arguments=flexmock(archive=None, json=True)
  77. )
  78. assert json_output == '[]'
  79. def test_display_archives_info_with_archive_calls_borg_with_archive_parameter():
  80. flexmock(module.environment).should_receive('make_environment')
  81. flexmock(module).should_receive('execute_command').with_args(
  82. ('borg', 'info', 'repo::archive'),
  83. output_log_level=logging.WARNING,
  84. borg_local_path='borg',
  85. extra_environment=None,
  86. )
  87. module.display_archives_info(
  88. repository='repo', storage_config={}, info_arguments=flexmock(archive='archive', json=False)
  89. )
  90. def test_display_archives_info_with_local_path_calls_borg_via_local_path():
  91. flexmock(module.environment).should_receive('make_environment')
  92. flexmock(module).should_receive('execute_command').with_args(
  93. ('borg1', 'info', 'repo'),
  94. output_log_level=logging.WARNING,
  95. borg_local_path='borg1',
  96. extra_environment=None,
  97. )
  98. module.display_archives_info(
  99. repository='repo',
  100. storage_config={},
  101. info_arguments=flexmock(archive=None, json=False),
  102. local_path='borg1',
  103. )
  104. def test_display_archives_info_with_remote_path_calls_borg_with_remote_path_parameters():
  105. flexmock(module.environment).should_receive('make_environment')
  106. flexmock(module).should_receive('execute_command').with_args(
  107. ('borg', 'info', '--remote-path', 'borg1', 'repo'),
  108. output_log_level=logging.WARNING,
  109. borg_local_path='borg',
  110. extra_environment=None,
  111. )
  112. module.display_archives_info(
  113. repository='repo',
  114. storage_config={},
  115. info_arguments=flexmock(archive=None, json=False),
  116. remote_path='borg1',
  117. )
  118. def test_display_archives_info_with_lock_wait_calls_borg_with_lock_wait_parameters():
  119. storage_config = {'lock_wait': 5}
  120. flexmock(module.environment).should_receive('make_environment')
  121. flexmock(module).should_receive('execute_command').with_args(
  122. ('borg', 'info', '--lock-wait', '5', 'repo'),
  123. output_log_level=logging.WARNING,
  124. borg_local_path='borg',
  125. extra_environment=None,
  126. )
  127. module.display_archives_info(
  128. repository='repo',
  129. storage_config=storage_config,
  130. info_arguments=flexmock(archive=None, json=False),
  131. )
  132. @pytest.mark.parametrize('argument_name', ('prefix', 'glob_archives', 'sort_by', 'first', 'last'))
  133. def test_display_archives_info_passes_through_arguments_to_borg(argument_name):
  134. flexmock(module.environment).should_receive('make_environment')
  135. flexmock(module).should_receive('execute_command').with_args(
  136. ('borg', 'info', '--' + argument_name.replace('_', '-'), 'value', 'repo'),
  137. output_log_level=logging.WARNING,
  138. borg_local_path='borg',
  139. extra_environment=None,
  140. )
  141. module.display_archives_info(
  142. repository='repo',
  143. storage_config={},
  144. info_arguments=flexmock(archive=None, json=False, **{argument_name: 'value'}),
  145. )