def test_send_privmsg(): bot = BotCollector() backend = MockIRCBackend(bot) backend.send_privmsg('#sopel', 'Hello world!') expected = 'PRIVMSG #sopel :Hello world!\r\n' assert backend.message_sent == [expected.encode('utf-8')] assert bot.message_sent == [expected]
def test_send_notice_safe(): bot = BotCollector() backend = MockIRCBackend(bot) backend.send_notice('#sopel', 'Hello\r\nworld!') expected = 'NOTICE #sopel :Helloworld!\r\n' assert backend.message_sent == [expected.encode('utf-8')] assert bot.message_sent == [expected]
def test_send_part_text(): bot = BotCollector() backend = MockIRCBackend(bot) backend.send_part('#sopel', 'Bye Sopelunkers!') expected = 'PART #sopel :Bye Sopelunkers!\r\n' assert backend.message_sent == [expected.encode('utf-8')] assert bot.message_sent == [expected]
def test_send_kick_text(): bot = BotCollector() backend = MockIRCBackend(bot) backend.send_kick('#sopel', 'spambot', reason='Flood!') expected = 'KICK #sopel spambot :Flood!\r\n' assert backend.message_sent == [expected.encode('utf-8')] assert bot.message_sent == [expected]
def test_send_pass(): bot = BotCollector() backend = MockIRCBackend(bot) backend.send_pass('secret_p4s5w0rd') expected = 'PASS secret_p4s5w0rd\r\n' assert backend.message_sent == [expected.encode('utf-8')] assert bot.message_sent == [expected]
def test_send_join_secret(): bot = BotCollector() backend = MockIRCBackend(bot) backend.send_join('#sopel', 'secret_p4s5w0rd') expected = 'JOIN #sopel secret_p4s5w0rd\r\n' assert backend.message_sent == [expected.encode('utf-8')] assert bot.message_sent == [expected]
def test_send_user(): bot = BotCollector() backend = MockIRCBackend(bot) backend.send_user('sopel', '+iw', 'Sopel', 'Sopel (https://sopel.chat)') expected = 'USER sopel +iw Sopel :Sopel (https://sopel.chat)\r\n' assert backend.message_sent == [expected.encode('utf-8')] assert bot.message_sent == [expected]
def test_send_nick(): bot = BotCollector() backend = MockIRCBackend(bot) backend.send_nick('Sopel') expected = 'NICK Sopel\r\n' assert backend.message_sent == [expected.encode('utf-8')] assert bot.message_sent == [expected]
def test_send_pong(): bot = BotCollector() backend = MockIRCBackend(bot) backend.send_pong('chat.freenode.net') expected = 'PONG chat.freenode.net\r\n' assert backend.message_sent == [expected.encode('utf-8')] assert bot.message_sent == [expected]
def test_send_command_args_text(): bot = BotCollector() backend = MockIRCBackend(bot) backend.send_command('KICK', 'Exirel', text='Too many PRs!') expected = 'KICK Exirel :Too many PRs!\r\n' assert backend.message_sent == [expected.encode('utf-8')] assert bot.message_sent == [expected]
def test_send_command_text(): bot = BotCollector() backend = MockIRCBackend(bot) backend.send_command('HELP', text='?') expected = 'HELP :?\r\n' assert backend.message_sent == [expected.encode('utf-8')] assert bot.message_sent == [expected]
def test_send_command(): bot = BotCollector() backend = MockIRCBackend(bot) backend.send_command('INFO') expected = 'INFO\r\n' assert backend.message_sent == [expected.encode('utf-8')] assert bot.message_sent == [expected]
def test_send_quit_text(): bot = BotCollector() backend = MockIRCBackend(bot) backend.connected = True # TODO: refactor without attribute backend.send_quit(reason='Bye freenode!') expected = 'QUIT :Bye freenode!\r\n' assert backend.message_sent == [expected.encode('utf-8')] assert bot.message_sent == [expected]
def test_send_command_args_text_safe(): bot = BotCollector() backend = MockIRCBackend(bot) backend.send_command('PRIVMSG', '#sopel', text='Unsafe\ntext') expected = 'PRIVMSG #sopel :Unsafetext\r\n' assert backend.message_sent == [expected.encode('utf-8')] assert bot.message_sent == [expected]
def test_send_quit_disconnected(): bot = BotCollector() backend = MockIRCBackend(bot) backend.connected = False # TODO: refactor without attribute backend.send_quit() backend.send_quit(reason='Bye freenode!') assert backend.message_sent == [] assert bot.message_sent == []
def test_send_command_args_text_many(): bot = BotCollector() backend = MockIRCBackend(bot) backend.send_command('PRIVMSG', '#sopel', text='Hello here!') backend.send_command('PRIVMSG', '#sopel', text='I have a question.') expected_1 = 'PRIVMSG #sopel :Hello here!\r\n' expected_2 = 'PRIVMSG #sopel :I have a question.\r\n' assert backend.message_sent == [ expected_1.encode('utf-8'), expected_2.encode('utf-8') ] assert bot.message_sent == [expected_1, expected_2]
def get_irc_backend(self): return MockIRCBackend(self)
def mockbot(tmpconfig): obj = bot.Sopel(tmpconfig, daemon=False) obj.backend = MockIRCBackend(obj) return obj