def test_names_handling():
    handlers = {
        "JOIN": chan_track.on_join,
        "PART": chan_track.on_part,
        "QUIT": chan_track.on_quit,
        "KICK": chan_track.on_kick,
        "353": chan_track.on_names,
        "366": chan_track.on_names,
    }

    bot = MagicMock()
    bot.loop = asyncio.get_event_loop()

    conn = MockConn(bot)
    serv_info = conn.memory["server_info"]
    server_info.handle_prefixes("(YohvV)!@%+-", serv_info)
    server_info.handle_chan_modes(
        "IXZbegw,k,FHJLWdfjlx,ABCDKMNOPQRSTcimnprstuz", serv_info
    )

    for line in NAMES_MOCK_TRAFFIC:
        from cloudbot.clients.irc import _IrcProtocol

        event = _IrcProtocol(conn=conn).parse_line(line)
        call_with_args(handlers[event.irc_command], event)
def test_replace_user_data():
    conn = MockConn()
    serv_info = conn.memory["server_info"]
    server_info.handle_prefixes("(YohvV)!@%+-", serv_info)
    users = chan_track.UsersDict(conn)
    conn.memory["users"] = users

    chan = chan_track.Channel("#test", conn)
    chan.data["new_users"] = [
        "@+foo!bar@baz",
        "@ExampleUser!bar@baz",
        "ExampleUser2!bar@baz",
        "!@%+-foo1!bar@baz",
    ]
    chan_track.replace_user_data(conn, chan)

    assert chan.users["foo"].user.mask == Prefix("foo", "bar", "baz")
    assert chan.users["foo1"].user.mask == Prefix("foo1", "bar", "baz")
    assert chan.users["exampleuser"].user.mask == Prefix(
        "ExampleUser", "bar", "baz"
    )
    assert chan.users["exampleuser2"].user.mask == Prefix(
        "ExampleUser2", "bar", "baz"
    )

    assert chan.users["foo"].status == conn.get_statuses("@+")
    assert chan.users["exampleuser"].status == conn.get_statuses("@")
    assert chan.users["Foo1"].status == conn.get_statuses("!@%+-")
    assert not chan.users["exampleuser2"].status
Beispiel #3
0
def test_replace_user_data():
    from plugins.core.chan_track import UsersDict, replace_user_data, Channel
    from plugins.core.server_info import handle_prefixes
    conn = MockConn()
    serv_info = conn.memory['server_info']
    handle_prefixes('(YohvV)!@%+-', serv_info)
    users = UsersDict(conn)
    conn.memory['users'] = users

    chan = Channel('#test', conn)
    chan.data['new_users'] = [
        '@+foo!bar@baz',
        '@ExampleUser!bar@baz',
        'ExampleUser2!bar@baz',
        '!@%+-foo1!bar@baz',
    ]
    replace_user_data(conn, chan)

    assert chan.users['foo'].user.mask == Prefix('foo', 'bar', 'baz')
    assert chan.users['foo1'].user.mask == Prefix('foo1', 'bar', 'baz')
    assert chan.users['exampleuser'].user.mask == Prefix(
        'ExampleUser', 'bar', 'baz'
    )
    assert chan.users['exampleuser2'].user.mask == Prefix(
        'ExampleUser2', 'bar', 'baz'
    )

    assert chan.users['foo'].status == conn.get_statuses('@+')
    assert chan.users['exampleuser'].status == conn.get_statuses('@')
    assert chan.users['Foo1'].status == conn.get_statuses('!@%+-')
    assert not chan.users['exampleuser2'].status
Beispiel #4
0
def test_channel_members():
    from plugins.core.server_info import handle_prefixes, handle_chan_modes
    from plugins.core.chan_track import (
        get_users, get_chans, replace_user_data,
        on_nick, on_join, on_mode, on_part, on_kick, on_quit,
    )

    conn = MockConn()
    serv_info = conn.memory['server_info']
    handle_prefixes('(YohvV)!@%+-', serv_info)
    handle_chan_modes('IXZbegw,k,FHJLWdfjlx,ABCDKMNOPQRSTcimnprstuz', serv_info)
    users = get_users(conn)
    chans = get_chans(conn)

    chan = chans.getchan('#foo')
    assert chan.name == '#foo'

    chan.data['new_users'] = [
        '@+foo!bar@baz',
        '@ExampleUser!bar@baz',
        '-ExampleUser2!bar@baz',
        '!@%+-foo1!bar@baz',
    ]
    replace_user_data(conn, chan)

    assert users['exampleuser'].host == 'baz'

    test_user = users['exampleuser2']
    on_nick('exampleuser2', ['ExampleUserFoo'], conn)

    assert test_user.nick == 'ExampleUserFoo'
    assert 'exampleuserfoo' in chan.users

    user = users.getuser('exampleuserfoo')

    assert chan.get_member(user).status == conn.get_statuses('-')

    on_join('nick1', 'user', 'host', conn, ['#bar'])

    assert users['Nick1'].host == 'host'

    assert chans['#Bar'].users['Nick1'].status == conn.get_statuses('')

    on_mode(chan.name, [chan.name, '+sop', test_user.nick], conn)

    assert chan.get_member(test_user).status == conn.get_statuses('@-')

    on_part(chan.name, test_user.nick, conn)

    assert test_user.nick not in chan.users

    assert 'foo' in chan.users
    on_kick(chan.name, 'foo', conn)
    assert 'foo' not in chan.users

    assert 'foo1' in chan.users
    on_quit('foo1', conn)
    assert 'foo1' not in chan.users
def test_channel_members():
    conn = MockConn()
    serv_info = conn.memory["server_info"]
    server_info.handle_prefixes("(YohvV)!@%+-", serv_info)
    server_info.handle_chan_modes(
        "IXZbegw,k,FHJLWdfjlx,ABCDKMNOPQRSTcimnprstuz", serv_info
    )
    users = chan_track.get_users(conn)
    chans = chan_track.get_chans(conn)

    chan = chans.getchan("#foo")
    assert chan.name == "#foo"

    chan.data["new_users"] = [
        "@+foo!bar@baz",
        "@ExampleUser!bar@baz",
        "-ExampleUser2!bar@baz",
        "!@%+-foo1!bar@baz",
    ]
    chan_track.replace_user_data(conn, chan)

    assert users["exampleuser"].host == "baz"

    test_user = users["exampleuser2"]
    chan_track.on_nick("exampleuser2", ["ExampleUserFoo"], conn)

    assert test_user.nick == "ExampleUserFoo"
    assert "exampleuserfoo" in chan.users

    user = users.getuser("exampleuserfoo")

    assert chan.get_member(user).status == conn.get_statuses("-")

    chan_track.on_join("nick1", "user", "host", conn, ["#bar"])

    assert users["Nick1"].host == "host"

    assert chans["#Bar"].users["Nick1"].status == conn.get_statuses("")

    chan_track.on_mode(chan.name, [chan.name, "+sop", test_user.nick], conn)

    assert chan.get_member(test_user).status == conn.get_statuses("@-")

    chan_track.on_part(chan.name, test_user.nick, conn)

    assert test_user.nick not in chan.users

    assert "foo" in chan.users
    chan_track.on_kick(chan.name, "foo", conn)
    assert "foo" not in chan.users

    assert "foo1" in chan.users
    chan_track.on_quit("foo1", conn)
    assert "foo1" not in chan.users
Beispiel #6
0
def test_names_handling():
    from plugins.core.server_info import handle_prefixes, handle_chan_modes
    from plugins.core.chan_track import on_join, on_part, on_kick, on_quit, on_names

    handlers = {
        "JOIN": on_join,
        "PART": on_part,
        "QUIT": on_quit,
        "KICK": on_kick,
        "353": on_names,
        "366": on_names,
    }

    chan_pos = {
        "JOIN": 0,
        "PART": 0,
        "KICK": 0,
        "353": 2,
        "366": 1,
    }

    bot = MagicMock()
    bot.loop = asyncio.get_event_loop()

    conn = MockConn(bot)
    serv_info = conn.memory["server_info"]
    handle_prefixes("(YohvV)!@%+-", serv_info)
    handle_chan_modes("IXZbegw,k,FHJLWdfjlx,ABCDKMNOPQRSTcimnprstuz",
                      serv_info)

    for line in NAMES_MOCK_TRAFFIC:
        line = Message.parse(line)
        data = {
            "nick": line.prefix.nick,
            "user": line.prefix.ident,
            "host": line.prefix.host,
            "conn": conn,
            "irc_paramlist": line.parameters,
            "irc_command": line.command,
            "chan": None,
            "target": None,
        }

        if line.command in chan_pos:
            data["chan"] = line.parameters[chan_pos[line.command]]

        if line.command == "KICK":
            data["target"] = line.parameters[1]

        call_with_args(handlers[line.command], data)
Beispiel #7
0
def test_names_handling():
    from plugins.core.server_info import handle_prefixes, handle_chan_modes
    from plugins.chan_track import on_join, on_part, on_kick, on_quit, on_names

    handlers = {
        'JOIN': on_join,
        'PART': on_part,
        'QUIT': on_quit,
        'KICK': on_kick,
        '353': on_names,
        '366': on_names,
    }

    chan_pos = {
        'JOIN': 0,
        'PART': 0,
        'KICK': 0,
        '353': 2,
        '366': 1,
    }

    bot = MagicMock()
    bot.loop = asyncio.get_event_loop()

    conn = MockConn(bot)
    serv_info = conn.memory['server_info']
    handle_prefixes('(YohvV)!@%+-', serv_info)
    handle_chan_modes('IXZbegw,k,FHJLWdfjlx,ABCDKMNOPQRSTcimnprstuz',
                      serv_info)

    for line in NAMES_MOCK_TRAFFIC:
        line = Message.parse(line)
        data = {
            'nick': line.prefix.nick,
            'user': line.prefix.ident,
            'host': line.prefix.host,
            'conn': conn,
            'irc_paramlist': line.parameters,
            'irc_command': line.command,
            'chan': None,
            'target': None,
        }

        if line.command in chan_pos:
            data['chan'] = line.parameters[chan_pos[line.command]]

        if line.command == 'KICK':
            data['target'] = line.parameters[1]

        call_with_args(handlers[line.command], data)
def test_handle_modes(mock_db):
    conn = make_conn()
    db = mock_db.session()
    chan_key_db.table.create(mock_db.engine)
    server_info.clear_isupport(conn)
    serv_info = server_info.get_server_info(conn)
    server_info.handle_prefixes("(YohvV)!@%+-", serv_info)
    server_info.handle_chan_modes(
        "IXZbegw,k,FHJLWdfjlx,ABCDKMNOPQRSTcimnprstuz", serv_info)
    assert (chan_key_db.handle_modes(["#foo", "+o", "foo"], conn, db, "#foo")
            is None)
    assert conn.get_channel_key("#foo") is None

    assert (chan_key_db.handle_modes(["#foo", "+ok", "foo", "beep"], conn, db,
                                     "#foo") is None)
    assert conn.get_channel_key("#foo") == "beep"

    assert (chan_key_db.handle_modes(["#foo", "-ok", "foo", "beep"], conn, db,
                                     "#foo") is None)
    assert conn.get_channel_key("#foo") is None

    assert (chan_key_db.handle_modes([conn.nick, "-ok"], conn, db,
                                     "server.host") is None)
    assert conn.get_channel_key("#foo") is None