Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Fix triagebot mq format (#1627)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcrose committed May 12, 2020
1 parent ae17a0a commit 7ab2665
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions mq/plugins/triage_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ def process(msg, meta, api_cfg):
if not update_succeeded:
return (None, None)

# Transform the message before sending it back to ES. The `user` field
# in particular is reserved, so we will expand ours' contents out.
del msg["details"]["user"]
msg["details"]["email"] = email
msg["details"]["slack"] = slack

return (msg, meta)


Expand Down
28 changes: 27 additions & 1 deletion tests/mq/plugins/test_triage_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,33 @@ def test_process_invokes_update_for_good_messages(self):
mock.post(cfg.url + "/alertstatus", json={"error": None})
(new_msg, new_meta) = bot.process(msg, {}, cfg)

assert new_msg == msg
def test_process_reformats_messages_for_elasticsearch(self):
msg = {
"details": {
"identifier": "id",
"user": {
"email": "tester@site.com",
"slack": "tester",
},
"identityConfidence": "high",
"response": "yes",
},
}

cfg = bot.RESTConfig("http://mock.site", "token")

with requests_mock.mock() as mock:
mock.post(cfg.url + "/alertstatus", json={"error": None})
(new_msg, new_meta) = bot.process(msg, {}, cfg)

assert "user" not in msg["details"]
assert msg["details"] == {
"identifier": "id",
"email": "tester@site.com",
"slack": "tester",
"identityConfidence": "high",
"response": "yes",
}


class TestLambda:
Expand Down

0 comments on commit 7ab2665

Please sign in to comment.