def test_message_sendlater():
    jsonClean()
    # SETUP BEGIN

    # Generate a valid user
    registerValidUserDict = auth_register("*****@*****.**", "password",
                                          "Thom", "Browne")
    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 = "I Heart Thom Browne"
    timesent = present + timedelta(minutes=1) + tdelta

    # Generate an invalid user
    registerInvalidUserDict = auth_register("*****@*****.**", "password",
                                            "Thom", "Browne")
    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)
    invalid_message = 0
    invalid_timesent = "20/10/1999"

    # Invalidate the invalid user
    auth_logout(invalid_token)

    # SET UP END

    # Asserting that the default case works
    message_id = message_sendlater(token, channel_id, message, timesent)
    time.sleep(60)

    data = getData()
    for channels in data['channels']:
        for messages in channels['messages']:
            if messages['message'] == message:
                assert messages['message_id'] == message_id['message_id']

    # Testing that ValueError is raised when invalid parameters are passed
    with pytest.raises(ValueError):

        # Testing function with an invalid token
        message_sendlater(invalid_token, channel_id, message, timesent)

        # Testing function with an invalid channel id
        message_sendlater(token, invalid_channelid, message, timesent)

        # Testing function with an invalid message
        message_sendlater(token, channel_id, invalid_message, timesent)

        # Testing function with an invalid timesent input
        message_sendlater(token, channel_id, message, invalid_timesent)
Example #2
0
def test_message_send():
    jsonClean()
    # SETUP BEGIN

    # Generate a valid user
    registerValidUserDict = auth_register("*****@*****.**", "valid6password",
                                          "first6name", "last6name")
    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 = "I Heart Hayden Smith"

    # Generate an invalid user
    registerInvalidUserDict = auth_register("*****@*****.**",
                                            "invalid6password",
                                            "invalid6firstname",
                                            "invalid6lastname")
    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)
    invalid_message = 0

    # Invalidate the invalid user
    auth_logout(invalid_token)

    # SETUP END

    # Asserting that the default case works
    message_id = message_send(token, channel_id, message)

    data = getData()
    for channels in data['channels']:
        for messages in channels['messages']:
            if messages['message'] == message:
                assert messages['message_id'] == message_id['message_id']

    # Testing that ValueError is raised when invalid parameters are passed
    with pytest.raises(ValueError):

        # Testing function with an invalid token
        message_send(invalid_token, channel_id, message)

        # Testing function with an invalid channel id
        message_send(token, invalid_channelid, message)

        # Testing function with an invalid message
        message_send(token, channel_id, invalid_message)
Example #3
0
def test_channel_invite_bad(): 
    # SET UP BEGIN 
    jsonClean()
    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']
    channelsCreateDicOne = channels_create(token_one, "validchannel1", True)
    channel_id_one = channelsCreateDicOne['channel_id']
    
    authRegisterDicTwo = auth_register("*****@*****.**", "validpassword2", "firstname2", "lastname2")
    token_two = authRegisterDicTwo['token']
    u_id_two = authRegisterDicTwo['u_id']
    # SETUP END
    with pytest.raises(ValueError): 
        # Testing function with invalid channel_id
        channel_invite(token, "invalidchannel_id", u_id_one)
        # Testing function with channel_id which the authorised user isn't a member of
        channel_invite(token, channel_id_one, u_id_two)
        # Testing function with an invalid u_id
        channel_invite(token, channel_id, "invalidu_id")
        
    auth_logout(token_one)

    with pytest.raises(ValueError): 
        # Testing function with invalid token
        channel_invite(token_one, channel_id_one, u_id_two)
Example #4
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)
Example #5
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])
Example #6
0
def test_channel_invite(): 
    jsonClean()
    # SET UP BEGIN 
    authRegisterDic = auth_register("*****@*****.**", "validpassword", "first6name", "last6name")
    token = authRegisterDic['token']
    u_id = authRegisterDic['u_id']
    channelsCreateDic = channels_create(token, "validchannel", True)
    channel_id = channelsCreateDic['channel_id']
    
    authRegisterDicOne = auth_register("*****@*****.**", "validpassword1", "first8name1", "last8name1")
    token_one = authRegisterDicOne['token']
    u_id_one = authRegisterDicOne['u_id']
    # SETUP END 
    
    channel_invite(token, channel_id, u_id_one)
    # Asserting that the invited user is now a member of the channel
    assert channel_details(token_one, channel_id) == {"name": "validchannel", "owner_members": [{"u_id": u_id, "name_first": "first6name", "name_last": "last6name"}], "all_members": [{"u_id": u_id, "name_first": "first6name", "name_last": "last6name"}, {"u_id": u_id_one, "name_first": "first8name1", "name_last": "last8name1"}]}
    # Testing channel_leave to check that he's a member of the channel
    channel_leave(token_one, channel_id)
Example #7
0
def test_standup_send():
    jsonClean()
    # Generate a valid user
    registerValidUserDict = auth_register("*****@*****.**", "feelspecial",
                                          "Hwang", "Yeji")
    token = registerValidUserDict["token"]
    u_id = registerValidUserDict["u_id"]
    createValidChannelDict = channels_create(token, "validchannel", True)
    channel_id = createValidChannelDict["channel_id"]
    message = "I Heart Hwang Yeji"
    message_list = createValidChannelDict['messages']
    message_dict = message_list[0]
    message_id = message_dict["message_id"]

    time = "19:16/02/10"

    # Generate an invalid user
    registerInvalidUserDict = auth_register("*****@*****.**", "password",
                                            "Kang", "Daniel")
    invalid_token = registerInvalidUserDict["token"]
    invalid_uid = registerInvalidUserDict["u_id"]
    createInvalidChannelDict = channels_create(invalid_token, "invalidchannel",
                                               True)
    invalid_channelid = createInvalidChannelDict["channel_id"]
    channel_invite(invalid_token, invalid_channelid, invalid_uid)
    invalid_message = 0

    # Asserting that the default case works
    assert standup_send(token, channel_id, message) == {}

    # Testing that ValueError is raised when invalid parameters are passed
    with pytest.raises(ValueError):

        # Testing function with an invalid token
        standup_send(invalid_token, channel_id, message)

        # Testing function with an invalid channel id
        standup_send(token, invalid_channelid, message)

        # Testing function with an invalid message
        standup_send(token, channel_id, invalid_message)
Example #8
0
def wrap_channel_invite():
    channel_invite(request.form.get('token'), request.form.get('channel_id'),
                   request.form.get('u_id'))
    return json.dumps({})
Example #9
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")