Beispiel #1
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