Skip to content
Snippets Groups Projects
Commit e3fd45ab authored by Cody Messick's avatar Cody Messick
Browse files

Add temporary fix to igwn_alert task

parent f7db3ba4
No related branches found
No related tags found
1 merge request!887Add temporary fix to igwn_alert task
"""IGWN alert client."""
import json
from celery.utils.log import get_task_logger
from ..igwn_alert.signals import igwn_alert_received
......@@ -18,7 +20,12 @@ class _IGWNAlertDispatchHandler(DispatchHandler):
igwn_alert_topics.update(keys)
return super().__call__(*keys, **kwargs)
def process_args(self, topic, alert):
def process_args(self, topic, message):
# FIXME: Loading the message with json.loads() is a change required
# because we are using a newer version of hop-client than IGWN-Alert
# is, once IGWN-Alert upgrades to the newest version the message may
# become a dictionary once again
alert = json.loads(message.content)
# Determine GraceDB service URL
try:
try:
......
......@@ -3,7 +3,7 @@ import json
import logging
import os
import stat
from unittest.mock import patch
from unittest.mock import Mock, patch
import lxml
import pytest
......@@ -54,7 +54,12 @@ def test_handle_messages(mock_superevents_handle, mock_get_event,
alert['object']['self'].replace('gracedb.ligo.org', 'gracedb.invalid')
# Run function under test
igwn_alert.handler.dispatch(node, alert)
# FIXME: We need to mock the content attribute of a JSONBlob because we
# IGWN-Alert does not yet use hop-client 0.6.0. Once IGWN-Alert updates
# that dep we will probably be able to drop this mock
mock_message = Mock()
mock_message.content = json.dumps(alert)
igwn_alert.handler.dispatch(node, mock_message)
mock_superevents_handle.assert_called_once()
......@@ -72,8 +77,13 @@ def test_handle_messages_wrong_server(mock_superevents_handle,
alert['object']['self'].replace('gracedb.ligo.org', 'gracedb2.invalid')
# Run function under test
# FIXME: We need to mock the content attribute of a JSONBlob because we
# IGWN-Alert does not yet use hop-client 0.6.0. Once IGWN-Alert updates
# that dep we will probably be able to drop this mock
mock_message = Mock()
mock_message.content = json.dumps(alert)
caplog.set_level(logging.WARNING)
igwn_alert.handler.dispatch(node, alert)
igwn_alert.handler.dispatch(node, mock_message)
record, *_ = caplog.records
assert record.message == ('ignoring IGWN alert message because it is '
'intended for GraceDB server '
......@@ -95,8 +105,13 @@ def test_handle_messages_no_self_link(mock_superevents_handle,
del alert['object']['self']
# Run function under test
# FIXME: We need to mock the content attribute of a JSONBlob because we
# IGWN-Alert does not yet use hop-client 0.6.0. Once IGWN-Alert updates
# that dep we will probably be able to drop this mock
mock_message = Mock()
mock_message.content = json.dumps(alert)
caplog.set_level(logging.ERROR)
igwn_alert.handler.dispatch(node, alert)
igwn_alert.handler.dispatch(node, mock_message)
record, = caplog.records
assert 'IGWN alert message does not contain an API URL' in record.message
mock_superevents_handle.assert_not_called()
......@@ -59,7 +59,7 @@ gracedb-sdk = ">=0.1.5"
gwdatafind = ">=1.1.1"
gwpy = ">=2.0.1" # https://github.com/gwpy/gwpy/issues/1277
healpy = "*"
igwn-alert = "*"
igwn-alert = "0.2.1"
imapclient = "*"
importlib-metadata = { version = "*", python = "<3.8" }
jinja2 = ">=2.11.2" # https://github.com/pallets/jinja/issues/1168
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment