def test_setname_valid(user1): user1_profile = user_profile(user1['token'], user1['u_id'])['user'] new_name_first = 'Different' new_name_last = 'Name' user_profile_setname(user1['token'], new_name_first, new_name_last) new_user1_profile = user_profile(user1['token'], user1['u_id'])['user'] assert new_user1_profile['name_first'] == new_name_first assert new_user1_profile['name_last'] == new_name_last # 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['handle_str'] == new_user1_profile['handle_str']
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_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_setname_wsgi(): json = request.get_json() return jsonify( user_profile_setname(json['token'], json['name_first'], json['name_last']))
def test_setname_invalid_name(user1): with pytest.raises(InputError): user_profile_setname(user1['token'], '', 'name') with pytest.raises(InputError): user_profile_setname(user1['token'], 'name', '') with pytest.raises(InputError): user_profile_setname(user1['token'], 'name', 'n' * 51) with pytest.raises(InputError): user_profile_setname(user1['token'], 'n' * 51, 'name') with pytest.raises(InputError): user_profile_setname(user1['token'], 'n' * 51, 'n' * 51) with pytest.raises(InputError): user_profile_setname(user1['token'], '', '') # Checking that user1's names have not been altered #Assumption: functions that result in errors perform no actions user1_profile = user_profile(user1['token'], user1['u_id'])['user'] assert user1_profile['name_first'] == user1['name_first'] assert user1_profile['name_last'] == user1['name_last']
def test_setname_invalid_token(inv_token): with pytest.raises(AccessError): user_profile_setname(inv_token, "John", "Smith")
def test_setname_edge_cases(user1): user_profile_setname(user1['token'], 'n' * 50, 'name') user_profile_setname(user1['token'], 'name', 'n' * 50) user_profile_setname(user1['token'], 'n' * 50, 'l' * 50) user_profile_setname(user1['token'], 'name', 'n') user_profile_setname(user1['token'], 'n', 'name') user_profile_setname(user1['token'], 'n', 'n')