Add tests and bugfix for b'' messages appearing in python3.
I added unicode and non-unicode message testing for the output() method
on RTMBot. I'm concerned about why the encode('ascii', 'ignore') was
there in the first place, but not having it seems to do the right
thing...
			
			
This commit is contained in:
		
							parent
							
								
									1a4b96584e
								
							
						
					
					
						commit
						2b9e9b752c
					
				
					 4 changed files with 47 additions and 9 deletions
				
			
		|  | @ -1,6 +1,7 @@ | |||
| coveralls==1.1 | ||||
| ipdb==0.9.3 | ||||
| ipython==4.1.2 | ||||
| mock==2.0.0 | ||||
| pdbpp==0.8.3 | ||||
| pytest>=2.8.2 | ||||
| pytest-cov==2.2.1 | ||||
|  |  | |||
|  | @ -101,7 +101,7 @@ class RtmBot(object): | |||
|                     if limiter: | ||||
|                         time.sleep(.1) | ||||
|                         limiter = False | ||||
|                     message = output[1].encode('ascii', 'ignore') | ||||
|                     message = output[1] | ||||
|                     channel.send_message("{}".format(message)) | ||||
|                     limiter = True | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,2 +0,0 @@ | |||
| def test_example(): | ||||
| 	assert True | ||||
|  | @ -1,15 +1,25 @@ | |||
| # -*- coding: utf-8 -*- | ||||
| try: | ||||
|     from unittest.mock import Mock | ||||
| except ImportError: | ||||
|     from mock import Mock | ||||
| 
 | ||||
| from testfixtures import LogCapture | ||||
| from rtmbot.core import RtmBot | ||||
| 
 | ||||
| def init_rtmbot(): | ||||
|     ''' Initializes an instance of RTMBot with some default values ''' | ||||
|     rtmbot = RtmBot({ | ||||
|         'SLACK_TOKEN': 'test-12345', | ||||
|         'BASE_PATH': '/tmp/', | ||||
|         'LOGFILE': '/tmp/rtmbot.log', | ||||
|         'DEBUG': True | ||||
|     }) | ||||
|     return rtmbot | ||||
| 
 | ||||
| def test_init(): | ||||
|     with LogCapture() as l: | ||||
|         rtmbot = RtmBot({ | ||||
|             'SLACK_TOKEN': 'test-12345', | ||||
|             'BASE_PATH': '/tmp/', | ||||
|             'LOGFILE': '/tmp/rtmbot.log', | ||||
|             'DEBUG': True | ||||
|         }) | ||||
|         rtmbot = init_rtmbot() | ||||
| 
 | ||||
|     assert rtmbot.token == 'test-12345' | ||||
|     assert rtmbot.directory == '/tmp/' | ||||
|  | @ -18,3 +28,32 @@ def test_init(): | |||
|     l.check( | ||||
|         ('root', 'INFO', 'Initialized in: /tmp/') | ||||
|     ) | ||||
| 
 | ||||
| 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() | ||||
|     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.do_output.return_value = [['C12345678', 'test message']] | ||||
|     rtmbot.bot_plugins.append(plugin_mock) | ||||
| 
 | ||||
|     rtmbot.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 | ||||
|     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') | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jeff Ammons
						Jeff Ammons