def test_sethandle_invalid(user1): user1_profile_before = user_profile(user1['token'], user1['u_id'])['user'] with pytest.raises(InputError): user_profile_sethandle(user1['token'], 'a') with pytest.raises(InputError): user_profile_sethandle(user1['token'], 'a' * 21) # Checking that user1's handle has not been altered user1_profile_after = user_profile(user1['token'], user1['u_id'])['user'] assert user1_profile_after == user1_profile_before
def test_sethandle_valid(user1): user1_profile = user_profile(user1['token'], user1['u_id'])['user'] new_handle = 'newhandle' user_profile_sethandle(user1['token'], new_handle) new_user1_profile = user_profile(user1['token'], user1['u_id'])['user'] assert new_user1_profile['handle_str'] == new_handle # Check that no other field has been changed assert user1_profile['u_id'] == new_user1_profile['u_id'] assert user1_profile['email'] == new_user1_profile['email'] assert user1_profile['name_first'] == new_user1_profile['name_first'] assert user1_profile['name_last'] == new_user1_profile['name_last']
def test_set_same(user1): user1_profile = user_profile(user1['token'], user1['u_id'])['user'] user_profile_setname(user1['token'], user1['name_first'], user1['name_last']) user_profile_setemail(user1['token'], user1['email']) user_profile_sethandle(user1['token'], user1_profile['handle_str']) new_user1_profile = user_profile(user1['token'], user1['u_id'])['user'] assert new_user1_profile['email'] == user1_profile['email'] assert new_user1_profile['name_first'] == user1_profile['name_first'] assert new_user1_profile['name_last'] == user1_profile['name_last'] assert new_user1_profile['handle_str'] == user1_profile['handle_str']
def test_sethandle_taken(user1, user2): user1_profile = user_profile(user1['token'], user1['u_id'])['user'] user2_prof = user_profile(user2['token'], user2['u_id'])['user'] with pytest.raises(InputError): user_profile_sethandle(user1['token'], user2_prof['handle_str']) with pytest.raises(InputError): user_profile_sethandle(user2['token'], user1_profile['handle_str']) # Checking that user's handles have not been altered new_user1_profile = user_profile(user1['token'], user1['u_id'])['user'] new_user2_prof = user_profile(user2['token'], user2['u_id'])['user'] assert user1_profile['handle_str'] == new_user1_profile['handle_str'] assert user2_prof['handle_str'] == new_user2_prof['handle_str']
def test_set_return_type(user1): setname_return = user_profile_setname(user1['token'], 'new', 'name') setemail_return = user_profile_setemail(user1['token'], '*****@*****.**') sethandle_return = user_profile_sethandle(user1['token'], 'newhandle') assert isinstance(setname_return, dict) assert isinstance(setemail_return, dict) assert isinstance(sethandle_return, dict) assert len(setname_return) == 0 assert len(setemail_return) == 0 assert len(sethandle_return) == 0
def user_profile_sethandle_wsgi(): json = request.get_json() return jsonify(user_profile_sethandle(json['token'], json['handle_str']))
def test_sethandle_invalid_token(inv_token): with pytest.raises(AccessError): user_profile_sethandle(inv_token, 'newhandle')