示例#1
0
def test_message_remove():
    jsonClean()
    # SETUP BEGIN
    
    # Generate a valid user
    registerValidUserDict = auth_register("*****@*****.**", "validpassword", "firstname", "lastname")
    token = registerValidUserDict["token"]    
    u_id = registerValidUserDict["u_id"]
    createValidChannelDict = channels_create(token, "validchannel", True)
    channel_id = createValidChannelDict["channel_id"]
    channel_invite(token, channel_id, u_id)
    message_send(token, channel_id, "Hi")
    message_send(token, channel_id, "My name is")
    message_send(token, channel_id, "Thom Browne")
    channelValidMessagesDict = channel_messages(token, channel_id, 0)
    message_list = channelValidMessagesDict["messages"]
    message_dict = message_list[0]
    message_id = message_dict["message_id"]
    
    # Generate an invalid user
    registerInvalidUserDict = auth_register("*****@*****.**", "invalidpassword", "invalidfirstname", "invalidlastname")
    invalid_token = registerInvalidUserDict["token"]  
    invalid_uid = registerValidUserDict["u_id"]  
    createInvalidChannelDict = channels_create(invalid_token, "invalidchannel", True)
    invalid_channelid = createInvalidChannelDict["channel_id"]
    channel_invite(invalid_token, invalid_channelid, invalid_uid)
    message_send(invalid_token, channel_id, "iH")
    message_send(invalid_token, channel_id, "si eman yM")
    message_send(invalid_token, channel_id, "enworB mohT")
    channelInvalidMessagesDict = channel_messages(invalid_token, invalid_channelid, 1)
    invalid_messagelist = channelValidMessagesDict["messages"]
    invalid_messagedict = invalid_messagelist[1]
    invalid_messageid = invalid_messagedict["message_id"]
    
    # Invalidate the invalid user
    auth_logout(invalid_token)
    
    # SETUP END
    
    # Asserting that the default case works
    assert remove_message(token, message_id) == {}
    
    # Testing that ValueError is raised when invalid parameters are passed
    with pytest.raises(ValueError):
        
        # Testing function with an invalid token
        remove_message(invalid_token, message_id)

        # Testing function with an invalid message id
        remove_message(valid_token, invalid_messageid)
示例#2
0
def test_message_pin():
    jsonClean()
    # SETUP BEGIN
    authRegisterDic = auth_register("*****@*****.**", "valid60password",
                                    "first60name", "last60name")
    token = authRegisterDic['token']
    u_id = authRegisterDic['u_id']
    channelsCreateDic = channels_create(token, "validchannel", True)
    channel_id = channelsCreateDic['channel_id']

    authRegisterDicOne = auth_register("*****@*****.**", "valid61password",
                                       "first61name", "last61name")
    token_one = authRegisterDicOne['token']
    u_id_one = authRegisterDicOne['u_id']

    message_send(token, channel_id, "validmessage")
    channelMessagesDic = channel_messages(token, channel_id, 0)
    message_list = channelMessagesDic["messages"]
    message_dic = message_list[0]
    message_id = message_dic["message_id"]
    # SETUP END

    message_pin(token, message_id)

    with pytest.raises(ValueError):
        message_pin(token, message_id)

    assert message_unpin(token, message_id) == {}
    # Testing message_pin to check the message was successfully unpinned
    message_pin(token, message_id)
示例#3
0
def test_message_edit():

    # SETUP BEGIN
    jsonClean()
    # Token creates the channel so it should be the owner
    registerValidUserDict = auth_register("*****@*****.**", "validpassword",
                                          "firstname", "lastname")
    token = registerValidUserDict["token"]
    u_id = registerValidUserDict["u_id"]
    createValidChannelDict = channels_create(token, "validchannel", True)
    channel_id = createValidChannelDict["channel_id"]
    message_send(token, channel_id, "Hi")
    message_send(token, channel_id, "My name is")
    message_send(token, channel_id, "Thom Browne")
    channelValidMessagesDict = channel_messages(token, channel_id, 0)
    message_list = channelValidMessagesDict["messages"]
    message_dict = message_list[0]
    message_id = message_dict["message_id"]

    # A member in the channel
    authRegisterDicOne = auth_register("*****@*****.**", "validpassword2",
                                       "firstname2", "lastname2")
    token_one = authRegisterDicOne['token']
    u_id_one = authRegisterDicOne['u_id']
    channel_invite(token, channel_id, u_id_one)
    message_send(token_one, channel_id, "iH")
    message_send(token_one, channel_id, "si eman yM")
    message_send(token_one, channel_id, "enworB mohT")
    channelInvalidMessagesDict = channel_messages(token_one, channel_id, 1)
    invalid_messagelist = channelValidMessagesDict["messages"]
    invalid_messagedict = invalid_messagelist[1]
    invalid_messageid = invalid_messagedict["message_id"]

    # SETUP END

    # Asserting that the default case works
    assert message_edit(token, message_id, message_list[0]) == {}
    # Testing that ValueError is raised when invalid parameters are passed
    with pytest.raises(ValueError):

        # Testing function with an invalid token
        message_edit(token_one, message_id, message_list[0])

        # Testing function with an invalid message id
        message_edit(token_one, invalid_messageid, message_list[1])
示例#4
0
def test_message_unreact_bad():
    jsonClean()
    # SETUP BEGIN
    authRegisterDic = auth_register("*****@*****.**", "validpassword",
                                    "firstname", "lastname")
    token = authRegisterDic['token']
    u_id = authRegisterDic['u_id']
    channelsCreateDic = channels_create(token, "validchannel", True)
    channel_id = channelsCreateDic['channel_id']

    authRegisterDicOne = auth_register("*****@*****.**", "validpassword1",
                                       "firstname1", "lastname1")
    token_one = authRegisterDicOne['token']
    u_id_one = authRegisterDicOne['u_id']
    channel_join(token_one, channel_id)

    authRegisterDicTwo = auth_register("*****@*****.**", "validpassword2",
                                       "firstname2", "lastname2")
    token_two = authRegisterDicTwo['token']
    u_id_two = authRegisterDicTwo['u_id']

    message_send(token, channel_id, "validmessage")
    channelMessagesDic = channel_messages(token, channel_id, 0)
    message_list = channelMessagesDic["messages"]
    message_dic = message_list[0]
    message_id = message_dic["message_id"]
    # SETUP END

    message_react(token, message_id, 1)
    with pytest.raises(ValueError):
        # Testing function with user who isn't admin
        message_unreact(token_one, message_id, 1)
        # Testing function with invalid message_id
        message_unreact(token, "invalidmessage_id", 1)
        # Testing function with user who isn't part of the channel
        message_unreact(token_two, message_id, react_id)
        # Testing function with invalid react_id
        message_unreact(token, message_id, "invalidreact_id")

    message_unreact(token, message_id, 1)
    with pytest.raises(ValueError):
        # Testing function with already unreacted message_id
        message_unreact(token, message_id, 1)

    message_react(token, message_id, react_id)
    auth_logout(token)
    with pytest.raises(ValueError):
        # Testing function with invalid token
        message_unreact(token, message_id, react_id)
示例#5
0
def test_message_pin_bad():
    jsonClean()
    # SETUP BEGIN
    authRegisterDic = auth_register("*****@*****.**", "valid70password",
                                    "first70name", "last70name")
    token = authRegisterDic['token']
    u_id = authRegisterDic['u_id']
    channelsCreateDic = channels_create(token, "validchannel", True)
    channel_id = channelsCreateDic['channel_id']

    authRegisterDicOne = auth_register("*****@*****.**", "valid71password",
                                       "first71name", "last71name")
    token_one = authRegisterDicOne['token']
    u_id_one = authRegisterDicOne['u_id']
    channel_join(token_one, channel_id)

    authRegisterDicTwo = auth_register("*****@*****.**", "valid72password",
                                       "first72name", "last72name")
    token_two = authRegisterDicTwo['token']
    u_id_two = authRegisterDicTwo['u_id']

    message_send(token, channel_id, "validmessage")
    channelMessagesDic = channel_messages(token, channel_id, 0)
    message_list = channelMessagesDic["messages"]
    message_dic = message_list[0]
    message_id = message_dic["message_id"]
    # SETUP END

    with pytest.raises(ValueError):
        # Testing function with user who isn't admin
        message_unpin(token_one, message_id)
        # Testing function with invalid message_id
        message_unpin(token, "invalidmessage_id")
        # Testing function with user who isn't part of the channel
        message_unpin(token_two, message_id)

    message_unpin(token, message_id)
    with pytest.raises(ValueError):
        # Testing function with already unpinned message_id
        message_unpin(token, message_id)
示例#6
0
def test_message_react():
    jsonClean()
    # SETUP BEGIN

    authRegisterDic = auth_register("*****@*****.**", "validpassword",
                                    "firstname", "lastname")
    token = authRegisterDic['token']
    u_id = authRegisterDic['u_id']
    channelsCreateDic = channels_create(token, "validchannel", True)
    channel_id = channelsCreateDic['channel_id']

    authRegisterDicOne = auth_register("*****@*****.**", "validpassword1",
                                       "firstname1", "lastname1")
    token_one = authRegisterDicOne['token']
    u_id_one = authRegisterDicOne['u_id']
    channel_join(token_one, channel_id)

    message_send(token, channel_id, "validmessage")
    channelMessagesDic = channel_messages(token, channel_id, 0)
    message_list = channelMessagesDic["messages"]
    message_dic = message_list[0]
    message_id = message_dic["message_id"]

    # Assuming 123 is valid react_id
    react_id = 123

    # SETUP END

    assert message_react(token, message_id, react_id) == {}
    # Testing two users can react laugh one message
    assert message_react(token_one, message_id, react_id) == {}

    with pytest.raises(ValueError):
        # Testing function can't react the message for a second time
        message_react(token, message_id, react_id)

    # Testing function can unreact the message
    assert message_unreact(token, message_id, react_id) == {}
示例#7
0
def wrap_channel_messages():
    channel_messages(request.args.get('token'), request.args.get('channel_id'),
                     request.args.get('start'))
    return json.dumps({})
示例#8
0
def test_search():
    jsonClean()
    # SETUP BEGIN
    # User One 
    validAuthRegisterDic = auth_register("*****@*****.**", "valid30password", "first30name", "last30name")
    token = validAuthRegisterDic['token']
    u_id = validAuthRegisterDic['u_id']
    
    # User Two
    validAuthRegisterDicOne = auth_register("*****@*****.**", "valid31password", "first31name", "last31name")
    token_one = validAuthRegisterDicOne['token']
    u_id_one = validAuthRegisterDicOne['u_id']
    
    # False User Three
    invalidAuthRegisterDic = auth_register("*****@*****.**", "valid32password", "first32name", "last32name")
    invalid_token = invalidAuthRegisterDic['token']
    # Creates an Invalid Token
    auth_logout(invalid_token) 
    
    # Create a channel
    channel_id_dic = channels_create(token, "Channel Nine", True)
    channel_id = channel_id_dic['channel_id']
    # Invite the member
    channel_invite(token, channel_id, u_id_one)
    
    # Send the messages
    message_send(token_one, channel_id, "Safe and secure society")
    message_send(token, channel_id, "Hello")
    message_send(token_one, channel_id, "Hellomydude")
    message_send(token, channel_id, "Hellomyman")
    message_send(token, channel_id, "Seriously cool")
    message_send(token_one, channel_id, "Absolutely astonishing")
    message_send(token, channel_id, "Congratulations on the role!")
    message_send(token_one, channel_id, "Happy work anniversary!")
    message_send(token, channel_id, "New world. New skills.")
    message_send(token, channel_id, "New world")
    
    # Find the Message ID's
    channelMessagesDic = channel_messages(token, channel_id, 0)
    message_list = channelMessagesDic["messages"]
    message_dic = message_list[0]
    message_id_safe = message_dic["message_id"]
    message_dic_one = message_list[2]
    message_id_one = message_dic_one["message_id"]
    message_dic_two = message_list[3]
    message_id_two = message_dic_two["message_id"]
    # SETUP END
    
    # Testing for no results
    assert search(token, "???") == []
    
    # Testing for one result
    assert search(token, "Safe") == {"message_id" : message_id_safe, "u_id" : u_id_one, "message" : "Safe and secure society", "time_created" : "19:35", "is_unread" : False}
    
    # Testing for two or more results
    assert search(token, "Hellomy") == [{  
        "message_id" : message_id_one,
        "u_id" : u_id_one, 
        "message" : "Hellomydude",
        "time_created" : "17:35",
        "is_unread" : False
    },
    {
        "message_id" : message_id,
        "u_id" : u_id, 
        "message" : "Helloymyman",
        "time_created" : "18:35",
        "is_unread" : False
    }]
    
    # Testing Bad Cases
    with pytest.raises(ValueError):
        # Bad token with multiple search results
        search(invalid_token, "Hellomy")
        # Bad token with no search results
        search(invalid_token, "ahahahahahaha")