| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 | 
							- from flexmock import flexmock
 
- import borgmatic.hooks.monitor
 
- from borgmatic.hooks import uptimekuma as module
 
- DEFAULT_PUSH_URL = 'https://example.uptime.kuma/api/push/abcd1234'
 
- CUSTOM_PUSH_URL = 'https://uptime.example.com/api/push/efgh5678'
 
- def test_ping_monitor_hits_default_uptimekuma_on_fail():
 
-     hook_config = {}
 
-     flexmock(module.requests).should_receive('get').with_args(
 
-         f'{DEFAULT_PUSH_URL}?status=down&msg=fail'
 
-     ).and_return(flexmock(ok=True)).once()
 
-     module.ping_monitor(
 
-         hook_config,
 
-         {},
 
-         'config.yaml',
 
-         borgmatic.hooks.monitor.State.FAIL,
 
-         monitoring_log_level=1,
 
-         dry_run=False,
 
-     )
 
- def test_ping_monitor_hits_custom_uptimekuma_on_fail():
 
-     hook_config = {'push_url': CUSTOM_PUSH_URL}
 
-     flexmock(module.requests).should_receive('get').with_args(
 
-         f'{CUSTOM_PUSH_URL}?status=down&msg=fail'
 
-     ).and_return(flexmock(ok=True)).once()
 
-     module.ping_monitor(
 
-         hook_config,
 
-         {},
 
-         'config.yaml',
 
-         borgmatic.hooks.monitor.State.FAIL,
 
-         monitoring_log_level=1,
 
-         dry_run=False,
 
-     )
 
- def test_ping_monitor_custom_uptimekuma_on_start():
 
-     hook_config = {'push_url': CUSTOM_PUSH_URL}
 
-     flexmock(module.requests).should_receive('get').with_args(
 
-         f'{CUSTOM_PUSH_URL}?status=up&msg=start'
 
-     ).and_return(flexmock(ok=True)).once()
 
-     module.ping_monitor(
 
-         hook_config,
 
-         {},
 
-         'config.yaml',
 
-         borgmatic.hooks.monitor.State.START,
 
-         monitoring_log_level=1,
 
-         dry_run=False,
 
-     )
 
- def test_ping_monitor_custom_uptimekuma_on_finish():
 
-     hook_config = {'push_url': CUSTOM_PUSH_URL}
 
-     flexmock(module.requests).should_receive('get').with_args(
 
-         f'{CUSTOM_PUSH_URL}?status=up&msg=finish'
 
-     ).and_return(flexmock(ok=True)).once()
 
-     module.ping_monitor(
 
-         hook_config,
 
-         {},
 
-         'config.yaml',
 
-         borgmatic.hooks.monitor.State.FINISH,
 
-         monitoring_log_level=1,
 
-         dry_run=False,
 
-     )
 
- def test_ping_monitor_does_not_hit_custom_uptimekuma_on_fail_dry_run():
 
-     hook_config = {'push_url': CUSTOM_PUSH_URL}
 
-     flexmock(module.requests).should_receive('get').never()
 
-     module.ping_monitor(
 
-         hook_config,
 
-         {},
 
-         'config.yaml',
 
-         borgmatic.hooks.monitor.State.FAIL,
 
-         monitoring_log_level=1,
 
-         dry_run=True,
 
-     )
 
- def test_ping_monitor_does_not_hit_custom_uptimekuma_on_start_dry_run():
 
-     hook_config = {'push_url': CUSTOM_PUSH_URL}
 
-     flexmock(module.requests).should_receive('get').never()
 
-     module.ping_monitor(
 
-         hook_config,
 
-         {},
 
-         'config.yaml',
 
-         borgmatic.hooks.monitor.State.START,
 
-         monitoring_log_level=1,
 
-         dry_run=True,
 
-     )
 
- def test_ping_monitor_does_not_hit_custom_uptimekuma_on_finish_dry_run():
 
-     hook_config = {'push_url': CUSTOM_PUSH_URL}
 
-     flexmock(module.requests).should_receive('get').never()
 
-     module.ping_monitor(
 
-         hook_config,
 
-         {},
 
-         'config.yaml',
 
-         borgmatic.hooks.monitor.State.FINISH,
 
-         monitoring_log_level=1,
 
-         dry_run=True,
 
-     )
 
- def test_ping_monitor_with_connection_error_logs_warning():
 
-     hook_config = {'push_url': CUSTOM_PUSH_URL}
 
-     flexmock(module.requests).should_receive('get').with_args(
 
-         f'{CUSTOM_PUSH_URL}?status=down&msg=fail'
 
-     ).and_raise(module.requests.exceptions.ConnectionError)
 
-     flexmock(module.logger).should_receive('warning').once()
 
-     module.ping_monitor(
 
-         hook_config,
 
-         {},
 
-         'config.yaml',
 
-         borgmatic.hooks.monitor.State.FAIL,
 
-         monitoring_log_level=1,
 
-         dry_run=False,
 
-     )
 
- def test_ping_monitor_with_other_error_logs_warning():
 
-     hook_config = {'push_url': CUSTOM_PUSH_URL}
 
-     response = flexmock(ok=False)
 
-     response.should_receive('raise_for_status').and_raise(
 
-         module.requests.exceptions.RequestException
 
-     )
 
-     flexmock(module.requests).should_receive('get').with_args(
 
-         f'{CUSTOM_PUSH_URL}?status=down&msg=fail'
 
-     ).and_return(response)
 
-     flexmock(module.logger).should_receive('warning').once()
 
-     module.ping_monitor(
 
-         hook_config,
 
-         {},
 
-         'config.yaml',
 
-         borgmatic.hooks.monitor.State.FAIL,
 
-         monitoring_log_level=1,
 
-         dry_run=False,
 
-     )
 
- def test_ping_monitor_with_invalid_run_state():
 
-     hook_config = {'push_url': CUSTOM_PUSH_URL}
 
-     flexmock(module.requests).should_receive('get').never()
 
-     module.ping_monitor(
 
-         hook_config,
 
-         {},
 
-         'config.yaml',
 
-         borgmatic.hooks.monitor.State.LOG,
 
-         monitoring_log_level=1,
 
-         dry_run=True,
 
-     )
 
 
  |