Пример #1
0
def testMessageJoin() -> None:
    """Tests the ability of Message objects to handle join messages
    """
    connection = DummyConnection()
    message = core.BotMessage(
        """>testroom
|J|#Ann(ik)a ^_^""",
        connection
    )
    assert message.type == "join"
    assert 'testroom' in connection.getUserRooms(connection.getUser('annika'))

    message = core.BotMessage(
        """>testroom2
|j|#Ann(ik)a ^_^""",
        connection
    )
    assert message.type == "join"
    assert 'testroom2' in connection.getUserRooms(connection.getUser('annika'))

    message = core.BotMessage(
        """>testroom3
|join|#Ann(ik)a ^_^""",
        connection
    )
    assert message.type == "join"
    assert 'testroom3' in connection.getUserRooms(connection.getUser('annika'))
Пример #2
0
def testMessageChallstr() -> None:
    """Tests the ability of Message objects to handle challstrs
    """
    message = core.BotMessage(
        "|challstr|4|314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823",
        DummyConnection()
    )
    assert message.challstr == "4|314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823"
Пример #3
0
def testMessagePM() -> None:
    """Tests the ability of Message objects to handle PM messages and commands
    """
    message = core.BotMessage(
        "|pm|+aNNika ^_^|Expecto Botronum|-somecommand argument1,argumENT2||withpipes, argumént3",
        DummyConnection()
    )
    assert message.senderName == "+aNNika ^_^"
    assert message.sender.id == "annika"
    assert message.arguments == ["-somecommand", "argument1", "argumENT2||withpipes", " argumént3"]
    assert message.room is None
    assert message.body == "-somecommand argument1,argumENT2||withpipes, argumént3"
    assert message.time is None
    assert message.type == 'pm'
    assert message.challstr is None
Пример #4
0
def testMessageChatCommand() -> None:
    """Tests the ability of Message objects to handle commands sent to rooms, with arguments
    """
    message = core.BotMessage(
        """>testroom
|c:|1593475694|#Ann/ika ^_^|-somecommand argument1,argumENT2||withpipes, argumént3""",
        DummyConnection()
    )
    assert message.senderName == "#Ann/ika ^_^"
    assert message.sender.id == "annika"
    assert message.arguments == ["-somecommand", "argument1", "argumENT2||withpipes", " argumént3"]
    assert message.room.id == "testroom"
    assert message.body == "-somecommand argument1,argumENT2||withpipes, argumént3"
    assert message.time == "1593475694"
    assert message.type == 'chat'
    assert message.challstr is None
Пример #5
0
def testMessageChat() -> None:
    """Tests the ability of Message objects to parse chat messages including strange characters, from the Lobby
    """
    message = core.BotMessage(
        "|c|#Ann/ika ^_^|Hi, I wrote a Python test|Isn't it cool?it,contains,odd characters och konstigt bokstaver från andra språk.",
        DummyConnection()
    )
    assert message.senderName == "#Ann/ika ^_^"
    assert message.sender.id == "annika"
    assert message.arguments == ['Hi,', "I wrote a Python test|Isn't it cool?it", "contains", "odd characters och konstigt bokstaver från andra språk."]
    assert message.room.id == "lobby"
    assert message.body == "Hi, I wrote a Python test|Isn't it cool?it,contains,odd characters och konstigt bokstaver från andra språk."
    assert message.time is None
    assert message.type == 'chat'
    assert message.challstr is None
    assert isinstance(str(message), str)
Пример #6
0
def testMessageQueryResponse() -> None:
    """Tests the ability of Message objects to handle query responses
    """
    connection = DummyConnection()
    message = core.BotMessage(
        """|queryresponse|roominfo|{"id":"testroom","roomid":"testroom","title":"Magic & Mayhem","type":"chat","visibility":"hidden","modchat":null,"auth":{"#":["annika","awa","cleo","meicoo"],"%":["dawnofares","instruct","ratisweep","pirateprincess","watfor","oaklynnthylacine"],"@":["gwynt","darth","profsapling","ravioliqueen","miapi"],"+":["madmonty","birdy","captanpasta","iwouldprefernotto","xprienzo","nui","toxtricityamped"],"*":["expectobotronum","kida"]}, "users":["user1","user2"]}""",
        connection
    )
    assert message.type == "queryresponse"
    assert "testroom" in connection.userList[connection.getUser('user1')]
    assert "testroom" in connection.userList[connection.getUser('user2')]

    allUserIDs = [user.id for user in connection.userList]
    assert 'user1' in allUserIDs
    assert 'user2' in allUserIDs

    auth = connection.getRoom("testroom").auth
    assert auth['#'] == {"annika", "awa", "cleo", "meicoo"}
    assert auth['*'] == {"expectobotronum", "kida"}
    assert auth['@'] == {"gwynt", "darth", "profsapling", "ravioliqueen", "miapi"}
    assert auth['%'] == {"dawnofares", "instruct", "ratisweep", "pirateprincess", "watfor", "oaklynnthylacine"}
    assert auth['+'] == {"madmonty", "birdy", "captanpasta", "iwouldprefernotto", "xprienzo", "nui", "toxtricityamped"}
Пример #7
0
def testMessageLeave() -> None:
    """Tests the ability of Message objects to handle leave messages
    """
    connection = DummyConnection()
    joinMessage = """>testroom
|J|#Ann(ik)a ^_^"""

    core.BotMessage(joinMessage, connection)
    assert 'testroom' in connection.getUserRooms(connection.getUser('annika'))
    message = core.BotMessage(
        """>testroom
|L|#Ann(ik)a ^_^""",
        connection
    )
    assert message.type == "leave"
    assert 'testroom' not in connection.getUserRooms(connection.getUser('annika'))

    core.BotMessage(joinMessage, connection)
    assert 'testroom' in connection.getUserRooms(connection.getUser('annika'))
    message = core.BotMessage(
        """>testroom
|l|#Ann(ik)a ^_^""",
        connection
    )
    assert message.type == "leave"
    assert 'testroom' not in connection.getUserRooms(connection.getUser('annika'))

    core.BotMessage(joinMessage, connection)
    assert 'testroom' in connection.getUserRooms(connection.getUser('annika'))
    message = core.BotMessage(
        """>testroom
|leave|#Ann(ik)a ^_^""",
        connection
    )
    assert message.type == "leave"
    assert 'testroom' not in connection.getUserRooms(connection.getUser('annika'))