From ea47704d86b9c3ebe3e412144f1c0d4459e9b79b Mon Sep 17 00:00:00 2001 From: Antonio Fernandez Date: Wed, 13 Nov 2024 12:09:25 -0500 Subject: [PATCH] added missing tests to get 100% test coverage --- tests/unit/hooks/test_pushover.py | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/unit/hooks/test_pushover.py b/tests/unit/hooks/test_pushover.py index a62cd9d3..3f14a5f1 100644 --- a/tests/unit/hooks/test_pushover.py +++ b/tests/unit/hooks/test_pushover.py @@ -506,3 +506,39 @@ def test_ping_monitor_config_incorrect_state_exit_early(): monitoring_log_level=1, dry_run=True, ) + + +def test_ping_monitor_push_post_error_exits_early(): + ''' + This test simulates the Pushover servers not responding with a 200 OK. We + should raise for status and warn then exit. + ''' + hook_config = hook_config = { + 'token': 'ksdjfwoweijfvwoeifvjmwghagy92', + 'user': '983hfe0of902lkjfa2amanfgui', + } + + push_response = flexmock(ok=False) + push_response.should_receive('raise_for_status').and_raise( + module.requests.ConnectionError + ).once() + flexmock(module.requests).should_receive('post').with_args( + 'https://api.pushover.net/1/messages.json', + headers={'Content-type': 'application/x-www-form-urlencoded'}, + data={ + 'token': 'ksdjfwoweijfvwoeifvjmwghagy92', + 'user': '983hfe0of902lkjfa2amanfgui', + 'message': 'fail', + }, + ).and_return(push_response).once() + + 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, + )