Exemplo n.º 1
0
def test_standup_active():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    finish_time = standup_start(user_info1['token'], 0, 1)
    standup_send(user_info1['token'], 0, "hi")
    standup_send(user_info1['token'], 0, "lol")

    data = getData()
    assert standup_active(user_info1, 0) == {
        'is_active': True,
        'time_finish': finish_time['time_finish']
    }

    sleep(1)
    assert standup_active(user_info1, 0) == {
        'is_active': False,
        'time_finish': finish_time['time_finish']
    }

    # Channel ID: is not a valid channel
    with pytest.raises(Value_Error):
        standup_active(user_info1, 1)

    save(clear_data())
Exemplo n.º 2
0
def test_message_edit():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "321654", "Frank", "Li")
    user_info3 = register("*****@*****.**", "456789", "Frank", "Li")
    create(user_info1['token'], 'lol', True)
    invite(user_info1['token'], 0, user_info2['u_id'])
    send(user_info2['token'], 0, "first message")

    edit(user_info1['token'], 0, "new first message")
    data = getData()
    assert (data['messages'][0]['message'] == "new first message")

    edit(user_info2['token'], 0, "second new first message")
    data = getData()
    assert (data['messages'][0]['message'] == "second new first message")

    # a normal member who doesn't send message wants to edit it
    with pytest.raises(AccessError):
        edit(user_info3['token'], 0, "not possible")

    # a member in channel but not the owner who doesn't send message wants to edit it
    invite(user_info1['token'], 0, user_info3['u_id'])
    with pytest.raises(AccessError):
        edit(user_info3['token'], 0, "not possible")

    # now member 3 is a admin
    data = getData()
    data['users'][2]['permission'] = 2
    edit(user_info1['token'], 0, "final message")
    data = getData()
    assert (data['messages'][0]['message'] == "final message")
    save(clear_data())
Exemplo n.º 3
0
def test_message_react():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    send(user_info1['token'], 0, "first message")
    react(user_info1['token'], 0, 1)

    data = getData()
    assert len(data['messages'][0]['reacts'][0]['u_ids']) == 1

    # sencond user create a channel and send a msg
    create(user_info2['token'], 'lol', True)
    send(user_info2['token'], 1, "second message")

    data = getData()
    assert len(data['messages']) == 2

    # Not a valid message within a channel that the authorised user has joined
    with pytest.raises(Value_Error):
        react(user_info1['token'], 1, 1)

    # Not a valid react_id
    with pytest.raises(Value_Error):
        react(user_info2['token'], 1, 0)

    # Message already contains active react with same react_id
    react(user_info2['token'], 1, 1)
    data = getData()
    assert len(data['messages'][1]['reacts'][0]['u_ids']) == 1

    with pytest.raises(Value_Error):
        react(user_info2['token'], 1, 1)

    save(clear_data())
Exemplo n.º 4
0
def test_join():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    join(user_info2['token'], 0)

    data = getData()
    assert len(data['channels_list'][0]['members']) == 2

    # nothing change if join the same ppl
    join(user_info2['token'], 0)
    data = getData()
    assert len(data['channels_list'][0]['members']) == 2

    # Channel ID is not a valid channel
    leave(user_info2['token'], 0)
    with pytest.raises(Value_Error):
        join(user_info2['token'], 1)

    # a private channel can only be joined by invitation
    create(user_info1['token'], 'lol', False)
    with pytest.raises(AccessError):
        join(user_info2['token'], 1)
    save(clear_data())
Exemplo n.º 5
0
def test_standup_start_send():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    finish_time = standup_start(user_info1['token'], 0, 10)
    standup_send(user_info1['token'], 0, "hi")
    standup_send(user_info1['token'], 0, "lol")

    data = getData()
    assert (len(data['messages']) == 1
            and data['messages'][0]['time_created'].replace(
                tzinfo=timezone.utc).timestamp() == finish_time['time_finish'])
    # An active standup is currently running in this channel
    with pytest.raises(Value_Error):
        finish_time = standup_start(user_info1['token'], 0, 10)

    # Channel ID: is not a valid channel
    with pytest.raises(Value_Error):
        finish_time = standup_start(user_info1['token'], 1, 10)

    # standup_send: Channel ID: is not a valid channel
    with pytest.raises(Value_Error):
        standup_send(user_info1['token'], 1, "hi")

    # standup_send: Message is more than 1000 characters
    with pytest.raises(Value_Error):
        standup_send(user_info1['token'], 0, "hi" * 1000)

    # The authorised user is not a member of the channel that the message is within
    with pytest.raises(AccessError):
        finish_time = standup_start(user_info2['token'], 0, 10)

    # standup_send: The authorised user is not a member of the channel that the message is within
    with pytest.raises(AccessError):
        standup_send(user_info2['token'], 0, "hi")

    save(clear_data())

    # standup_send: An active standup is not currently running in this channel
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)

    # The authorised user is not a member of the channel that the message is within
    with pytest.raises(Value_Error):
        standup_send(user_info1['token'], 0, "hi")

    save(clear_data())
Exemplo n.º 6
0
def test_message_unreact():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    send(user_info1['token'], 0, "first message in first channel")
    react(user_info1['token'], 0, 1)

    data = getData()
    assert len(data['messages'][0]['reacts'][0]['u_ids']) == 1

    # sencond user create a channel and send a msg and react by itself
    create(user_info2['token'], 'lol', True)
    send(user_info2['token'], 1, "first message in second channel")
    react(user_info2['token'], 1, 1)

    data = getData()
    assert len(data['messages']) == 2

    # Not a valid message within a channel that the authorised user has joined
    with pytest.raises(Value_Error):
        unreact(user_info1['token'], 1, 1)

    # Not a valid react_id
    with pytest.raises(Value_Error):
        unreact(user_info2['token'], 1, 0)

    # Message with ID message_id does not contain an active React with ID react_id
    send(user_info2['token'], 1, "third message")
    data = getData()
    assert len(data['messages'][2]['reacts'][0]['u_ids']) == 0

    with pytest.raises(Value_Error):
        unreact(user_info2['token'], 2, 1)

    # pass test
    unreact(user_info2['token'], 1, 1)
    data = getData()
    assert len(data['messages'][1]['reacts'][0]['u_ids']) == 0

    save(clear_data())
Exemplo n.º 7
0
def test_search():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    send(user_info1['token'], 0, "first message")
    send(user_info1['token'], 0, "second message")

    messages = search(user_info1['token'], 'mess')
    assert len(messages['messages']) == 2

    messages = search(user_info1['token'], 'p')
    assert len(messages['messages']) == 0

    messages = search(user_info1['token'], '')
    assert len(messages['messages']) == 0

    messages = search(user_info1['token'], 'second')
    assert len(messages['messages']) == 1

    save(clear_data())
Exemplo n.º 8
0
def test_addowner_and_remove():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    join(user_info2['token'], 0)

    addowner(user_info1['token'], 0, user_info2['u_id'])
    data = getData()
    assert len(data['channels_list'][0]['owners']) == 2

    removeowner(user_info1['token'], 0, user_info2['u_id'])
    data = getData()
    assert len(data['channels_list'][0]['owners']) == 1

    # Channel ID is not a valid channel
    with pytest.raises(Value_Error):
        addowner(user_info1['token'], 1, user_info2['u_id'])

    # you don't have the right to access to add owner
    with pytest.raises(AccessError):
        addowner(user_info2['token'], 0, user_info2['u_id'])

    # you don't have the right to access to remove owner
    with pytest.raises(AccessError):
        removeowner(user_info2['token'], 0, user_info2['u_id'])

    # the user id is already an owner
    addowner(user_info1['token'], 0, user_info2['u_id'])
    data = getData()
    assert len(data['channels_list'][0]['owners']) == 2

    with pytest.raises(Value_Error):
        addowner(user_info1['token'], 0, user_info2['u_id'])

    # Channel ID: is not a valid channel
    with pytest.raises(Value_Error):
        removeowner(user_info1['token'], 1, user_info2['u_id'])

    save(clear_data())
Exemplo n.º 9
0
def test_message_sendlater():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    sent_time_before = dt.utcnow() - timedelta(minutes=15)
    sent_time_after = dt.utcnow() + timedelta(minutes=15)
    sendlater(user_info1['token'], 0, "first message", sent_time_after)

    data = getData()
    assert (data['messages'][0]['message'] == "first message"
            and data['messages'][0]['time_created'] == sent_time_after)

    # Channel ID: is not a valid channel
    with pytest.raises(Value_Error):
        sendlater(user_info1['token'], 1, "second message", sent_time_after)

    # Message is more than 1000 characters
    with pytest.raises(Value_Error):
        sendlater(user_info1['token'], 0, "second message" * 500,
                  sent_time_after)

    # the authorised user has not joined the channel they are trying to post to
    with pytest.raises(AccessError):
        sendlater(user_info2['token'], 0, "second message", sent_time_after)

    # Time sent is a time in the past
    with pytest.raises(Value_Error):
        sendlater(user_info1['token'], 0, "second message", sent_time_before)

    # if the given time type is not datetime
    sendlater(user_info1['token'], 0, "first message",
              sent_time_after.replace(tzinfo=timezone.utc).timestamp())

    data = getData()
    assert (data['messages'][0]['message'] == "first message"
            and data['messages'][0]['time_created'] == sent_time_after)
    save(clear_data())
Exemplo n.º 10
0
def test_message_remove():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    send(user_info1['token'], 0, "first message")
    remove(user_info1['token'], 0)

    data = getData()
    assert len(data['messages']) == 0

    # Message (based on ID) no longer exists
    send(user_info1['token'], 0, "first message")
    remove(user_info1['token'], 0)
    with pytest.raises(Value_Error):
        remove(user_info1['token'], 0)

    # Message with message_id was not sent by the authorised user making this request and The authorised user is not an admin or owner of this channel or the slackr
    send(user_info1['token'], 0, "first message")
    with pytest.raises(Value_Error):
        remove(user_info2['token'], 0)

    save(clear_data())
Exemplo n.º 11
0
def test_message_send():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    send(user_info1['token'], 0, "first message")

    data = getData()
    assert data['messages'][0]['message'] == "first message"

    send(user_info1['token'], 0, "second message")
    data = getData()
    assert len(data['messages']) == 2

    # Message is more than 1000 characters
    with pytest.raises(Value_Error):
        send(user_info1['token'], 0, "second message" * 500)

    # the authorised user has not joined the channel they are trying to post to
    with pytest.raises(AccessError):
        send(user_info2['token'], 0, "second message")

    save(clear_data())
Exemplo n.º 12
0
def test_channel_leave():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    invite(user_info1['token'], 0, user_info2['u_id'])

    data = getData()
    assert len(data['channels_list'][0]['members']) == 2

    # Channel ID is not a valid channel
    with pytest.raises(Value_Error):
        leave(user_info2['token'], 1)

    leave(user_info2['token'], 0)
    data = getData()
    assert len(data['channels_list'][0]['members']) == 1

    # leave again, and it should have no change
    leave(user_info2['token'], 0)
    data = getData()
    assert len(data['channels_list'][0]['members']) == 1
    save(clear_data())
Exemplo n.º 13
0
def test_channel_invite():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    user_info3 = register("*****@*****.**", "12345678", "Frank", "Li")

    # channel_id does not refer to a valid channel that the authorised user is part of
    create(user_info1['token'], 'lol', True)
    with pytest.raises(Value_Error):
        invite(user_info1['token'], 2, user_info2['u_id'])

    # u_id does not refer to a valid user
    with pytest.raises(Value_Error):
        invite(user_info1['token'], 0, 4)

    #  AccessError whenthe authorised user is not already a member of the channel
    with pytest.raises(AccessError):
        invite(user_info2['token'], 0, user_info1['u_id'])

    #  AccessError whenthe authorised user is not already a member of the channel
    with pytest.raises(AccessError):
        invite(user_info3['token'], 0, user_info2['u_id'])

    invite(user_info1['token'], 0, user_info2['u_id'])
    data = getData()

    assert {
        'u_id': user_info2['u_id'],
        'profile_img_url': '/user_image?file=default.jpg',
        'name_first': data['users'][user_info2['u_id']]['name_first'],
        'name_last': data['users'][user_info2['u_id']]['name_last']
    } in data['channels_list'][0]['members']

    invite(user_info1['token'], 0, user_info2['u_id'])
    data = getData()
    assert len(data['channels_list'][0]['members']) == 2
    save(clear_data())
Exemplo n.º 14
0
def test_channel_messages():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    send(user_info1['token'], 0, "first message")
    send(user_info1['token'], 0, "second message")

    channel_message = messages(user_info1['token'], 0, 0)
    assert (len(channel_message['messages'])
            == 2) and (channel_message['start'] == 0
                       and channel_message['end'] == -1)

    channel_message = messages(user_info1['token'], 0, 1)
    assert (len(channel_message['messages'])
            == 1) and (channel_message['start'] == 1
                       and channel_message['end'] == -1)

    edit(user_info1['token'], 0, '')
    channel_message = messages(user_info1['token'], 0, 0)
    assert (len(channel_message['messages'])
            == 1) and (channel_message['start'] == 0
                       and channel_message['end'] == -1)

    # start is greater than or equal to the total number of messages in the channel
    with pytest.raises(Value_Error):
        channel_message = messages(user_info1['token'], 0, 2)

    # Channel ID: is not a valid channel
    with pytest.raises(Value_Error):
        channel_message = messages(user_info1['token'], 1, 0)

    # Authorised user is not a member of channel with channel_id
    with pytest.raises(AccessError):
        channel_message = messages(user_info2['token'], 0, 0)

    save(clear_data())
Exemplo n.º 15
0
def test_message_unpin():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    send(user_info1['token'], 0, "first message")
    pin(user_info1['token'], 0)
    unpin(user_info1['token'], 0)
    data = getData()
    assert data['messages'][0]['is_pinned'] == False

    # Message_Id is not a valid message
    with pytest.raises(Value_Error):
        unpin(user_info1['token'], 1)

    # Message with ID message_id already pinned
    with pytest.raises(Value_Error):
        unpin(user_info1['token'], 0)

# The user is not an admin
    with pytest.raises(Value_Error):
        unpin(user_info2['token'], 0)

    save(clear_data())

    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info2['token'], 'lol', True)
    send(user_info2['token'], 0, "first message")

    # The authorised user is not a member of the channel that the message is within
    with pytest.raises(AccessError):
        unpin(user_info1['token'], 0)

    save(clear_data())
Exemplo n.º 16
0
def test_detail():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    create(user_info2['token'], 'wtf', True)
    # check channel_deatil
    assert details(user_info1['token'], 0) == {
        'name':
        'lol',
        'owner_members': [{
            'u_id': user_info1['u_id'],
            'profile_img_url': '/user_image?file=default.jpg',
            'name_first': "minglang",
            'name_last': "xie"
        }],
        'all_members': [{
            'u_id': user_info1['u_id'],
            'profile_img_url': '/user_image?file=default.jpg',
            'name_first': "minglang",
            'name_last': "xie"
        }],
    }
    save(clear_data())

    # Channel ID is not a valid channel
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    with pytest.raises(Value_Error):
        details(user_info1['token'], 1)
    save(clear_data())

    # Authorised user is not a member of channel with channel_id
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    with pytest.raises(AccessError):
        details(user_info2['token'], 0)
    save(clear_data())
Exemplo n.º 17
0
def channel_create():
    """ return channel id """
    result = create(request.form.get('token'), request.form.get('name'),
                    request.form.get('is_public'))
    return dumps(result)
Exemplo n.º 18
0
def test_create_list_listall():

    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")

    #check when people join or created no channel
    assert user_channel_list(user_info1['token']) == {'channels': []}
    assert listall(user_info1['token']) == {'channels': []}

    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    create(user_info2['token'], 'wtf', True)

    # check channel_id and diff ppl create a channel
    assert user_channel_list(user_info1['token']) == {
        'channels': [{
            'channel_id': 0,
            'name': 'lol'
        }]
    }
    assert user_channel_list(user_info2['token']) == {
        'channels': [{
            'channel_id': 1,
            'name': 'wtf'
        }]
    }
    # check channel_list_all
    assert listall(user_info1['token']) == {
        'channels': [{
            'channel_id': 0,
            'name': 'lol'
        }, {
            'channel_id': 1,
            'name': 'wtf'
        }]
    }
    assert listall(user_info1['token']) == listall(user_info2['token'])
    # check channel_deatil
    assert details(user_info1['token'], 0) == {
        'name':
        'lol',
        'owner_members': [{
            'u_id': user_info1['u_id'],
            'profile_img_url': '/user_image?file=default.jpg',
            'name_first': "minglang",
            'name_last': "xie"
        }],
        'all_members': [{
            'u_id': user_info1['u_id'],
            'profile_img_url': '/user_image?file=default.jpg',
            'name_first': "minglang",
            'name_last': "xie"
        }],
    }
    save(clear_data())

    # the token doesn't exist
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    data = getData()
    token = generateToken(len(data['users']))
    with pytest.raises(Value_Error):
        create(token, 'lol', True)
    save(clear_data())

    #check channel_create: the name is longer than 20 character
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    with pytest.raises(Value_Error):
        create(user_info1['token'], 'lol' * 20, True)
    save(clear_data())