2
0

test_prune.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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(), statistics=flexmock(), list_details=flexmock()
  28. )
  29. global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
  30. module.run_prune(
  31. config_filename='test.yaml',
  32. repository={'path': 'repo'},
  33. config={},
  34. local_borg_version=None,
  35. prune_arguments=prune_arguments,
  36. global_arguments=global_arguments,
  37. dry_run_label='',
  38. local_path=None,
  39. remote_path=None,
  40. )
  41. def test_run_prune_bails_if_repository_does_not_match():
  42. flexmock(module.logger).answer = lambda message: None
  43. flexmock(module.borgmatic.config.validate).should_receive(
  44. 'repositories_match'
  45. ).once().and_return(False)
  46. flexmock(module.borgmatic.borg.prune).should_receive('prune_archives').never()
  47. prune_arguments = flexmock(
  48. repository=flexmock(), statistics=flexmock(), list_details=flexmock()
  49. )
  50. global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
  51. module.run_prune(
  52. config_filename='test.yaml',
  53. repository='repo',
  54. config={},
  55. local_borg_version=None,
  56. prune_arguments=prune_arguments,
  57. global_arguments=global_arguments,
  58. dry_run_label='',
  59. local_path=None,
  60. remote_path=None,
  61. )