Beispiel #1
0
def test_user_profile():
    ''' Tests user_profile function'''
    reset_data()
    # SETUP START
    output = auth_register("*****@*****.**", "validPW", "tom", "cruise")
    u_id = output['u_id']
    # SETUP END

    # Valid user
    assert user_profile(server_data.data['users'][u_id]['token'], u_id) == {
        'u_id': server_data.data['users'][u_id]['u_id'],
        'email': server_data.data['users'][u_id]['email'],
        'name_first': server_data.data['users'][u_id]['name_first'],
        'name_last': server_data.data['users'][u_id]['name_last'],
        'handle_str': server_data.data['users'][u_id]['handle_str'],
        'profile_img_url': server_data.data['users'][u_id]['handle_str']
    }

    # Invalid user
    with pytest.raises(ValueError):
        user_profile(server_data.data['users'][u_id]['token'], 999)

    # Invalid token:
    with pytest.raises(AccessError):
        user_profile("Invalid token", 0)
Beispiel #2
0
def test_user_profile():
    reset_data()
    #SETUP Begin - initialisation of variables for calling the function
    authRegDict1 = auth_register("*****@*****.**", "qwerty", "John", "Smith")
    auth_login("*****@*****.**", "qwerty")
    token1 = authRegDict1['token']
    userId1 = authRegDict1['u_id']
    #SETUP End

    #Test Case 1: successful case where calling user_profile returns the desired result
    assert user_profile(token1, userId1)['email'] == "*****@*****.**"

    #Test Case 2: Unsuccessful case where an invalid user ID is provided
    with pytest.raises(ValueError, match='not a valid u_id'):
        # the uis 10 do not exist
        user_profile(token1, 10)

    auth_logout(token1)
    reset_data()
Beispiel #3
0
def userProfile():
    '''For a valid user, returns information about
    their email, first name, last name, and handle'''

    token = request.args.get('token')
    u_id = request.args.get('u_id')
    try:
        return dumps(user_profile(token, u_id))
    except ValueError as e:
        raise e
    except AccessError as e:
        raise e
Beispiel #4
0
def user_profile_details():
    """List details"""
    token = request.args.get('token')
    u_id = request.args.get('u_id')
    try:
        output = user_profile(str(token), int(u_id))
    except ValueError as e:
        return str(e)
    except AccessError as e:
        return dumps({
            'code': 400,
            'name': 'AccessError',
            'message': str(e)
        }), 400
    save()
    return dumps(output)
Beispiel #5
0
def us_prof():
    ''' Route to list a user profile'''
    return user_profile(request.args.get('token'), request.args.get('u_id'))
Beispiel #6
0
def userprofile():
    token = get_args('token')
    u_id = int(get_args('u_id'))

    return dumps(user_profile(token, u_id))