class TestPhialBot(unittest.TestCase): def setUp(self): self.bot = Phial('test-token') self.bot._is_running = MockTrueFunc() def tearDown(self): self.bot = None phial.globals._global_ctx_stack.pop() phial.globals._command_ctx_stack.pop() def assertCommandInCommands(self, command, case_sensitive=False): self.assertTrue( self.bot._build_command_pattern(command, case_sensitive) in self.bot.commands)
def test_config_override(self): bot = Phial('test-token', config={ 'prefix': "/", 'registerHelpCommand': False, 'baseHelpText': "All commands:", 'autoReconnect': False }) self.assertEqual( bot.config, { 'prefix': "/", 'registerHelpCommand': False, 'baseHelpText': "All commands:", 'autoReconnect': False })
from phial import Phial, command, Response, Attachment, g import os slackbot = Phial('token-goes-here') @slackbot.command('ping') def ping(): '''Simple command which replies with a message''' return "Pong" @slackbot.command('pong') def pong(): ''' Simple command which replies with a message. Has a mutiline docstring. ''' return "Ping" @slackbot.command('hello <name>') def hello(name): '''Simple command with argument which replies to a message''' return Response(text="Hi {0}".format(name), channel=command.channel) @slackbot.command('hello <name> <from_>') def hello(name, from_): '''Simple command with two arguments which replies to a message''' return Response(text="Hi {0}, from {1}".format(name, from_),
def test_global_context_in_command(self): bot = Phial('test-token') command_pattern1 = bot._build_command_pattern('test', False) command_pattern2 = bot._build_command_pattern('test2', False) def command_function(): g['test'] = "test value" def second_command_function(): self.assertEqual(g['test'], "test value") bot.add_command('test', command_function) message = phial.wrappers.Message(text="!test", channel="channel_id", user="******", timestamp="timestamp") command_instance = phial.wrappers.Command(command_pattern1, 'channel_id', {}, 'user', message) bot.add_command('test2', second_command_function) second_command_instance = phial.wrappers.Command( command_pattern2, 'channel_id', {}, 'user', message) bot._handle_command(command_instance) bot._handle_command(second_command_instance)
def test_partial_config_override(self): bot = Phial('test-token', config={ 'prefix': "/", }) self.assertEqual(bot.config['prefix'], '/') self.assertEqual(bot.config['baseHelpText'], "All available commands:")
def test_uses_default_config_when_specified(self): bot = Phial('test-token') self.assertEqual(bot.config, Phial.default_config)
def setUp(self): self.bot = Phial('test-token') self.bot._is_running = MockTrueFunc()
def test_returns_expected_value(self): bot = Phial('test-token') self.assertFalse(bot._is_running())