def test_alert(self): alerter = slack_alert.SlackAlerter() params = { 'channel': '#oncall', 'from': 'ZK Monitor Test', 'token': 'unittest' } post_message_mock = mock.MagicMock(name='chat_postMessage') post_message_mock.http_post = helper.mock_tornado(value='test') slack_mock = mock.MagicMock(name='SlackAPI') slack_mock.chat_postMessage.side_effect = post_message_mock with mock.patch.object(slack, 'Slack') as slack_mock: # Mock out the chat_postMessage().http_post() method m = helper.mock_tornado('test_value') slack_mock().chat_postMessage().http_post = m ret = yield alerter._alert('/test', states.OK, 'Happy', params) self.assertEquals(ret, slack_mock().check_results()) self.assertEquals( slack_mock().chat_postMessage().http_post._call_count, 1)
def test_alert_raises_exc(self): alerter = slack_alert.SlackAlerter() params = { 'channel': '#oncall', 'from': 'ZK Monitor Test', 'token': 'unittest' } post_message_mock = mock.MagicMock(name='chat_postMessage') post_message_mock.http_post = helper.mock_tornado(value='test') slack_mock = mock.MagicMock(name='SlackAPI') slack_mock.chat_postMessage.side_effect = post_message_mock with mock.patch.object(slack, 'Slack') as slack_mock: # Mock out the chat_postMessage().http_post() method exc = exceptions.InvalidCredentials('Boom') slack_mock().chat_postMessage().http_post.side_effect = exc ret = yield alerter._alert('/test', states.OK, 'Happy', params) self.assertEquals(ret, None)