Fix formatting

This commit is contained in:
Matthias 2021-11-29 19:54:54 +01:00
parent 018407852a
commit dfb148f8d7
2 changed files with 6 additions and 3 deletions

View File

@ -79,7 +79,8 @@ class Webhook(RPCHandler):
attempts = 0 attempts = 0
while not success and attempts <= self._retries: while not success and attempts <= self._retries:
if attempts: if attempts:
if self._retry_delay: time.sleep(self._retry_delay) if self._retry_delay:
time.sleep(self._retry_delay)
logger.info("Retrying webhook...") logger.info("Retrying webhook...")
attempts += 1 attempts += 1
@ -90,10 +91,11 @@ class Webhook(RPCHandler):
elif self._format == 'json': elif self._format == 'json':
response = post(self._url, json=payload) response = post(self._url, json=payload)
elif self._format == 'raw': elif self._format == 'raw':
response = post(self._url, data=payload['data'], headers={'Content-Type': 'text/plain'}) response = post(self._url, data=payload['data'],
headers={'Content-Type': 'text/plain'})
else: else:
raise NotImplementedError('Unknown format: {}'.format(self._format)) raise NotImplementedError('Unknown format: {}'.format(self._format))
# Throw a RequestException if the post was not successful # Throw a RequestException if the post was not successful
response.raise_for_status() response.raise_for_status()
success = True success = True

View File

@ -293,6 +293,7 @@ def test__send_msg_with_json_format(default_conf, mocker, caplog):
assert post.call_args[1] == {'json': msg} assert post.call_args[1] == {'json': msg}
def test__send_msg_with_raw_format(default_conf, mocker, caplog): def test__send_msg_with_raw_format(default_conf, mocker, caplog):
default_conf["webhook"] = get_webhook_dict() default_conf["webhook"] = get_webhook_dict()
default_conf["webhook"]["format"] = "raw" default_conf["webhook"]["format"] = "raw"