test_borgmatic.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import json
  2. import sys
  3. from flexmock import flexmock
  4. from borgmatic.commands import borgmatic as module
  5. def test_run_commands_handles_multiple_json_outputs_in_array():
  6. (
  7. flexmock(module)
  8. .should_receive('_run_commands_on_repository')
  9. .times(3)
  10. .replace_with(
  11. lambda args, consistency, json_results, local_path, location, remote_path, retention, storage, unexpanded_repository: json_results.append(
  12. {"whatever": unexpanded_repository}
  13. )
  14. )
  15. )
  16. (
  17. flexmock(sys.stdout)
  18. .should_call("write")
  19. .with_args(
  20. json.dumps(
  21. json.loads(
  22. '''
  23. [
  24. {"whatever": "fake_repo1"},
  25. {"whatever": "fake_repo2"},
  26. {"whatever": "fake_repo3"}
  27. ]
  28. '''
  29. )
  30. )
  31. )
  32. )
  33. module._run_commands(
  34. args=flexmock(json=True),
  35. consistency=None,
  36. local_path=None,
  37. location={'repositories': ['fake_repo1', 'fake_repo2', 'fake_repo3']},
  38. remote_path=None,
  39. retention=None,
  40. storage=None,
  41. )
  42. def test_collect_configuration_run_summary_logs_info_for_success():
  43. flexmock(module).should_receive('run_configuration')
  44. logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=()))
  45. assert any(log for log in logs if log.levelno == module.logging.INFO)
  46. def test_collect_configuration_run_summary_logs_critical_for_error():
  47. flexmock(module).should_receive('run_configuration').and_raise(ValueError)
  48. logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=()))
  49. assert any(log for log in logs if log.levelno == module.logging.CRITICAL)
  50. def test_collect_configuration_run_summary_logs_critical_for_missing_configs():
  51. logs = tuple(
  52. module.collect_configuration_run_summary_logs(
  53. config_filenames=(), args=flexmock(config_paths=())
  54. )
  55. )
  56. assert any(log for log in logs if log.levelno == module.logging.CRITICAL)