test_info.py 4.8 KB

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