bots: Simplify test_yoda.py.
This commit is contained in:
		
							parent
							
								
									20cb236fdd
								
							
						
					
					
						commit
						060211a131
					
				
					 1 changed files with 27 additions and 74 deletions
				
			
		|  | @ -1,18 +1,9 @@ | ||||||
| #!/usr/bin/env python | from zulip_bots.test_lib import StubBotTestCase | ||||||
| 
 | 
 | ||||||
| from __future__ import absolute_import | class TestYodaBot(StubBotTestCase): | ||||||
| from __future__ import print_function |  | ||||||
| 
 |  | ||||||
| import json |  | ||||||
| 
 |  | ||||||
| from zulip_bots.test_lib import BotTestCase |  | ||||||
| 
 |  | ||||||
| class TestYodaBot(BotTestCase): |  | ||||||
|     bot_name = "yoda" |     bot_name = "yoda" | ||||||
| 
 | 
 | ||||||
|     # Override default function in StubBotTestCase |     help_text = ''' | ||||||
|     def test_bot_responds_to_empty_message(self): |  | ||||||
|         bot_response = ''' |  | ||||||
|             This bot allows users to translate a sentence into |             This bot allows users to translate a sentence into | ||||||
|             'Yoda speak'. |             'Yoda speak'. | ||||||
|             Users should preface messages with '@mention-bot'. |             Users should preface messages with '@mention-bot'. | ||||||
|  | @ -25,77 +16,39 @@ class TestYodaBot(BotTestCase): | ||||||
|             Example input: |             Example input: | ||||||
|             @mention-bot You will learn how to speak like me someday. |             @mention-bot You will learn how to speak like me someday. | ||||||
|             ''' |             ''' | ||||||
|         self.assert_bot_response( | 
 | ||||||
|             message = {'content': ''}, |     def _test(self, message, response, fixture=None): | ||||||
|             response = {'content': bot_response}, |         with self.mock_config_info({'api_key': '12345678'}): | ||||||
|             expected_method='send_reply' |             if fixture is not None: | ||||||
|         ) |                 with self.mock_http_conversation(fixture): | ||||||
|  |                     self.verify_reply(message, response) | ||||||
|  |             else: | ||||||
|  |                 self.verify_reply(message, response) | ||||||
|  | 
 | ||||||
|  |     # Override default function in StubBotTestCase | ||||||
|  |     def test_bot_responds_to_empty_message(self): | ||||||
|  |         self._test('', self.help_text) | ||||||
| 
 | 
 | ||||||
|     def test_bot(self): |     def test_bot(self): | ||||||
| 
 | 
 | ||||||
|         # Test normal sentence (1). |         # Test normal sentence (1). | ||||||
|         bot_response = "Learn how to speak like me someday, you will. Yes, hmmm." |         self._test('You will learn how to speak like me someday.', | ||||||
| 
 |                    "Learn how to speak like me someday, you will. Yes, hmmm.", | ||||||
|         with self.mock_config_info({'api_key': '12345678'}), \ |                    'test_1') | ||||||
|                 self.mock_http_conversation('test_1'): |  | ||||||
|             self.initialize_bot() |  | ||||||
|             self.assert_bot_response( |  | ||||||
|                 message = {'content': 'You will learn how to speak like me someday.'}, |  | ||||||
|                 response = {'content': bot_response}, |  | ||||||
|                 expected_method='send_reply' |  | ||||||
|             ) |  | ||||||
| 
 | 
 | ||||||
|         # Test normal sentence (2). |         # Test normal sentence (2). | ||||||
|         bot_response = "Much to learn, you still have." |         self._test('you still have much to learn', | ||||||
| 
 |                    "Much to learn, you still have.", | ||||||
|         with self.mock_config_info({'api_key': '12345678'}), \ |                    'test_2') | ||||||
|                 self.mock_http_conversation('test_2'): |  | ||||||
|             self.initialize_bot() |  | ||||||
|             self.assert_bot_response( |  | ||||||
|                 message = {'content': 'you still have much to learn'}, |  | ||||||
|                 response = {'content': bot_response}, |  | ||||||
|                 expected_method='send_reply' |  | ||||||
|             ) |  | ||||||
| 
 | 
 | ||||||
|         # Test only numbers. |         # Test only numbers. | ||||||
|         bot_response = "23456.  Herh herh herh." |         self._test('23456', "23456.  Herh herh herh.", | ||||||
| 
 |                    'test_only_numbers') | ||||||
|         with self.mock_config_info({'api_key': '12345678'}), \ |  | ||||||
|                 self.mock_http_conversation('test_only_numbers'): |  | ||||||
|             self.initialize_bot() |  | ||||||
|             self.assert_bot_response( |  | ||||||
|                 message = {'content': '23456'}, |  | ||||||
|                 response = {'content': bot_response}, |  | ||||||
|                 expected_method='send_reply' |  | ||||||
|             ) |  | ||||||
| 
 | 
 | ||||||
|         # Test help. |         # Test help. | ||||||
|         bot_response = ''' |         self._test('help', self.help_text) | ||||||
|             This bot allows users to translate a sentence into |  | ||||||
|             'Yoda speak'. |  | ||||||
|             Users should preface messages with '@mention-bot'. |  | ||||||
| 
 |  | ||||||
|             Before running this, make sure to get a Mashape Api token. |  | ||||||
|             Instructions are in the 'readme.md' file. |  | ||||||
|             Store it in the 'yoda.conf' file. |  | ||||||
|             The 'yoda.conf' file should be located in this bot's (zulip_bots/bots/yoda/yoda) |  | ||||||
|             directory. |  | ||||||
|             Example input: |  | ||||||
|             @mention-bot You will learn how to speak like me someday. |  | ||||||
|             ''' |  | ||||||
|         self.assert_bot_response( |  | ||||||
|             message = {'content': 'help'}, |  | ||||||
|             response = {'content': bot_response}, |  | ||||||
|             expected_method='send_reply' |  | ||||||
|         ) |  | ||||||
| 
 | 
 | ||||||
|         # Test invalid input. |         # Test invalid input. | ||||||
|         bot_response = "Invalid input, please check the sentence you have entered." |         self._test('@#$%^&*', | ||||||
|         with self.mock_config_info({'api_key': '12345678'}), \ |                    "Invalid input, please check the sentence you have entered.", | ||||||
|                 self.mock_http_conversation('test_invalid_input'): |                    'test_invalid_input') | ||||||
|             self.initialize_bot() |  | ||||||
|             self.assert_bot_response( |  | ||||||
|                 message = {'content': '@#$%^&*'}, |  | ||||||
|                 response = {'content': bot_response}, |  | ||||||
|                 expected_method='send_reply' |  | ||||||
|             ) |  | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 neiljp (Neil Pilgrim)
						neiljp (Neil Pilgrim)