def test_user_success():
    reset_data()
    A = auth_register("*****@*****.**", 'HoyaLee2019', "Hoya", "Lee")
    token = A['token']
    u_id = A['u_id']

    UF.user_profile(token, u_id)
def test_user_NotLogin():
    token = A['token']
    auth_logout(token)
    u_id = A['u_id']

    with pytest.raises(UF.AccessError):
        UF.user_profile(token, u_id)
def test_user_Invalid():
    reset_data()
    A = auth_register("*****@*****.**", 'HoyaLee2019', "Hoya", "Lee")
    token = A['token']
    u_id = A['u_id'] + 10010

    with pytest.raises(UF.AccessError):
        UF.user_profile(token, u_id)
def test_user_invalidID():
    reset_data()
    A = auth_register("*****@*****.**", 'HoyaLee2019', "Hoya", "Lee")
    u_id = None
    token = A['token']

    with pytest.raises(TypeError):
        UF.user_profile(token, u_id)
Example #5
0
def user_profile():
    '''
    returns info about their email, first name, last name, handle
    '''
    token = request.args.get("token")
    u_id = to_int(request.args.get("u_id"))

    return dumps(user.user_profile(token, u_id))
def test_profile_sethandle():
    '''
    Update the user's handle
    '''

    # Initialisation
    global_var.initialise_all()

    # Creating a user
    user = auth_functions.auth_register("*****@*****.**", "pass123", \
         "Rayden", "Smith")
    token = user["token"]
    u_id = user["u_id"]

    # A valid handle is given
    assert funcs.user_profile_sethandle(token, "a handle") == {}

    # Updating the handle of the user
    funcs.user_profile_sethandle(token, "new handle")

    # Checking if the user's handle has been updated successfully
    assert funcs.user_profile(token, u_id) == {
        "u_id":
        u_id,
        "email":
        "*****@*****.**",
        "name_first":
        "Rayden",
        "name_last":
        "Smith",
        "handle_str":
        "new handle",
        "profile_img_url":
        'http://*****:*****@gmail.com", "pass123", \
            "Rayden", "Smith")
        funcs.user_profile_sethandle(user1["token"], "new handle")
def test_profile_setname():
    '''
    Update the authorised user's first and last name
    '''

    # Initialisation
    global_var.initialise_all()

    # Creating user
    user = auth_functions.auth_register("*****@*****.**", "pass123", \
        "Rayden", "Smith")
    token = user["token"]
    u_id = user["u_id"]

    # A valid first and last name is given
    assert funcs.user_profile_setname(token, "Rayden", "Smith") == {}

    # Updating the first and last name of user
    funcs.user_profile_setname(token, "Hello", "World")

    # Checking if first and last name have been updated successfully
    assert funcs.user_profile(token, u_id) == {
        "u_id":
        u_id,
        "email":
        '*****@*****.**',
        "name_first":
        'Hello',
        "name_last":
        'World',
        "handle_str":
        'raydensmith',
        "profile_img_url":
        'http://localhost:5001/imgurl/server/assets/images/default.jpg'
    }

    # A name of 50 length is valid
    assert funcs.user_profile_setname(token, "a" * STRING_LENGTH, \
        "a" * STRING_LENGTH) == {}

    # First name too long
    with pytest.raises(ValueError, match="Name too long"):
        funcs.user_profile_setname(token, "a" * STRING_LENGTH + "a", "Smith")

    # Lasts name too long
    with pytest.raises(ValueError, match="Name too long"):
        funcs.user_profile_setname(token, "Raydon", "a" * STRING_LENGTH + "a")

    # An exception occurs when token is invalid
    with pytest.raises(AccessError, match="Invalid token"):
        funcs.user_profile_setname("invalid_token", "Raydon", "Smith")
def test_user_profile():
    '''
    Returns information about their email, first name, last name, and handle
    '''

    # Initialisation
    global_var.initialise_all()

    # Creating a user
    user = auth_functions.auth_register("*****@*****.**", "pass123", \
         "Raydon", "Smith")
    token = user["token"]
    u_id = user["u_id"]

    # A valid user_id is provided, user details are returned
    assert funcs.user_profile(token, u_id) == {
        "u_id":
        u_id,
        "email":
        '*****@*****.**',
        "name_first":
        'Raydon',
        "name_last":
        'Smith',
        "handle_str":
        'raydonsmith',
        "profile_img_url":
        'http://localhost:5001/imgurl/server/assets/images/default.jpg'
    }

    # An exception occurs when the user_id is invalid
    with pytest.raises(ValueError, match="Invalid User ID"):
        funcs.user_profile(token, -1)

    # An exception occurs when token is invalid
    with pytest.raises(AccessError, match="Invalid token"):
        funcs.user_profile("invalid_token", u_id)
def test_profile_setemail():
    '''
    Update the user's email
    '''

    # Initialisation
    global_var.initialise_all()

    # Creating user
    user = auth_functions.auth_register("*****@*****.**", "pass123",\
        "Rayden", "Smith")
    token = user["token"]
    u_id = user["u_id"]

    # An email already in use is given
    with pytest.raises(ValueError, match="Email already in use"):
        funcs.user_profile_setemail(token, "*****@*****.**")

    # A valid email change
    assert funcs.user_profile_setemail(token, "*****@*****.**") == {}

    # Checking if the user's email has been updated successfully
    assert funcs.user_profile(token, u_id) == {
        "u_id":
        u_id,
        "email":
        '*****@*****.**',
        "name_first":
        'Rayden',
        "name_last":
        'Smith',
        "handle_str":
        'raydensmith',
        "profile_img_url":
        'http://*****:*****@gmail.com")
def test_user_invalidToken():
    u_id = A['u_id']
    token = None

    with pytest.raises(TypeError):
        UF.user_profile(token, u_id)