Exemple #1
0
def test_remove_twice():
    '''Cannot remove a message twice'''
    reset_data()
    data = auth_register('*****@*****.**', 'cs1531', 'Kevin', 'Trang')
    token = data['token']
    channel_id = channels_create(token, 'Channel One', True)
    message_id = message_send(token, channel_id['channel_id'], 'Hello World')
    message_remove(token, message_id['message_id'])
    with pytest.raises(InputError):
        message_remove(token, message_id['message_id'])
Exemple #2
0
def test_remove_other():
    '''Cannot remove another user's message when user is not owner'''
    reset_data()
    data = auth_register('*****@*****.**', 'cs1531', 'Kevin', 'Trang')
    token = data['token']
    channel_id = channels_create(token, 'Channel One', True)
    message_id = message_send(token, channel_id['channel_id'], 'Hello World')
    data_two = auth_register('*****@*****.**', 'IZ*ONE', 'Yena', 'Choi')
    token_two = data_two['token']
    channel_join(token_two, channel_id['channel_id'])
    with pytest.raises(AccessError):
        message_remove(token_two, message_id['message_id'])
Exemple #3
0
def test_message_remove():
    '''This function will remove a message'''
    reset_data()
    data = auth_register('*****@*****.**', 'cs1531', 'Kevin', 'Trang')
    token = data['token']
    channel_id = channels_create(token, 'Channel One', True)
    message_id = message_send(token, channel_id['channel_id'], 'Hello World')
    assert message_remove(token, message_id['message_id']) == {}
def user_remove(token, u_id):
    email = check_token(token)
    database = get_data()
    for user in database["users"]:
        if user["email"] == email:
            if user["permissions"]["global"] != 1:
                raise AccessError(description='Given token is not from owner')
    for user in database["users"]:
        if user["u_id"] == u_id:
            for channel in database["channels"]:
                if u_id in channel["members"]:
                    for message in channel['messages']:
                        if message['u_id'] == u_id:
                            message_remove(token, message['message_id'])
                if u_id in channel['owners']:
                    channel_removeowner(token, channel['channel_id'], u_id)
                elif u_id in channel["members"]:
                    channel["members"].remove(u_id)
            database["users"].remove(user)
            with open('data_store.json', 'w') as FILE:
                json.dump(database, FILE)
            return {}
    raise InputError(description='Invalid u_id')
Exemple #5
0
def remove():
    '''Removes a message with the user's token and message id'''
    details = request.get_json()
    return dumps(message_remove(details["token"], details["message_id"]))