test_hook.py 1.0 KB

1234567891011121314151617181920212223242526272829
  1. from flexmock import flexmock
  2. from borgmatic.commands import hook as module
  3. def test_execute_hook_invokes_each_command():
  4. subprocess = flexmock(module.subprocess)
  5. subprocess.should_receive('check_call').with_args(':', shell=True).once()
  6. module.execute_hook([':'], 'config.yaml', 'pre-backup', dry_run=False)
  7. def test_execute_hook_with_multiple_commands_invokes_each_command():
  8. subprocess = flexmock(module.subprocess)
  9. subprocess.should_receive('check_call').with_args(':', shell=True).once()
  10. subprocess.should_receive('check_call').with_args('true', shell=True).once()
  11. module.execute_hook([':', 'true'], 'config.yaml', 'pre-backup', dry_run=False)
  12. def test_execute_hook_with_dry_run_skips_commands():
  13. subprocess = flexmock(module.subprocess)
  14. subprocess.should_receive('check_call').never()
  15. module.execute_hook([':', 'true'], 'config.yaml', 'pre-backup', dry_run=True)
  16. def test_execute_hook_with_empty_commands_does_not_raise():
  17. module.execute_hook([], 'config.yaml', 'post-backup', dry_run=False)