예제 #1
0
def test_account_tag():
    bot = MagicMock()
    bot.loop = asyncio.get_event_loop()

    conn = MockConn(bot)
    data = {
        "conn": conn,
        "irc_tags": TagList.from_dict({"account": "foo"}),
        "nick": "bar",
    }
    user = chan_track.get_users(conn).getuser("bar")
    assert user.account is None
    res = call_with_args(chan_track.handle_tags, data)
    assert res is None
    assert dict(chan_track.get_users(conn)) == {"bar": user}
    assert user.account == "foo"

    data = {
        "conn": conn,
        "irc_tags": TagList.from_dict({"account": "*"}),
        "nick": "bar",
    }
    res = call_with_args(chan_track.handle_tags, data)
    assert res is None
    assert dict(chan_track.get_users(conn)) == {"bar": user}
    assert user.account is None
예제 #2
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
예제 #3
0
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