def setUp(self): self.ext = CommandExtension(mock_bot())
class CommandExtensionTestCase(TestCase): def setUp(self): self.ext = CommandExtension(mock_bot()) def test_parse_command(self): self.ext.usage = '[FOO] [BAR] [BAZ]' msg = Mock(message='foo bar baz') opts = self.ext.parse_command(msg) assert opts['FOO'] == 'foo' assert opts['BAR'] == 'bar' assert opts['BAZ'] == 'baz' def test_parse_command_no_match(self): self.ext.usage = 'foo [BAR]' msg = Mock(message='helga dosomething') assert self.ext.parse_command(msg) is None def test_parse_command_no_nick_required_arg(self): self.ext.usage = '[BOTNICK] foo' msg = Mock(message='foo') assert self.ext.parse_command(msg) def test_should_handle_message_private_without_nick(self): msg = Mock(is_public=False) opts = { 'foo': True } assert self.ext.should_handle_message(opts, msg) def test_should_handle_message_private_with_nick(self): msg = Mock(is_public=False) opts = { 'BOTNICK': self.ext.bot.nick, 'foo': True } assert self.ext.should_handle_message(opts, msg) def test_should_handle_message_private_different_nick(self): msg = Mock(is_public=False) opts = { 'BOTNICK': '@' + self.ext.bot.nick, 'foo': True } assert not self.ext.should_handle_message(opts, msg) def test_should_handle_message_public_without_nick(self): msg = Mock(is_public=True) opts = { 'foo': True } assert not self.ext.should_handle_message(opts, msg) def test_should_handle_message_public_with_nick(self): msg = Mock(is_public=True) opts = { 'BOTNICK': self.ext.bot.nick, 'foo': True } assert self.ext.should_handle_message(opts, msg) def test_should_handle_message_public_different_nick(self): msg = Mock(is_public=True) opts = { 'BOTNICK': '@' + self.ext.bot.nick, 'foo': True } assert not self.ext.should_handle_message(opts, msg)
class CommandExtensionTestCase(TestCase): def setUp(self): self.ext = CommandExtension(mock_bot()) def test_parse_command(self): self.ext.usage = '[FOO] [BAR] [BAZ]' msg = Mock(message='foo bar baz') opts = self.ext.parse_command(msg) assert opts['FOO'] == 'foo' assert opts['BAR'] == 'bar' assert opts['BAZ'] == 'baz' def test_parse_command_no_match(self): self.ext.usage = 'foo [BAR]' msg = Mock(message='helga dosomething') assert self.ext.parse_command(msg) is None def test_parse_command_no_nick_required_arg(self): self.ext.usage = '[BOTNICK] foo' msg = Mock(message='foo') assert self.ext.parse_command(msg) def test_parse_command_mixed_case(self): self.ext.usage = 'BOTNICK foo' msg = Mock(message='helga Foo') assert self.ext.parse_command(msg) def test_should_handle_message_private_without_nick(self): msg = Mock(is_public=False) opts = { 'foo': True } assert self.ext.should_handle_message(opts, msg) def test_should_handle_message_private_with_nick(self): msg = Mock(is_public=False) opts = { 'BOTNICK': self.ext.bot.nick, 'foo': True } assert self.ext.should_handle_message(opts, msg) def test_should_handle_message_private_different_nick(self): msg = Mock(is_public=False) opts = { 'BOTNICK': '@' + self.ext.bot.nick, 'foo': True } assert not self.ext.should_handle_message(opts, msg) def test_should_handle_message_public_without_nick(self): msg = Mock(is_public=True) opts = { 'foo': True } assert not self.ext.should_handle_message(opts, msg) def test_should_handle_message_public_with_nick(self): msg = Mock(is_public=True) opts = { 'BOTNICK': self.ext.bot.nick, 'foo': True } assert self.ext.should_handle_message(opts, msg) def test_should_handle_message_public_different_nick(self): msg = Mock(is_public=True) opts = { 'BOTNICK': '@' + self.ext.bot.nick, 'foo': True } assert not self.ext.should_handle_message(opts, msg) def test_should_handle_message_nick_with_comma(self): msg = Mock(is_public=True) opts = { 'BOTNICK': self.ext.bot.nick + ',', 'foo': True } assert self.ext.should_handle_message(opts, msg) def test_should_handle_message_nick_with_colon(self): msg = Mock(is_public=True) opts = { 'BOTNICK': self.ext.bot.nick + ':', 'foo': True } assert self.ext.should_handle_message(opts, msg) def test_should_handle_message_nick_with_diff_nick_ending(self): msg = Mock(is_public=True) opts = { 'BOTNICK': self.ext.bot.nick + 't', 'foo': True } assert not self.ext.should_handle_message(opts, msg)