コード例 #1
0
def test_flockr_owner_permissions(register_login, create_channel):
    flockr_owner = register_login

    # Creates a new user who is the owner of a channel
    auth_register("*****@*****.**", "password2", "Richard2", "Shen2")
    user_2 = auth_login("*****@*****.**", "password2")

    c_id = channels_create(user_2["token"], "Channel", True)['channel_id']

    # Create a new user who is not flockr owner, and is a member of a channel,
    # sends a message
    auth_register("*****@*****.**", "password3", "Richard3", "Shen3")
    user_3 = auth_login("*****@*****.**", "password3")
    channel_join(user_3['token'], c_id)
    channel_join(flockr_owner['token'], c_id)

    m_id = message_send(user_3['token'], c_id, "First Message")['message_id']

    message_edit(flockr_owner['token'], m_id, "Edited Message")

    # Check the message was edited correctly
    updated_message = channel_messages(flockr_owner['token'], c_id,
                                       0)['messages'][0]['message']

    assert updated_message == "Edited Message"
コード例 #2
0
def test_member_edits_own_message(register_login, create_channel):
    owner = register_login
    owner_c_id = create_channel['c_id']

    # Creating a new user who is not the owner, and joins the channel as a member
    auth_register("*****@*****.**", "password2", "Richard2", "Shen2")
    user_2 = auth_login("*****@*****.**", "password2")
    channel_join(user_2['token'], owner_c_id)

    # Verify the new user is not an owner
    channel = channel_details(owner['token'], owner_c_id)
    assert user_2['u_id'] not in channel['owner_members']

    # User 2's message id
    user_2_m_id = message_send(user_2['token'], owner_c_id,
                               "Member's Message")['message_id']

    # Ensure that it is user 2's message
    messages = channel_messages(user_2['token'], owner_c_id, 0)['messages']
    assert user_2['u_id'] == messages[0]['u_id']

    # User 2 edits the message
    new_message = "user_2 can edit their own message"
    message_edit(user_2['token'], user_2_m_id, new_message)

    # Ensure the message is edited
    messages = channel_messages(user_2['token'], owner_c_id, 0)['messages']
    assert new_message == messages[0]['message']
コード例 #3
0
def test_multiple_edits(register_login, create_channel):
    owner = register_login
    owner_c_id = create_channel['c_id']

    # 3 messages are created, the 2nd and 3rd will be edited
    message_send(owner['token'], owner_c_id, "Message 1")['message_id']
    edit_request_1 = message_send(owner['token'], owner_c_id,
                                  "Message 2")['message_id']
    edit_request_2 = message_send(owner['token'], owner_c_id,
                                  "Message 3")['message_id']

    # Edit the 2nd message
    edited_message = "Edited Message 2"
    message_edit(owner["token"], edit_request_1, edited_message)

    # Check the 2nd message was editied correctly
    updated_message = channel_messages(owner['token'], owner_c_id,
                                       0)['messages'][1]['message']
    assert edited_message == updated_message

    # Edit the 3rd Message
    edited_message = "Edited Message 3"
    message_edit(owner["token"], edit_request_2, edited_message)

    # Check the 3rd message was editied correctly
    updated_message = channel_messages(owner['token'], owner_c_id,
                                       0)['messages'][2]['message']
    assert edited_message == updated_message
コード例 #4
0
def test_invalid_message_id(register_login, create_channel):
    owner = register_login
    owner_c_id = create_channel['c_id']
    message_send(owner['token'], owner_c_id, "New Message")

    invalid_message_id = -1
    with pytest.raises(AccessError):
        message_edit(owner['token'], invalid_message_id, "Edit Message")
コード例 #5
0
def test_unauthorised_user_message(register_login, create_channel):
    owner = register_login
    owner_c_id = create_channel['c_id']
    owner_m_id = message_send(owner['token'], owner_c_id,
                              "New Message")['message_id']

    # creating a new user who isnt the owner of the channel, and did not create a message
    auth_register("*****@*****.**", "password2", "Richard2", "Shen2")
    user_2 = auth_login("*****@*****.**", "password2")
    channel_join(user_2['token'], owner_c_id)

    # should raise an AccessError since the new user is not an owner of the channel and didn't create the message
    with pytest.raises(AccessError):
        message_edit(user_2['token'], owner_m_id, "Edited Message")
コード例 #6
0
def message_edit_flask():
    payload = request.get_json()

    token = payload['token']
    message_id = payload['message_id']
    message = payload['message']

    return dumps(m.message_edit(token, message_id, message))
コード例 #7
0
def test_owner_edits_user_message(register_login, create_channel):
    owner = register_login
    owner_c_id = create_channel['c_id']

    # Create a new user who is not the owner, and joins the channel as a member
    auth_register("*****@*****.**", "password2", "Richard2", "Shen2")
    user_2 = auth_login("*****@*****.**", "password2")
    channel_join(user_2['token'], owner_c_id)

    user_2_m_id = message_send(user_2['token'], owner_c_id,
                               "User 2's Message")['message_id']

    # Ensure that the owner can edit user 2's message
    owner_message = "Owner has authority to edit"
    message_edit(owner['token'], user_2_m_id, owner_message)

    message = channel_messages(owner['token'], owner_c_id, 0)
    assert owner_message == message['messages'][0]['message']
コード例 #8
0
def test_empty_message(register_login, create_channel):
    owner = register_login
    owner_c_id = create_channel['c_id']

    # Create 3 messages
    message_send(owner['token'], owner_c_id, "Message 1")['message_id']
    owner_m_id = message_send(owner['token'], owner_c_id,
                              "Message 2")['message_id']
    message_send(owner['token'], owner_c_id, "Message 3")['message_id']

    all_messages = channel_messages(owner['token'], owner_c_id, 0)['messages']
    message_1 = channel_messages(owner['token'], owner_c_id, 0)['messages'][0]
    message_3 = channel_messages(owner['token'], owner_c_id, 0)['messages'][2]

    # Deletes the 2nd message
    empty_message = ""
    assert len(all_messages) == 3
    message_edit(owner["token"], owner_m_id, empty_message)

    # Ensure that the right message was removed
    all_messages = channel_messages(owner['token'], owner_c_id, 0)['messages']
    assert len(all_messages) == 2

    assert all_messages == [message_1, message_3]