Example #1
0
def test_invalid_id():
    global my_users
    data_delete()
    auth_register("*****@*****.**","password","Student","Citizen")
    user = auth_login("*****@*****.**",'password')
    
    # Testing user_profile
    with pytest.raises(ValueError):
        user_profile(user['token'], '546')
Example #2
0
def test_correct_profile():
    global my_users
    data_delete()
    auth_register("*****@*****.**","password","Student","Citizen")
    userDict = auth_login("*****@*****.**",'password')
    # Testing user_profile
    profile = user_profile(userDict['token'], userDict['u_id'])
    
    assert(profile['email'] == '*****@*****.**')
    assert(profile['name_first'] == 'Student')
    assert(profile['name_last'] == 'Citizen')
    assert(profile['handle_str'] == 'studentcitizen')
Example #3
0
def test_correct_sethandle():
    global my_users
    data_delete()
    auth_register("*****@*****.**","password","Student","Citizen")
    user = auth_login("*****@*****.**",'password')
    
    # Changing user's handle
    user_profile_sethandle(user['token'],"Apple")
    
    # Checking handle
    profile = user_profile(user['token'], user['u_id'])
    assert(profile['handle_str'] == "Apple")
Example #4
0
def test_no_inputs_handle():
    global my_users
    data_delete()
    auth_register("*****@*****.**","password","Student","Citizen")
    user = auth_login("*****@*****.**",'password')
    
    # Changing user's handle
    with pytest.raises(AccessError):
        user_profile_sethandle("","")
    
    # Checking handle
    profile = user_profile(user['token'], user['u_id'])
    assert(profile['handle_str'] == "studentcitizen")
Example #5
0
def test_handle_too_long():
    global my_users
    data_delete()
    auth_register("*****@*****.**","password","Student","Citizen")
    user = auth_login("*****@*****.**",'password')
    
    # Changing user's handle
    with pytest.raises(ValueError):
        user_profile_sethandle(user['token'],"abcdefghijklmnopqrstuvwxyz")
    
    # Checking handle
    profile = user_profile(user['token'], user['u_id'])
    assert(profile['handle_str'] == "studentcitizen")
Example #6
0
def test_correct_email():
    global my_users
    data_delete()
    auth_register("*****@*****.**","password","Student","Citizen")
    user = auth_login("*****@*****.**",'password')
    
    
    # Changing user's email
    user_profile_setemail(user['token'],'*****@*****.**')
    
    # Testing user_profile
    profile = user_profile(user['token'], user['u_id'])
    assert(profile['email'] == '*****@*****.**')
Example #7
0
def test_correct_name():
    global my_users
    data_delete()
    auth_register("*****@*****.**","password","Student","Citizen")
    user = auth_login("*****@*****.**",'password')
    
    # Changing user's email
    user_profile_setname(user['token'],'Citizen','Student')
    
    # Testing user_profile
    profile = user_profile(user['token'], user['u_id'])
    assert(profile['name_first'] == 'Citizen')
    assert(profile['name_last'] == 'Student')
Example #8
0
def test_email_no_inputs():
    global my_users
    data_delete()
    auth_register("*****@*****.**","password","Student","Citizen")
    user = auth_login("*****@*****.**",'password')
    
    
     # Changing user's email
    with pytest.raises(AccessError):
        user_profile_setemail("","")
    
    # Checking email
    profile = user_profile(user['token'], user['u_id'])
    assert(profile['email'] == '*****@*****.**')
Example #9
0
def test_20_users():
    global my_users
    data_delete()
    for i in range(0,19):
        string = "st" + str(i) + "@unsw.edu.au"
        user = auth_register(string,"password","Studentabcde","Citizen")
        userDict = user_profile(user['token'], user['u_id']);
        handle = "studentabcdecitize"
        if i == 0:
            handle += "n"
        elif i >= 1 and i < 10:
            handle += "n" + str(i)
        else:
            handle += str(i)
        assert handle == userDict['handle_str']
Example #10
0
def test_name_no_inputs():
    global my_users
    data_delete()
    auth_register("*****@*****.**","password","Student","Citizen")
    user = auth_login("*****@*****.**",'password')
    
    
    # Changing user's name
    with pytest.raises(AccessError):
        user_profile_setname("","","")
    
    # Checking name
    profile = user_profile(user['token'], user['u_id'])
    assert(profile['name_last'] == 'Citizen')
    assert(profile['name_first'] == 'Student')
Example #11
0
def test_invalid_last_name():
    global my_users
    data_delete()
    auth_register("*****@*****.**","password","Student","Citizen")
    user = auth_login("*****@*****.**",'password')
    
    last_name = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
    
    # Changing user's name
    with pytest.raises(ValueError):
        user_profile_setname(user['token'],'Student',last_name)
    
    # Checking email
    profile = user_profile(user['token'], user['u_id'])
    assert(profile['name_last'] == 'Citizen')
    assert(profile['name_first'] == 'Student')
Example #12
0
def test_email_used():
    global my_users
    data_delete()
    auth_register("*****@*****.**","password","Student","Citizen")
    user = auth_login("*****@*****.**",'password')
    
    
    # Creating user 2
    user2 = auth_register("*****@*****.**", "Lilyisthebest555", "John", "Smith")
    token2 = user2['token']
    
    # Changing user's email
    with pytest.raises(ValueError):
        user_profile_setemail(user['token'],"*****@*****.**")
    
    # Checking email
    profile = user_profile(user['token'], user['u_id'])
    assert(profile['email'] == '*****@*****.**')
Example #13
0
def user_profile_show():
    token = request.args.get('token')
    u_id = request.args.get('u_id')
    try:
        returnDict = user_profile(token, int(u_id))
        if returnDict is not None:
            return sendSuccess({
                'u_id' : returnDict['u_id'],
                'email' : returnDict['email'],
                'name_first' : returnDict['name_first'],
                'name_last' : returnDict['name_last'],
                'handle_str' : returnDict['handle_str'],
                'profile_img_url' : returnDict['profile_img_url']
            })
    except ValueError as e:
        return sendError(400, "ValueError", e.args)
    except AccessError as a:
        return sendError(401, "AccessError", a.args)
Example #14
0
def test_no_inputs_profile():
    
    # Testing user_profile
    with pytest.raises(AccessError):
        user_profile("", "")