async def test_handle_message_dispatch(randint): bot = SlackBot(None, None, None) mock_message = mock.Mock(data='{"channel": 123}') mock_socket = mock.MagicMock() bot.socket = mock_socket dummy_response = 'bar' await bot.handle_message(mock_message, [Handled(dummy_response)]) expected = dict( channel=123, id=randint.return_value, text=dummy_response, type='message', ) assert json.loads(mock_socket.send_str.call_args[0][0]) == expected
async def test_handle_version_message(randint): bot = SlackBot('foo', None, None) mock_msg = mock.Mock( data=json.dumps( dict(channel='bar', text='<@foo>: version', type='message'), ), ) expected = dict( channel='bar', id=randint.return_value, text=bot.VERSION, type='message', ) mock_socket = mock.MagicMock() bot.socket = mock_socket await bot.handle_message(mock_msg, []) assert json.loads(mock_socket.send_str.call_args[0][0]) == expected