From cb7c3d7ff4f4591335b42ac12ae63a36d05e57a7 Mon Sep 17 00:00:00 2001 From: Diego Cepeda Date: Tue, 20 Jul 2021 14:49:51 -0700 Subject: [PATCH] fix tests and incident id insert in slack message --- src/iris/vendors/iris_slack.py | 6 ++++-- test/test_iris_vendor_slack.py | 5 +---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/iris/vendors/iris_slack.py b/src/iris/vendors/iris_slack.py index a3d2b3b9..ebc3b797 100644 --- a/src/iris/vendors/iris_slack.py +++ b/src/iris/vendors/iris_slack.py @@ -57,13 +57,13 @@ def construct_attachment(self, message): return { 'fallback': self.message_attachments.get('fallback'), 'pretext': self.message_attachments.get('pretext'), - 'title': 'Iris incident %r' % message['incident_id'], + 'title': 'Iris incident %r' % message.get('incident_id'), 'mrkdwn_in': ['pretext'], 'attachment_type': 'default', 'callback_id': message.get('message_id'), 'color': 'danger', 'title_link': '%s/%s' % ( - self.config['iris_incident_url'], message['incident_id']), + self.config['iris_incident_url'], message.get('incident_id')), 'actions': [ { 'name': 'claim', @@ -108,6 +108,8 @@ def get_message_payload(self, message): slack_message.get('text', '')) # For incidents, add the Iris attachments at the end if 'incident_id' in message: + slack_message['incident_id'] = message.get('incident_id') + slack_message['message_id'] = message.get('message_id') slack_message.setdefault('attachments', []).append(self.construct_attachment(slack_message)) return slack_message diff --git a/test/test_iris_vendor_slack.py b/test/test_iris_vendor_slack.py index dc7596d3..11f6eee0 100644 --- a/test/test_iris_vendor_slack.py +++ b/test/test_iris_vendor_slack.py @@ -2,7 +2,6 @@ # -*- coding:utf-8 -*- from iris.vendors.iris_slack import iris_slack -import ujson as json def test_atttachments_construction_for_incident(): @@ -23,11 +22,10 @@ def test_atttachments_construction_for_incident(): } msg_payload = slack_vendor.get_message_payload(fake_msg) assert msg_payload['text'] == '[grafana] %s' % fake_msg['body'] - assert msg_payload['token'] == 'abc' assert msg_payload['channel'] == '@user1' attachments = msg_payload['attachments'] - assert json.loads(attachments) == [{ + assert attachments == [{ 'fallback': 'foo fallback', 'pretext': 'foo pretext', 'title': 'Iris incident %r' % fake_msg['incident_id'], @@ -77,6 +75,5 @@ def test_atttachments_construction_for_notification(): msg_payload = slack_vendor.get_message_payload(fake_msg) assert msg_payload == { 'text': '[grafana] %s' % fake_msg['body'], - 'token': 'abc', 'channel': '@user1' }