def test_process_reformats_messages_for_elasticsearch(self): msg = { "details": { "identifier": "id", "user": { "email": "*****@*****.**", "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": "*****@*****.**", "slack": "tester", "identityConfidence": "high", "userresponse": "yes", }
def test_process_invokes_update_for_good_messages(self): msg = { "details": { "identifier": "id", "user": { "email": "*****@*****.**", "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 len(mock.request_history) == 1 req_json = mock.request_history[0].json() assert req_json == { "alert": "id", "status": "acknowledged", "user": { "email": "*****@*****.**", "slack": "tester", }, "identityConfidence": "high", "response": "yes", }
def test_process_rejects_bad_messages(self): msg = {"details": {"identifier": "test"}} cfg = bot.RESTConfig("", "") (new_msg, new_meta) = bot.process(msg, {}, cfg) assert new_msg is None assert new_meta is None
def test_update_alert_status_request_success(self): with requests_mock.mock() as mock: url = "http://mock.site" cfg = bot.RESTConfig(url, "token") msg = bot.UserResponseMessage( "id", bot.UserInfo("*****@*****.**", "tester"), bot.Confidence.HIGH, bot.UserResponse.YES, ) mock.post(url + "/alertstatus", json={"error": None}) succeeded = bot.update_alert_status(msg, cfg) assert succeeded