Example #1
0
def test_user_profile():
    #register an user for test purpose
    reset_all()
    data = auth_register('*****@*****.**', 'password', 'jiahao', 'zhang')
    u_id1 = data['u_id']
    token1 = data['token']
    data1 = auth_register('*****@*****.**', 'password', 'jiahao',
                          'zhang')
    u_id2 = data1['u_id']
    #sample invalid id and token
    invalid_u_id = -1

    assert user_profile(token1, u_id1) == {
        'u_id': u_id1,
        'email': '*****@*****.**',
        'name_first': 'jiahao',
        'name_last': 'zhang',
        'handle_str': 'jiahaozhang',
    }
    ## test to check another user
    assert user_profile(token1, u_id2) == {
        'u_id': u_id2,
        'email': '*****@*****.**',
        'name_first': 'jiahao',
        'name_last': 'zhang',
        'handle_str': 'jiahaozhang',
    }
    with pytest.raises(InputError):
        user_profile(token1, invalid_u_id)
Example #2
0
def test_user_profile_sethandle():
    reset_all()
    data1 = auth_register('*****@*****.**', 'password', 'jiahao',
                          'zhang')
    u_id1 = data1['u_id']
    token1 = data1['token']
    data2 = auth_register('*****@*****.**', 'password', 'jiahao',
                          'zhang')
    token2 = data2['token']
    assert user_profile_sethandle(token1, 'jiah') == {}
    assert user_profile(token1, u_id1) == {
        'u_id': u_id1,
        'email': '*****@*****.**',
        'name_first': 'jiahao',
        'name_last': 'zhang',
        'handle_str': 'jiah',
    }
    assert user_profile_sethandle(token2, 'alen') == {}
    #token changed after successful change handle_str
    #token1 = auth_login('*****@*****.**','123456')['token']
    #token2 = auth_login('*****@*****.**','123456')['token']

    with pytest.raises(InputError):
        user_profile_sethandle(token2, 'jiah')

    with pytest.raises(InputError):
        user_profile_sethandle(token1, 'alen')

    with pytest.raises(InputError):
        user_profile_sethandle(token1, 'a')

    with pytest.raises(InputError):
        user_profile_sethandle(token1, '123456789123456789123')
Example #3
0
def test_user_profile_setemail():
    reset_all()
    data1 = auth_register('*****@*****.**', 'password', 'jiahao',
                          'zhang')
    u_id1 = data1['u_id']
    token1 = data1['token']
    data2 = auth_register('*****@*****.**', 'password', 'jiahao',
                          'zhang')
    token2 = data2['token']
    assert user_profile_setemail(token1, '*****@*****.**') == {}
    #token changed after successful change email
    #check for new eamil login
    data3 = auth_login('*****@*****.**', 'password')
    token3 = data3['token']
    assert user_profile(token3, u_id1) == {
        'u_id': u_id1,
        'email': '*****@*****.**',
        'name_first': 'jiahao',
        'name_last': 'zhang',
        'handle_str': 'jiahaozhang',
    }

    ##token1 = auth_login('*****@*****.**','password')['token']

    with pytest.raises(InputError):
        user_profile_setemail(token3, '5')
    with pytest.raises(InputError):
        user_profile_setemail(token3, '*****@*****.**')
    with pytest.raises(InputError):
        user_profile_setemail(token2, '*****@*****.**')
Example #4
0
def test_user_profile_setname():
    reset_all()
    data = auth_register('*****@*****.**', 'password', 'jiahao', 'zhang')
    u_id1 = data['u_id']
    token1 = data['token']
    assert user_profile_setname(token1, 'alen', 'banana') == {}

    #show user profile after successful change
    assert user_profile(token1, u_id1) == {
        'u_id': u_id1,
        'email': '*****@*****.**',
        'name_first': 'alen',
        'name_last': 'banana',
        'handle_str': 'jiahaozhang',
    }
    #test for wrong input
    with pytest.raises(InputError):
        user_profile_setname(token1, 'i' * 60, 'banana')

    with pytest.raises(InputError):
        user_profile_setname(token1, 'alen', 'i' * 60)

    with pytest.raises(InputError):
        user_profile_setname(token1, 'alen', '')
    with pytest.raises(InputError):
        user_profile_setname(token1, '', 'banana')
Example #5
0
def view_profile():
    '''Returns information about a valid user.'''
    token = request.args.get("token")
    u_id = request.args.get("u_id")
    return dumps(user_profile(token, u_id))
Example #6
0
def user_profile():
    user_dict = user.user_profile(request.args.get('token'),
                                  int(request.args.get('u_id')))
    return dumps(user_dict)