test_pagerduty.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from flexmock import flexmock
  2. from borgmatic.hooks import pagerduty as module
  3. def test_ping_monitor_ignores_start_state():
  4. flexmock(module.requests).should_receive('post').never()
  5. module.ping_monitor(
  6. {'integration_key': 'abc123'},
  7. 'config.yaml',
  8. module.monitor.State.START,
  9. monitoring_log_level=1,
  10. dry_run=False,
  11. )
  12. def test_ping_monitor_ignores_finish_state():
  13. flexmock(module.requests).should_receive('post').never()
  14. module.ping_monitor(
  15. {'integration_key': 'abc123'},
  16. 'config.yaml',
  17. module.monitor.State.FINISH,
  18. monitoring_log_level=1,
  19. dry_run=False,
  20. )
  21. def test_ping_monitor_calls_api_for_fail_state():
  22. flexmock(module.requests).should_receive('post')
  23. module.ping_monitor(
  24. {'integration_key': 'abc123'},
  25. 'config.yaml',
  26. module.monitor.State.FAIL,
  27. monitoring_log_level=1,
  28. dry_run=False,
  29. )
  30. def test_ping_monitor_dry_run_does_not_call_api():
  31. flexmock(module.requests).should_receive('post').never()
  32. module.ping_monitor(
  33. {'integration_key': 'abc123'},
  34. 'config.yaml',
  35. module.monitor.State.FAIL,
  36. monitoring_log_level=1,
  37. dry_run=True,
  38. )
  39. def test_ping_monitor_with_connection_error_does_not_raise():
  40. flexmock(module.requests).should_receive('post').and_raise(
  41. module.requests.exceptions.ConnectionError
  42. )
  43. flexmock(module.logger).should_receive('warning')
  44. module.ping_monitor(
  45. {'integration_key': 'abc123'},
  46. 'config.yaml',
  47. module.monitor.State.FAIL,
  48. monitoring_log_level=1,
  49. dry_run=False,
  50. )