variable renaming
This commit is contained in:
parent
612f867ea8
commit
f97968b72d
1 changed files with 18 additions and 15 deletions
|
@ -3,13 +3,14 @@ from flexmock import flexmock
|
|||
import borgmatic.hooks.monitor
|
||||
from borgmatic.hooks import uptimekuma as module
|
||||
|
||||
DEFAULT_BASE_URL = 'https://example.uptime.kuma/api/push/abcd1234'
|
||||
CUSTOM_BASE_URL = 'https://uptime.example.com/api/push/efgh5678'
|
||||
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_BASE_URL}?status=down&msg=fail'
|
||||
f'{DEFAULT_PUSH_URL}?status=down&msg=fail'
|
||||
).and_return(flexmock(ok=True)).once()
|
||||
|
||||
module.ping_monitor(
|
||||
|
@ -23,9 +24,9 @@ def test_ping_monitor_hits_default_uptimekuma_on_fail():
|
|||
|
||||
|
||||
def test_ping_monitor_hits_custom_uptimekuma_on_fail():
|
||||
hook_config = {'push_url': push_url}
|
||||
hook_config = {'push_url': CUSTOM_PUSH_URL}
|
||||
flexmock(module.requests).should_receive('get').with_args(
|
||||
f'{CUSTOM_BASE_URL}?status=down&msg=fail'
|
||||
f'{CUSTOM_PUSH_URL}?status=down&msg=fail'
|
||||
).and_return(flexmock(ok=True)).once()
|
||||
|
||||
module.ping_monitor(
|
||||
|
@ -38,9 +39,9 @@ def test_ping_monitor_hits_custom_uptimekuma_on_fail():
|
|||
)
|
||||
|
||||
def test_ping_monitor_custom_uptimekuma_on_start():
|
||||
hook_config = {'push_url': push_url}
|
||||
hook_config = {'push_url': CUSTOM_PUSH_URL}
|
||||
flexmock(module.requests).should_receive('get').with_args(
|
||||
f'{CUSTOM_BASE_URL}?status=up&msg=start'
|
||||
f'{CUSTOM_PUSH_URL}?status=up&msg=start'
|
||||
).and_return(flexmock(ok=True)).once()
|
||||
|
||||
module.ping_monitor(
|
||||
|
@ -53,9 +54,9 @@ def test_ping_monitor_custom_uptimekuma_on_start():
|
|||
)
|
||||
|
||||
def test_ping_monitor_custom_uptimekuma_on_finish():
|
||||
hook_config = {'push_url': CUSTOM_BASE_URL}
|
||||
hook_config = {'push_url': CUSTOM_PUSH_URL}
|
||||
flexmock(module.requests).should_receive('get').with_args(
|
||||
f'{CUSTOM_BASE_URL}?status=up&msg=finish'
|
||||
f'{CUSTOM_PUSH_URL}?status=up&msg=finish'
|
||||
).and_return(flexmock(ok=True)).once()
|
||||
|
||||
module.ping_monitor(
|
||||
|
@ -68,7 +69,7 @@ def test_ping_monitor_custom_uptimekuma_on_finish():
|
|||
)
|
||||
|
||||
def test_ping_monitor_does_not_hit_custom_uptimekuma_on_fail_dry_run():
|
||||
hook_config = {'push_url': CUSTOM_BASE_URL}
|
||||
hook_config = {'push_url': CUSTOM_PUSH_URL}
|
||||
flexmock(module.requests).should_receive('get').never()
|
||||
|
||||
module.ping_monitor(
|
||||
|
@ -81,7 +82,7 @@ def test_ping_monitor_does_not_hit_custom_uptimekuma_on_fail_dry_run():
|
|||
)
|
||||
|
||||
def test_ping_monitor_does_not_hit_custom_uptimekuma_on_start_dry_run():
|
||||
hook_config = {'push_url': CUSTOM_BASE_URL}
|
||||
hook_config = {'push_url': CUSTOM_PUSH_URL}
|
||||
flexmock(module.requests).should_receive('get').never()
|
||||
|
||||
module.ping_monitor(
|
||||
|
@ -94,7 +95,7 @@ def test_ping_monitor_does_not_hit_custom_uptimekuma_on_start_dry_run():
|
|||
)
|
||||
|
||||
def test_ping_monitor_does_not_hit_custom_uptimekuma_on_finish_dry_run():
|
||||
hook_config = {'push_url': CUSTOM_BASE_URL}
|
||||
hook_config = {'push_url': CUSTOM_PUSH_URL}
|
||||
flexmock(module.requests).should_receive('get').never()
|
||||
|
||||
module.ping_monitor(
|
||||
|
@ -108,8 +109,9 @@ def test_ping_monitor_does_not_hit_custom_uptimekuma_on_finish_dry_run():
|
|||
|
||||
|
||||
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'{DEFAULT_BASE_URL}?status=down&msg=fail'
|
||||
f'{CUSTOM_PUSH_URL}?status=down&msg=fail'
|
||||
).and_raise(module.requests.exceptions.ConnectionError)
|
||||
flexmock(module.logger).should_receive('warning').once()
|
||||
|
||||
|
@ -123,12 +125,13 @@ def test_ping_monitor_with_connection_error_logs_warning():
|
|||
)
|
||||
|
||||
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('post').with_args(
|
||||
f'{DEFAULT_BASE_URL}?status=down&msg=fail'
|
||||
f'{CUSTOM_PUSH_URL}?status=down&msg=fail'
|
||||
).and_return(response)
|
||||
flexmock(module.logger).should_receive('warning').once()
|
||||
|
||||
|
@ -142,7 +145,7 @@ def test_ping_monitor_with_other_error_logs_warning():
|
|||
)
|
||||
|
||||
def test_ping_monitor_with_invalid_run_state():
|
||||
hook_config = {'push_url': CUSTOM_BASE_URL}
|
||||
hook_config = {'push_url': CUSTOM_PUSH_URL}
|
||||
flexmock(module.requests).should_receive('get').never()
|
||||
|
||||
module.ping_monitor(
|
||||
|
|
Loading…
Reference in a new issue