Skip to content

Commit

Permalink
Merge e197ae6 into b38bb14
Browse files Browse the repository at this point in the history
  • Loading branch information
mraspaud committed Aug 29, 2022
2 parents b38bb14 + e197ae6 commit dbe4c74
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions pytroll_monitor/monitor_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def send_message(self, status, msg):
"service_description": self.monitor_service,
"status_code": status,
"plugin_output": msg}
with requests.post(self.monitor_server,
auth=self.monitor_auth,
json=json_data) as response:
with requests.get(self.monitor_server,
auth=self.monitor_auth,
json=json_data) as response:
response.raise_for_status()
return response
15 changes: 8 additions & 7 deletions pytroll_monitor/tests/test_op5.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from pytroll_monitor.monitor_hook import OP5Monitor
from pytroll_monitor.op5_logger import OP5Handler
import yaml
import logging
import logging.config

import requests_mock
import yaml

from pytroll_monitor.monitor_hook import OP5Monitor
from pytroll_monitor.op5_logger import OP5Handler # noqa

yaml_config = """version: 1
disable_existing_loggers: false
Expand Down Expand Up @@ -50,19 +51,19 @@ def test_op5monitor_without_auth(self):
op5m = OP5Monitor(self.service, self.server, self.host, monitor_auth=None)

with requests_mock.Mocker() as m:
m.post(self.server, text=self.response_text)
m.get(self.server, text=self.response_text)
op5m.send_message(self.status, self.message)
assert m.last_request.json() == self.expected_json
assert m.last_request.url == self.server
assert m.last_request.method == "POST"
assert m.last_request.method == "GET"
assert "Authorization" not in m.last_request.headers

def test_op5monitor_with_auth(self):
"""Test the monitor with authentication."""
op5m = OP5Monitor(self.service, self.server, self.host, self.auth)

with requests_mock.Mocker() as m:
m.post(self.server, text=self.response_text)
m.get(self.server, text=self.response_text)
op5m.send_message(self.status, self.message)
assert m.last_request.headers["Authorization"] == self.expected_auth

Expand All @@ -73,7 +74,7 @@ def test_op5handler(self):
logging.config.dictConfig(log_dict)

with requests_mock.Mocker() as m:
m.post(self.server, text=self.response_text)
m.get(self.server, text=self.response_text)
logger.warning(self.message)
assert m.last_request.json() == self.expected_json
assert m.last_request.headers["Authorization"] == self.expected_auth

0 comments on commit dbe4c74

Please sign in to comment.