浏览代码

added missing tests to get 100% test coverage

Antonio Fernandez 7 月之前
父节点
当前提交
ea47704d86
共有 1 个文件被更改,包括 36 次插入0 次删除
  1. 36 0
      tests/unit/hooks/test_pushover.py

+ 36 - 0
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,
+    )