Beispiel #1
0
async def test_on_response():
    # Tests on_response, _attach_message_log, and _get_author for IRC
    listener = IRCListener(None, 'chitanda', 'irc.freenode.fake')
    listener.nickname = 'chitanda'

    await on_response(Response(None, listener, '#chan', 'hello'))
    assert listener.message_log['#chan'].popleft() == '<chitanda> hello'
Beispiel #2
0
async def test_on_message_self_message(method):
    bot = Mock()
    bot.handle_message.return_value = coroutine(lambda **kwargs: None)()
    listener = IRCListener(bot, 'zad', 'irc.freenode.fake')
    listener.nickname = 'zad'

    await getattr(listener, method)(1, 'zad', 2)
    bot.handle_message.assert_not_called()
Beispiel #3
0
async def test_on_join(test_db):
    listener = IRCListener(None, "chitanda", "irc.freenode.fake")
    listener.nickname = "chitanda"
    listener.on_join = AsyncMock(return_value=True)
    await on_join(listener, "#channel", "chitanda")
    with database() as (conn, cursor):
        cursor.execute("""
            SELECT 1 FROM irc_channels WHERE name = "#channel"
            AND server = "irc.freenode.fake" AND active = 1
            """)
        assert cursor.fetchone()
Beispiel #4
0
async def test_on_join_other_user(test_db):
    listener = IRCListener(None, 'chitanda', 'irc.freenode.fake')
    listener.nickname = 'chitanda'
    listener.on_join = coroutine(lambda *args: True)
    await on_join(listener, '#channel', 'azul')
    with database() as (conn, cursor):
        cursor.execute(
            """
            SELECT 1 FROM irc_channels WHERE name = "#channel"
            AND server = "irc.freenode.fake" AND active = 1
            """
        )
        assert not cursor.fetchone()
Beispiel #5
0
async def test_on_part_other_user(test_db):
    listener = IRCListener(None, "chitanda", "irc.freenode.fake")
    listener.nickname = "chitanda"
    listener.on_part = AsyncMock(return_value=True)
    with database() as (conn, cursor):
        cursor.execute("""
            INSERT INTO irc_channels (name, server)
            VALUES ("#channel", "irc.freenode.fake")
            """)
        conn.commit()
        await on_part(listener, "#channel", "azul", None)
        cursor.execute("""
            SELECT 1 FROM irc_channels WHERE name = "#channel"
            AND server = "irc.freenode.fake" AND active = 1
            """)
        assert cursor.fetchone()
Beispiel #6
0
async def test_on_part_other_user(test_db):
    listener = IRCListener(None, 'chitanda', 'irc.freenode.fake')
    listener.nickname = 'chitanda'
    listener.on_part = coroutine(lambda *args: True)
    with database() as (conn, cursor):
        cursor.execute(
            """
            INSERT INTO irc_channels (name, server)
            VALUES ("#channel", "irc.freenode.fake")
            """
        )
        conn.commit()
        await on_part(listener, '#channel', 'azul', None)
        cursor.execute(
            """
            SELECT 1 FROM irc_channels WHERE name = "#channel"
            AND server = "irc.freenode.fake" AND active = 1
            """
        )
        assert cursor.fetchone()