|
@@ -2,6 +2,7 @@ from enum import Enum
|
|
|
|
|
|
from flexmock import flexmock
|
|
from flexmock import flexmock
|
|
|
|
|
|
|
|
+import borgmatic.hooks.monitor
|
|
from borgmatic.hooks import ntfy as module
|
|
from borgmatic.hooks import ntfy as module
|
|
|
|
|
|
default_base_url = 'https://ntfy.sh'
|
|
default_base_url = 'https://ntfy.sh'
|
|
@@ -37,12 +38,16 @@ def test_ping_monitor_minimal_config_hits_hosted_ntfy_on_fail():
|
|
hook_config = {'topic': topic}
|
|
hook_config = {'topic': topic}
|
|
flexmock(module.requests).should_receive('post').with_args(
|
|
flexmock(module.requests).should_receive('post').with_args(
|
|
f'{default_base_url}/{topic}',
|
|
f'{default_base_url}/{topic}',
|
|
- headers=return_default_message_headers(module.monitor.State.FAIL),
|
|
|
|
|
|
+ headers=return_default_message_headers(borgmatic.hooks.monitor.State.FAIL),
|
|
auth=None,
|
|
auth=None,
|
|
).and_return(flexmock(ok=True)).once()
|
|
).and_return(flexmock(ok=True)).once()
|
|
|
|
|
|
module.ping_monitor(
|
|
module.ping_monitor(
|
|
- hook_config, 'config.yaml', module.monitor.State.FAIL, monitoring_log_level=1, dry_run=False
|
|
|
|
|
|
+ hook_config,
|
|
|
|
+ 'config.yaml',
|
|
|
|
+ borgmatic.hooks.monitor.State.FAIL,
|
|
|
|
+ monitoring_log_level=1,
|
|
|
|
+ dry_run=False,
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -54,12 +59,16 @@ def test_ping_monitor_with_auth_hits_hosted_ntfy_on_fail():
|
|
}
|
|
}
|
|
flexmock(module.requests).should_receive('post').with_args(
|
|
flexmock(module.requests).should_receive('post').with_args(
|
|
f'{default_base_url}/{topic}',
|
|
f'{default_base_url}/{topic}',
|
|
- headers=return_default_message_headers(module.monitor.State.FAIL),
|
|
|
|
|
|
+ headers=return_default_message_headers(borgmatic.hooks.monitor.State.FAIL),
|
|
auth=module.requests.auth.HTTPBasicAuth('testuser', 'fakepassword'),
|
|
auth=module.requests.auth.HTTPBasicAuth('testuser', 'fakepassword'),
|
|
).and_return(flexmock(ok=True)).once()
|
|
).and_return(flexmock(ok=True)).once()
|
|
|
|
|
|
module.ping_monitor(
|
|
module.ping_monitor(
|
|
- hook_config, 'config.yaml', module.monitor.State.FAIL, monitoring_log_level=1, dry_run=False
|
|
|
|
|
|
+ hook_config,
|
|
|
|
+ 'config.yaml',
|
|
|
|
+ borgmatic.hooks.monitor.State.FAIL,
|
|
|
|
+ monitoring_log_level=1,
|
|
|
|
+ dry_run=False,
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -67,13 +76,17 @@ def test_ping_monitor_auth_with_no_username_warning():
|
|
hook_config = {'topic': topic, 'password': 'fakepassword'}
|
|
hook_config = {'topic': topic, 'password': 'fakepassword'}
|
|
flexmock(module.requests).should_receive('post').with_args(
|
|
flexmock(module.requests).should_receive('post').with_args(
|
|
f'{default_base_url}/{topic}',
|
|
f'{default_base_url}/{topic}',
|
|
- headers=return_default_message_headers(module.monitor.State.FAIL),
|
|
|
|
|
|
+ headers=return_default_message_headers(borgmatic.hooks.monitor.State.FAIL),
|
|
auth=None,
|
|
auth=None,
|
|
).and_return(flexmock(ok=True)).once()
|
|
).and_return(flexmock(ok=True)).once()
|
|
flexmock(module.logger).should_receive('warning').once()
|
|
flexmock(module.logger).should_receive('warning').once()
|
|
|
|
|
|
module.ping_monitor(
|
|
module.ping_monitor(
|
|
- hook_config, 'config.yaml', module.monitor.State.FAIL, monitoring_log_level=1, dry_run=False
|
|
|
|
|
|
+ hook_config,
|
|
|
|
+ 'config.yaml',
|
|
|
|
+ borgmatic.hooks.monitor.State.FAIL,
|
|
|
|
+ monitoring_log_level=1,
|
|
|
|
+ dry_run=False,
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -81,13 +94,17 @@ def test_ping_monitor_auth_with_no_password_warning():
|
|
hook_config = {'topic': topic, 'username': 'testuser'}
|
|
hook_config = {'topic': topic, 'username': 'testuser'}
|
|
flexmock(module.requests).should_receive('post').with_args(
|
|
flexmock(module.requests).should_receive('post').with_args(
|
|
f'{default_base_url}/{topic}',
|
|
f'{default_base_url}/{topic}',
|
|
- headers=return_default_message_headers(module.monitor.State.FAIL),
|
|
|
|
|
|
+ headers=return_default_message_headers(borgmatic.hooks.monitor.State.FAIL),
|
|
auth=None,
|
|
auth=None,
|
|
).and_return(flexmock(ok=True)).once()
|
|
).and_return(flexmock(ok=True)).once()
|
|
flexmock(module.logger).should_receive('warning').once()
|
|
flexmock(module.logger).should_receive('warning').once()
|
|
|
|
|
|
module.ping_monitor(
|
|
module.ping_monitor(
|
|
- hook_config, 'config.yaml', module.monitor.State.FAIL, monitoring_log_level=1, dry_run=False
|
|
|
|
|
|
+ hook_config,
|
|
|
|
+ 'config.yaml',
|
|
|
|
+ borgmatic.hooks.monitor.State.FAIL,
|
|
|
|
+ monitoring_log_level=1,
|
|
|
|
+ dry_run=False,
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -98,7 +115,7 @@ def test_ping_monitor_minimal_config_does_not_hit_hosted_ntfy_on_start():
|
|
module.ping_monitor(
|
|
module.ping_monitor(
|
|
hook_config,
|
|
hook_config,
|
|
'config.yaml',
|
|
'config.yaml',
|
|
- module.monitor.State.START,
|
|
|
|
|
|
+ borgmatic.hooks.monitor.State.START,
|
|
monitoring_log_level=1,
|
|
monitoring_log_level=1,
|
|
dry_run=False,
|
|
dry_run=False,
|
|
)
|
|
)
|
|
@@ -111,7 +128,7 @@ def test_ping_monitor_minimal_config_does_not_hit_hosted_ntfy_on_finish():
|
|
module.ping_monitor(
|
|
module.ping_monitor(
|
|
hook_config,
|
|
hook_config,
|
|
'config.yaml',
|
|
'config.yaml',
|
|
- module.monitor.State.FINISH,
|
|
|
|
|
|
+ borgmatic.hooks.monitor.State.FINISH,
|
|
monitoring_log_level=1,
|
|
monitoring_log_level=1,
|
|
dry_run=False,
|
|
dry_run=False,
|
|
)
|
|
)
|
|
@@ -121,12 +138,16 @@ def test_ping_monitor_minimal_config_hits_selfhosted_ntfy_on_fail():
|
|
hook_config = {'topic': topic, 'server': custom_base_url}
|
|
hook_config = {'topic': topic, 'server': custom_base_url}
|
|
flexmock(module.requests).should_receive('post').with_args(
|
|
flexmock(module.requests).should_receive('post').with_args(
|
|
f'{custom_base_url}/{topic}',
|
|
f'{custom_base_url}/{topic}',
|
|
- headers=return_default_message_headers(module.monitor.State.FAIL),
|
|
|
|
|
|
+ headers=return_default_message_headers(borgmatic.hooks.monitor.State.FAIL),
|
|
auth=None,
|
|
auth=None,
|
|
).and_return(flexmock(ok=True)).once()
|
|
).and_return(flexmock(ok=True)).once()
|
|
|
|
|
|
module.ping_monitor(
|
|
module.ping_monitor(
|
|
- hook_config, 'config.yaml', module.monitor.State.FAIL, monitoring_log_level=1, dry_run=False
|
|
|
|
|
|
+ hook_config,
|
|
|
|
+ 'config.yaml',
|
|
|
|
+ borgmatic.hooks.monitor.State.FAIL,
|
|
|
|
+ monitoring_log_level=1,
|
|
|
|
+ dry_run=False,
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -135,7 +156,11 @@ def test_ping_monitor_minimal_config_does_not_hit_hosted_ntfy_on_fail_dry_run():
|
|
flexmock(module.requests).should_receive('post').never()
|
|
flexmock(module.requests).should_receive('post').never()
|
|
|
|
|
|
module.ping_monitor(
|
|
module.ping_monitor(
|
|
- hook_config, 'config.yaml', module.monitor.State.FAIL, monitoring_log_level=1, dry_run=True
|
|
|
|
|
|
+ hook_config,
|
|
|
|
+ 'config.yaml',
|
|
|
|
+ borgmatic.hooks.monitor.State.FAIL,
|
|
|
|
+ monitoring_log_level=1,
|
|
|
|
+ dry_run=True,
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -146,7 +171,11 @@ def test_ping_monitor_custom_message_hits_hosted_ntfy_on_fail():
|
|
).and_return(flexmock(ok=True)).once()
|
|
).and_return(flexmock(ok=True)).once()
|
|
|
|
|
|
module.ping_monitor(
|
|
module.ping_monitor(
|
|
- hook_config, 'config.yaml', module.monitor.State.FAIL, monitoring_log_level=1, dry_run=False
|
|
|
|
|
|
+ hook_config,
|
|
|
|
+ 'config.yaml',
|
|
|
|
+ borgmatic.hooks.monitor.State.FAIL,
|
|
|
|
+ monitoring_log_level=1,
|
|
|
|
+ dry_run=False,
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -154,14 +183,14 @@ def test_ping_monitor_custom_state_hits_hosted_ntfy_on_start():
|
|
hook_config = {'topic': topic, 'states': ['start', 'fail']}
|
|
hook_config = {'topic': topic, 'states': ['start', 'fail']}
|
|
flexmock(module.requests).should_receive('post').with_args(
|
|
flexmock(module.requests).should_receive('post').with_args(
|
|
f'{default_base_url}/{topic}',
|
|
f'{default_base_url}/{topic}',
|
|
- headers=return_default_message_headers(module.monitor.State.START),
|
|
|
|
|
|
+ headers=return_default_message_headers(borgmatic.hooks.monitor.State.START),
|
|
auth=None,
|
|
auth=None,
|
|
).and_return(flexmock(ok=True)).once()
|
|
).and_return(flexmock(ok=True)).once()
|
|
|
|
|
|
module.ping_monitor(
|
|
module.ping_monitor(
|
|
hook_config,
|
|
hook_config,
|
|
'config.yaml',
|
|
'config.yaml',
|
|
- module.monitor.State.START,
|
|
|
|
|
|
+ borgmatic.hooks.monitor.State.START,
|
|
monitoring_log_level=1,
|
|
monitoring_log_level=1,
|
|
dry_run=False,
|
|
dry_run=False,
|
|
)
|
|
)
|
|
@@ -171,7 +200,7 @@ def test_ping_monitor_with_connection_error_logs_warning():
|
|
hook_config = {'topic': topic}
|
|
hook_config = {'topic': topic}
|
|
flexmock(module.requests).should_receive('post').with_args(
|
|
flexmock(module.requests).should_receive('post').with_args(
|
|
f'{default_base_url}/{topic}',
|
|
f'{default_base_url}/{topic}',
|
|
- headers=return_default_message_headers(module.monitor.State.FAIL),
|
|
|
|
|
|
+ headers=return_default_message_headers(borgmatic.hooks.monitor.State.FAIL),
|
|
auth=None,
|
|
auth=None,
|
|
).and_raise(module.requests.exceptions.ConnectionError)
|
|
).and_raise(module.requests.exceptions.ConnectionError)
|
|
flexmock(module.logger).should_receive('warning').once()
|
|
flexmock(module.logger).should_receive('warning').once()
|
|
@@ -179,7 +208,7 @@ def test_ping_monitor_with_connection_error_logs_warning():
|
|
module.ping_monitor(
|
|
module.ping_monitor(
|
|
hook_config,
|
|
hook_config,
|
|
'config.yaml',
|
|
'config.yaml',
|
|
- module.monitor.State.FAIL,
|
|
|
|
|
|
+ borgmatic.hooks.monitor.State.FAIL,
|
|
monitoring_log_level=1,
|
|
monitoring_log_level=1,
|
|
dry_run=False,
|
|
dry_run=False,
|
|
)
|
|
)
|
|
@@ -193,7 +222,7 @@ def test_ping_monitor_with_other_error_logs_warning():
|
|
)
|
|
)
|
|
flexmock(module.requests).should_receive('post').with_args(
|
|
flexmock(module.requests).should_receive('post').with_args(
|
|
f'{default_base_url}/{topic}',
|
|
f'{default_base_url}/{topic}',
|
|
- headers=return_default_message_headers(module.monitor.State.FAIL),
|
|
|
|
|
|
+ headers=return_default_message_headers(borgmatic.hooks.monitor.State.FAIL),
|
|
auth=None,
|
|
auth=None,
|
|
).and_return(response)
|
|
).and_return(response)
|
|
flexmock(module.logger).should_receive('warning').once()
|
|
flexmock(module.logger).should_receive('warning').once()
|
|
@@ -201,7 +230,7 @@ def test_ping_monitor_with_other_error_logs_warning():
|
|
module.ping_monitor(
|
|
module.ping_monitor(
|
|
hook_config,
|
|
hook_config,
|
|
'config.yaml',
|
|
'config.yaml',
|
|
- module.monitor.State.FAIL,
|
|
|
|
|
|
+ borgmatic.hooks.monitor.State.FAIL,
|
|
monitoring_log_level=1,
|
|
monitoring_log_level=1,
|
|
dry_run=False,
|
|
dry_run=False,
|
|
)
|
|
)
|