def mkuser(openidstr, fullname, force_id): u = usermodel.User() u.fullname=fullname u.user_id = force_id i = usermodel.Identifier() i.identifierstring = openidstr i.identifiertype = 'openid' i.user_id = u.user_id u.identifiers=[i,] db_session.add(u) db_session.commit()
def test_putuser(): d = {"user_id": "org.cnx.user-75e06194-baee-4395-8e1a-566b656f6920", "email": "wibbleemail", "version": "1.0", "fullname": "wibblename"} u = usermodel.put_user(d, "org.cnx.user-75e06194-baee-4395-8e1a-566b656f6920") assert u.fullname == "wibblename" db_session.add(u); db_session.commit() u_fromdb = usermodel.get_user("org.cnx.user-75e06194-baee-4395-8e1a-566b656f6920") assert u_fromdb.fullname == "wibblename"
def test_putuser(): # d = {"interests": null, "identifiers": [{"identifierstring": "https://paulbrian.myopenid.com", "user_id": "org.cnx.user-75e06194-baee-4395-8e1a-566b656f6920", "identifiertype": "openid"}], "user_id": "org.cnx.user-75e06194-baee-4395-8e1a-566b656f6920", "suffix": null, "firstname": null, "title": null, "middlename": null, "lastname": null, "imageurl": null, "otherlangs": null, "affiliationinstitution_url": null, "email": null, "version": null, "location": null, "recommendations": null, "preferredlang": null, "fullname": "Paul Brian", "homepage": null, "affiliationinstitution": null, "biography": null} d = {"user_id": "org.cnx.user-75e06194-baee-4395-8e1a-566b656f6920", "email": "wibbleemail", "version": "1.0", "fullname": "wibblename"} u = usermodel.put_user(d, "org.cnx.user-75e06194-baee-4395-8e1a-566b656f6920") assert u.fullname == "wibblename" db_session.add(u); db_session.commit() u_fromdb = usermodel.get_user("org.cnx.user-75e06194-baee-4395-8e1a-566b656f6920") assert u_fromdb.fullname == "wibblename"
def post_user(jsond): """Given a dict representing the complete set of fields then create a new user and those fields I am getting a dictionary direct form Flask request object - want to handle that myself with parser. returns User object, for later saveing to DB""" u = User() #parser = verify_schema_version(None) #incomingd = parser(json_str) incomingd = json_dict u = populate_user(incomingd, u) db_session.add(u); db_session.commit() return u
return outl def put_user(jsond, user_id): """Given a user_id, and a json_str representing the "Updated" fields then update those fields for that user_id """ try: uobj =get_user(user_id) except Exception, e: dolog("INFO", str(e)) raise Rhaptos2Error("FAiled to get user") #.. todo:: parser = verify_schema_version(None) updated_obj = populate_user(jsond, uobj) db_session.add(updated_obj); db_session.commit() return updated_obj def populate_user(incomingd, userobj): """Given a dict, and a User object, push dict into User object and return it. .. todo:: validate and parse dict. """ ### put every key in json into User(), manually handling ### Identifier for k in incomingd: if k in ('user_id'): continue #.. todo:: test for user_id in a POST if k not in (u'identifier', u'identifiers'): ## a poor manual approach...