Fix unicode error in py2.7 for example plugin

Strings should now be passed to the plugins as unicode values in py2.7
so we have to make sure that we don't convert those into ascii by using
python str instead of u'' strings.
This commit is contained in:
Jeff Ammons 2016-06-05 13:28:28 -07:00
parent 2b9e9b752c
commit c81bdfec99
8 changed files with 41 additions and 11 deletions

View file

@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-
try:
from unittest.mock import Mock
from unittest.mock import Mock, create_autospec
except ImportError:
from mock import Mock
from mock import Mock, create_autospec
from testfixtures import LogCapture
from rtmbot.core import RtmBot
from slackclient import SlackClient, _channel, _server, _util
from rtmbot.core import RtmBot, Plugin
def init_rtmbot():
''' Initializes an instance of RTMBot with some default values '''
@ -33,14 +34,21 @@ def test_output():
''' Test that sending a message behaves as expected '''
rtmbot = init_rtmbot()
# Mock the slack_client object
slackclient_mock = Mock()
channel_mock = Mock()
# Mock the slack_client object with Server, Channel objects and needed methods
slackclient_mock = create_autospec(SlackClient)
server_mock = create_autospec(_server.Server)
# Mock Server with channels method and correct return value
slackclient_mock.server = server_mock
searchlist_mock = create_autospec(_util.SearchList)
server_mock.channels = searchlist_mock
channel_mock = create_autospec(_channel.Channel)
slackclient_mock.server.channels.find.return_value = channel_mock
rtmbot.slack_client = slackclient_mock
# mock the plugin object to return a sample response
plugin_mock = Mock()
plugin_mock = create_autospec(Plugin)
plugin_mock.do_output.return_value = [['C12345678', 'test message']]
rtmbot.bot_plugins.append(plugin_mock)
@ -50,10 +58,18 @@ def test_output():
# test that the output matches the expected value
channel_mock.send_message.assert_called_with('test message')
# test that unicode messages work as expected
# test that emoji messages work as expected
channel_mock.reset_mock()
plugin_mock.reset_mock()
plugin_mock.do_output.return_value = [['C12345678', '🚀 testing']]
rtmbot.output()
channel_mock.send_message.assert_called_with('🚀 testing')
# test that unicode messages work as expected
channel_mock.reset_mock()
plugin_mock.reset_mock()
plugin_mock.do_output.return_value = [['C12345678', 'ù hœø3ö']]
rtmbot.output()
channel_mock.send_message.assert_called_with('ù hœø3ö')