def test_user_profile_setname(): #user_profile_setname(token, firstname, lastname), no return value #SETUP TESTS BEGIN #create token: authRegDict = auth_register("*****@*****.**", "password", "Ben", "Kah") userId = authRegDict["u_id"] token = authRegDict["token"] #SETUP TESTS END user_profile_setname(token, "Jeffrey", "Oh") #this function should pass userDict = user_profile(token, userId) assert userDict["name_first"] == "Jeffrey" #test that name has been changed assert userDict["name_last"] == "Oh" with pytest.raises(ValueError): #following should raise exceptions user_profile_setname( token, "This is a really long first name, more than 50 characters", "lmao") with pytest.raises(ValueError): user_profile_setname( token, "lmao", "This is a really long last name, more than 50 characters") with pytest.raises(ValueError): user_profile_setname( token, "This is a really long first name, more than 50 characters", "This is a really long last name, more than 50 characters")
def test_user_profile(): # set up # user1(admin) registerDict1 = auth_register("*****@*****.**", "password", "kenny", "han") userID1 = registerDict1['u_id'] token1 = registerDict1['token'] # user2 registerDict2 = auth_register("*****@*****.**", "password2", "ken", "han") userID2 = registerDict2['u_id'] token2 = registerDict2['token'] # end of set up # testing # raises ValueError when user with u_id is not a valid user with pytest.raises(ValueError): userProfile = user_profile(token1, userID2) with pytest.raises(ValueError): userProfile = user_profile(token2, userID1)
def test_user_profile_sethandle(): #user_profile_sethandle(token, handle_str), no return value #SETUP TESTS BEGIN #create token: authRegDict = auth_register("*****@*****.**", "password", "Ben", "Kah") userId = authRegDict["u_id"] token = authRegDict["token"] #SETUP TESTS END user_profile_sethandle(token, "good handle") userDict = user_profile(token, userId) assert userDict["handle_str"] == "good handle" with pytest.raises(ValueError): user_profile_sethandle(token, "This handle is way too long")
def test_user_profile_email(): #user_profile_setemail(token, email), no return value #SETUP TESTS BEGIN #create token: authRegDict = auth_register("*****@*****.**", "password", "Ben", "Kah") userId = authRegDict["u_id"] token = authRegDict["token"] #create second person's email: authRegDict2 = auth_register("*****@*****.**", "password", "Jeffrey", "Oh") userDict2 = user_profile(authRegDict2["token"], authRegDict2["u_id"]) email2 = userDict2["email"] #SETUP TESTS END user_profile_email( token, "*****@*****.**") #this function should pass userDict = user_profile(token, userId) assert userDict[ "email"] == "*****@*****.**" #test that email has been changed with pytest.raises(ValueError): #following should raise exceptions user_profile_email(token, "bad email") with pytest.raises(ValueError): user_profile_email(token, email2) #using another user's email
def route_user_profile(): global data token = request.args.get("token") user_id = int(request.args.get("u_id")) user = user_profile(token, user_id) return dumps(user)
import profile import cars from parse_dict import * profile = profile.user_profile('ana', 'dana', varsta='19', scoala='CNAV') car = cars.make_car('tesla', 'model s', parse(profile))