示例#1
0
    def test_dispatch(self):
        bot = BaseBot(self.token)
        bot.commands = (
            (r'test_command (?P<test_param>[0-9]+)', 'test_command'),
        )

        def test_command(test_param):
            return test_param
        bot.test_command = test_command

        # Assign the testing command
        bot.__init__(self.token)

        # Test a valid command
        text = 'test_command 5'
        mock_slack_data = get_mock_slack_data(text=text)
        result = bot.dispatch(mock_slack_data)
        self.assertEqual('5', result)

        # Test a valid command with missing param
        text = 'test_command'
        mock_slack_data = get_mock_slack_data(text=text)
        result = bot.dispatch(mock_slack_data)
        self.assertEqual(bot.no_command_found(text), result)

        # Test invalid command
        text = 'invalid'
        mock_slack_data = get_mock_slack_data(text=text)
        result = bot.dispatch(mock_slack_data)
        self.assertEqual(bot.no_command_found(text), result)
示例#2
0
    def test_dispatch(self):
        bot = BaseBot(self.token)
        bot.commands = ((r'test_command (?P<test_param>[0-9]+)',
                         'test_command'), )

        def test_command(test_param):
            return test_param

        bot.test_command = test_command

        # Assign the testing command
        bot.__init__(self.token)

        # Test a valid command
        text = 'test_command 5'
        mock_slack_data = get_mock_slack_data(text=text)
        result = bot.dispatch(mock_slack_data)
        self.assertEqual('5', result)

        # Test a valid command with missing param
        text = 'test_command'
        mock_slack_data = get_mock_slack_data(text=text)
        result = bot.dispatch(mock_slack_data)
        self.assertEqual(bot.no_command_found(text), result)

        # Test invalid command
        text = 'invalid'
        mock_slack_data = get_mock_slack_data(text=text)
        result = bot.dispatch(mock_slack_data)
        self.assertEqual(bot.no_command_found(text), result)
示例#3
0
 def test_help(self):
     bot = BaseBot(self.token)
     mock_slack_data = get_mock_slack_data(text='help')
     with self.assertRaises(NotImplementedError):
         bot.dispatch(mock_slack_data)
示例#4
0
 def test_help(self):
     bot = BaseBot(self.token)
     mock_slack_data = get_mock_slack_data(text='help')
     with self.assertRaises(NotImplementedError):
         bot.dispatch(mock_slack_data)