Beispiel #1
0
def test_channel_leave_bad():

    jsonClean()
    # SET UP 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']

    authRegisterDicTwo = auth_register("*****@*****.**", "validpassword2",
                                       "firstname2", "lastname2")
    token_two = authRegisterDicTwo['token']
    u_id_two = authRegisterDicTwo['u_id']
    # SETUP END
    channel_join(token_one, channel_id)
    with pytest.raises(ValueError):
        # Testing function using invalid channel_id
        channel_leave(token_one, "invalidchannel_id")
        # Testing function on user who isn't part of the channel
        channel_leave(token_two, channel_id)

    auth_logout(token_one)
    with pytest.raises(ValueError):
        # Testing function using invalid token
        channel_leave(token_one, channel_id)
Beispiel #2
0
def test_channel_join():
    jsonClean()
    # SET UP BEGIN
    authRegisterDic = auth_register("*****@*****.**", "validpassword",
                                    "first100name", "last100name")
    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']
    # SETUP END

    channel_join(token_one, channel_id)

    # checking output matches local data base
    data = getData()
    for channels in data['channels']:
        if channels['channel_id'] == channel_id:
            assert channels['all_members'] == [{
                "u_id": u_id,
                "name_first": "first100name",
                "name_last": "last100name"
            }, {
                "u_id": u_id_one,
                "name_first": "firstname1",
                "name_last": "lastname1"
            }]

    # Assuming admin isn't in all_members list since admin was specifically isn't a member
    assert channel_details(token, channel_id) == {
        "name":
        "validchannel",
        "owner_members": [{
            "u_id": u_id,
            "name_first": "first100name",
            "name_last": "last100name"
        }],
        "all_members": [{
            "u_id": u_id,
            "name_first": "first100name",
            "name_last": "last100name"
        }, {
            "u_id": u_id_one,
            "name_first": "firstname1",
            "name_last": "lastname1"
        }]
    }
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)
Beispiel #4
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)
Beispiel #5
0
def test_channel_join_bad():
    jsonClean()
    # SET UP BEGIN
    authRegisterDic = auth_register("*****@*****.**", "validpassword",
                                    "first10name", "last10name")
    token = authRegisterDic['token']
    u_id = authRegisterDic['u_id']
    channelsCreateDic = channels_create(token, "validchannel", False)
    channel_id = channelsCreateDic['channel_id']

    authRegisterDicOne = auth_register("*****@*****.**", "validpassword1",
                                       "first20name1", "last20name1")
    token_one = authRegisterDicOne['token']
    u_id_one = authRegisterDicOne['u_id']
    # SETUP END

    with pytest.raises(ValueError):
        # Testing function with invalid channel_id
        channel_join(token_one, "invalidchannel_id")
        # Testing function with unauthorised token when channel is private
        channel_join(token_one, channel_id)

    # Invalidate token
    auth_logout(token_one)

    with pytest.raises(ValueError):
        # Testing function with invalid token
        channel_join(token_one, channel_id)
Beispiel #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) == {}
Beispiel #7
0
def wrap_channel_join():
    channel_join(request.form.get('token'), request.form.get('channel_id'))
    return json.dumps({})