test_hook.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. import logging
  2. from flexmock import flexmock
  3. from borgmatic import hook as module
  4. def test_execute_hook_invokes_each_command():
  5. flexmock(module.execute).should_receive('execute_command').with_args(
  6. [':'], output_log_level=logging.WARNING, shell=True
  7. ).once()
  8. module.execute_hook([':'], 'config.yaml', 'pre-backup', dry_run=False)
  9. def test_execute_hook_with_multiple_commands_invokes_each_command():
  10. flexmock(module.execute).should_receive('execute_command').with_args(
  11. [':'], output_log_level=logging.WARNING, shell=True
  12. ).once()
  13. flexmock(module.execute).should_receive('execute_command').with_args(
  14. ['true'], output_log_level=logging.WARNING, shell=True
  15. ).once()
  16. module.execute_hook([':', 'true'], 'config.yaml', 'pre-backup', dry_run=False)
  17. def test_execute_hook_with_dry_run_skips_commands():
  18. flexmock(module.execute).should_receive('execute_command').never()
  19. module.execute_hook([':', 'true'], 'config.yaml', 'pre-backup', dry_run=True)
  20. def test_execute_hook_with_empty_commands_does_not_raise():
  21. module.execute_hook([], 'config.yaml', 'post-backup', dry_run=False)