def test_join_part(registered_connection): fs = registered_connection.conn assert not registered_connection.join(CHANNEL) with registered_connection: assert registered_connection.join(CHANNEL) assert _wrap('JOIN {}'.format(CHANNEL)) in fs.sent assert registered_connection.part(CHANNEL) assert _wrap('PART {}'.format(CHANNEL)) in fs.sent
def test_register(mocked_connection): fs = mocked_connection.conn with mocked_connection: mocked_connection.register(USER, NICK, HOSTNAME, REALNAME) assert _wrap('NICK {}'.format(NICK)) in fs.sent assert _wrap('USER {0} {0} {2} :{1}'.format(USER, REALNAME, HOSTNAME)) in fs.sent assert mocked_connection.addr == HOSTNAME assert mocked_connection.port == PORT assert _wrap('QUIT :{}/{}'.format(NICK, mocked_connection.version)) in fs.sent
def test_run_join(response_bot, channels): fs = response_bot.conn.conn response_bot.joinall(MALFORMED_CHANNELS) response_bot.run() j_msgz = [_wrap('JOIN {}'.format(i)) for i in channels] for m in j_msgz: assert m in fs.sent
def test_message(registered_connection): fs = registered_connection.conn message = 'oh jeez rick' assert registered_connection.send(message) assert registered_connection.message(CHANNEL, message) assert _wrap('PRIVMSG {} :{}'.format(CHANNEL, message)) in fs.sent registered_connection.conn = None assert not registered_connection.send(message)
def test_bot_join_part(connected_bot, channels): fs = connected_bot.conn.conn j_msgz = [_wrap('JOIN {}'.format(i)) for i in channels] p_msgz = [_wrap('PART {}'.format(i)) for i in channels] with connected_bot.conn: connected_bot.joinall(['#foobar']) assert _wrap('JOIN #foobar') in fs.sent connected_bot.joinall(MALFORMED_CHANNELS) for c in channels: assert c in connected_bot.channels for m in j_msgz: assert m in fs.sent connected_bot.part(MALFORMED_CHANNELS) for c in channels: assert c not in connected_bot.channels for m in p_msgz: assert m in fs.sent
def test_builtin_join(connected_bot): log = ':[email protected] PRIVMSG #defaultchannel :.join newch' bad_log = ':[email protected] PRIVMSG #defaultchannel :.join' bad_reply = 'PRIVMSG #defaultchannel :Usage: ^\\.join #channelname' fs = connected_bot.conn.conn fs._set_reply_text(log) m = Message(log) assert not connected_bot.handle(m), 'Commands not yet activated!' with connected_bot.conn: # try out a proper command connected_bot._enable_builtin_commands() assert connected_bot.handle(m) assert _wrap('JOIN #newch') in fs.sent # try the case where the user doesn't provide an arg m = Message(bad_log) assert connected_bot.handle(m) assert _wrap(bad_reply) in fs.sent
def test_ping(registered_connection): fs = registered_connection.conn reply = '''PING :irc.foo.bar.baz\n PING :irc.foo.bar.baz\n ''' fs._set_reply_text(reply) respones = [] for item in registered_connection.recieve(): assert item responses.append(item) assert _wrap('PONG :irc.foo.bar.baz') in fs.sent
def test_builtin_ping(connected_bot): log = ':[email protected] PRIVMSG #defaultchannel :.ping' reply = 'PRIVMSG #defaultchannel :foo: pong' fs = connected_bot.conn.conn fs._set_reply_text(log) m = Message(log) assert not connected_bot.handle(m), 'Commands not yet activated!' with connected_bot.conn: connected_bot._enable_builtin_commands() assert connected_bot.handle(m) assert _wrap(reply) in fs.sent
def test_builtin_version(connected_bot): log = ':[email protected] PRIVMSG #defaultchannel :.version' reply = 'PRIVMSG #defaultchannel :foo: {} version {}'.format( NICK, __version__) fs = connected_bot.conn.conn fs._set_reply_text(log) m = Message(log) assert not connected_bot.handle(m), 'Commands not yet activated!' with connected_bot.conn: connected_bot._enable_builtin_commands() assert connected_bot.handle(m) assert _wrap(reply) in fs.sent
def test_send(registered_connection): fs = registered_connection.conn message = 'oh jeez rick' assert registered_connection.send(message) assert _wrap(message) in fs.sent
def test_raw_send(connected_bot): fs = connected_bot.conn.conn message = 'oh jeez rick' assert connected_bot.raw_send(message) assert _wrap(message) in fs.sent