test_prune.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. from flexmock import flexmock
  2. from borgmatic.actions import prune as module
  3. def test_run_prune_calls_hooks_for_configured_repository():
  4. flexmock(module.logger).answer = lambda message: None
  5. flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never()
  6. flexmock(module.borgmatic.borg.prune).should_receive('prune_archives').once()
  7. prune_arguments = flexmock(repository=None, statistics=flexmock(), list_details=flexmock())
  8. global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
  9. module.run_prune(
  10. config_filename='test.yaml',
  11. repository={'path': 'repo'},
  12. config={},
  13. local_borg_version=None,
  14. prune_arguments=prune_arguments,
  15. global_arguments=global_arguments,
  16. dry_run_label='',
  17. local_path=None,
  18. remote_path=None,
  19. )
  20. def test_run_prune_runs_with_selected_repository():
  21. flexmock(module.logger).answer = lambda message: None
  22. flexmock(module.borgmatic.config.validate).should_receive(
  23. 'repositories_match',
  24. ).once().and_return(True)
  25. flexmock(module.borgmatic.borg.prune).should_receive('prune_archives').once()
  26. prune_arguments = flexmock(
  27. repository=flexmock(),
  28. statistics=flexmock(),
  29. list_details=flexmock(),
  30. )
  31. global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
  32. module.run_prune(
  33. config_filename='test.yaml',
  34. repository={'path': 'repo'},
  35. config={},
  36. local_borg_version=None,
  37. prune_arguments=prune_arguments,
  38. global_arguments=global_arguments,
  39. dry_run_label='',
  40. local_path=None,
  41. remote_path=None,
  42. )
  43. def test_run_prune_bails_if_repository_does_not_match():
  44. flexmock(module.logger).answer = lambda message: None
  45. flexmock(module.borgmatic.config.validate).should_receive(
  46. 'repositories_match',
  47. ).once().and_return(False)
  48. flexmock(module.borgmatic.borg.prune).should_receive('prune_archives').never()
  49. prune_arguments = flexmock(
  50. repository=flexmock(),
  51. statistics=flexmock(),
  52. list_details=flexmock(),
  53. )
  54. global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
  55. module.run_prune(
  56. config_filename='test.yaml',
  57. repository='repo',
  58. config={},
  59. local_borg_version=None,
  60. prune_arguments=prune_arguments,
  61. global_arguments=global_arguments,
  62. dry_run_label='',
  63. local_path=None,
  64. remote_path=None,
  65. )