Exemplo n.º 1
0
def test_sender_message_remove_success(channel_with_user, ):
    owner = channel_with_user

    # Create second user who will send the message
    auth_register("*****@*****.**", "password", "First", "Last")
    sender = auth_login("*****@*****.**", "password")
    channel_join(sender['token'], owner['c_id'])

    # Ensure there's no messages in the channel to begin with
    messages = channel_messages(owner['token'], owner['c_id'], 0)['messages']
    assert not messages

    # Send the message with a user other than the owner
    message_id = message_send(sender['token'], owner['c_id'], "Test Message")

    # Verify the message was sent inbetween creating and removing
    message = channel_messages(owner['token'], owner['c_id'], 0)['messages']

    assert message[0]['message_id'] == 0
    assert message[0]['u_id'] == 1
    assert message[0]['message'] == 'Test Message'

    # Remove message
    message_remove(sender['token'], message_id['message_id'])

    # Verify that the message was removed
    messages = channel_messages(owner['token'], owner['c_id'], 0)['messages']
    assert not messages
Exemplo n.º 2
0
def test_flockr_owner_remover(channel_with_user):
    clear()
    # Creating the flockr owner
    auth_register("*****@*****.**", "flockr_ownerpassword",
                  "flockr_ownerFirstname", "flockr_ownerLastname")
    flockr_owner = auth_login("*****@*****.**", "flockr_ownerpassword")

    # Creating the owner and their own channel
    auth_register("*****@*****.**", "ownerpassword", "ownerFirstname",
                  "ownerLastname")
    owner = auth_login("*****@*****.**", "ownerpassword")
    public = True
    channel_id = channels_create(owner['token'], "Channel", public)

    # Creating the message via the owner
    message_id = message_send(owner['token'], channel_id['channel_id'],
                              "Test Message 1")
    message = channel_messages(owner['token'], channel_id['channel_id'],
                               0)['messages']
    # assert message == [
    #     {'message_id': 0, 'u_id': 1, 'message': 'Test Message 1', 'time_created': timestamp}
    # ]
    assert message[0]['message_id'] == 0
    assert message[0]['u_id'] == 1
    assert message[0]['message'] == 'Test Message 1'

    # Removing the message via the flockr owner
    message_remove(flockr_owner['token'], message_id['message_id'])
    messages = channel_messages(owner['token'], channel_id['channel_id'],
                                0)['messages']
    assert not messages
Exemplo n.º 3
0
def test_multiple_messages_success(channel_with_user):
    owner = channel_with_user

    # Ensure there's no messages in the channel to begin with
    messages = channel_messages(owner['token'], owner['c_id'], 0)['messages']
    assert not messages

    # Assumption: No need to test whether a message has been sent with message_send as this would be covered by message_send functions
    # Send 2 messages
    message_to_remove = message_send(owner['token'], owner['c_id'],
                                     "Test Message 1")
    message_send(owner['token'], owner['c_id'], "Test Message 2")

    # Verify the message was sent inbetween creating and removing
    message = channel_messages(owner['token'], owner['c_id'], 0)['messages']

    assert message[0]['message_id'] == 0
    assert message[0]['u_id'] == 0
    assert message[0]['message'] == 'Test Message 1'

    assert message[1]['message_id'] == 1
    assert message[1]['u_id'] == 0
    assert message[1]['message'] == 'Test Message 2'

    # Remove 1st message
    message_remove(owner['token'], message_to_remove['message_id'])

    # Verify that the 2nd message has become the first message in the channel
    message = channel_messages(owner['token'], owner['c_id'], 0)['messages']

    assert message[0]['message_id'] == 1
    assert message[0]['u_id'] == 0
    assert message[0]['message'] == 'Test Message 2'
Exemplo n.º 4
0
def test_invalid_message_id(channel_with_user):
    owner = channel_with_user

    message_send(owner['token'], owner['c_id'], "Test Message 1")

    invalid_message_id = -1
    with pytest.raises(InputError):
        message_remove(owner['token'], invalid_message_id)
Exemplo n.º 5
0
def test_reused_message_id(channel_with_user):
    owner = channel_with_user

    # Ensure there's no messages in the channel to begin with
    messages = channel_messages(owner['token'], owner['c_id'], 0)['messages']
    assert not messages

    # Send message
    message_id = message_send(owner['token'], owner['c_id'], "Test Message 1")
    message_remove(owner['token'], message_id['message_id'])

    # Failed message removal due to message already having been removed
    with pytest.raises(InputError):
        message_remove(owner['token'], message_id['message_id'])
Exemplo n.º 6
0
def message_remove_flask():
    payload = request.get_json()

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

    return dumps(m.message_remove(token, message_id))
Exemplo n.º 7
0
def test_unauthorised_remover(channel_with_user):
    owner = channel_with_user

    # Ensure there's no messages in the channel to begin with
    messages = channel_messages(owner['token'], owner['c_id'], 0)['messages']
    assert not messages

    # Send the first message
    message_id = message_send(owner['token'], owner['c_id'], "Test Message 1")

    # Register a second user
    auth_register("*****@*****.**", "password1", "unauthorised",
                  "remover")
    unauthorised_remover = auth_login("*****@*****.**", "password1")
    channel_join(unauthorised_remover['token'], owner['c_id'])

    # Access Error, as the user trying to remove the message did not send it and is not an owner
    with pytest.raises(AccessError):
        message_remove(unauthorised_remover['token'], message_id['message_id'])
Exemplo n.º 8
0
def test_owner_message_remove_success(channel_with_user):
    owner = channel_with_user

    # Ensure there's no messages in the channel to begin with
    messages = channel_messages(owner['token'], owner['c_id'], 0)['messages']
    assert not messages

    # Send message
    message_id = message_send(owner['token'], owner['c_id'], "Test Message 1")

    # Verify the message was sent inbetween creating and removing
    message = channel_messages(owner['token'], owner['c_id'], 0)['messages']

    assert message[0]['message_id'] == 0
    assert message[0]['u_id'] == 0
    assert message[0]['message'] == 'Test Message 1'

    # Remove message
    message_remove(owner['token'], message_id['message_id'])

    # Verify that the message was removed
    messages = channel_messages(owner['token'], owner['c_id'], 0)['messages']
    assert not messages