def test_soobj(): p = Person(fname="Peter", mi="P", lname="Pasulke") pj = jsonify(p) assert pj == {'fname': "Peter", 'mi': "P", 'lname': "Pasulke", 'id': 1} b = B(foo="foo", bar="bar") bj = jsonify(b) assert bj == {'foo': "foo", 'bar': "bar", 'id': b.id, 'childName': None}
def test_customized_soobj(): ep = ExplicitPerson(fname="Peter") epj = jsonify(ep) assert epj == {'customized': True} c = C(foo="foo", baz="baz") cj = jsonify(c) assert cj == {'customized': True}
def test_jsonify_group(self): """Test that Group model objects are correctly jsonified.""" json = jsonify(self.test_group) assert json['group_name'] == u'test' assert json['display_name'] == u'Test Group' assert json['users'] == [u'test'] assert json['permissions'] == [u'test']
def test_descent_bases(): b = B(foo="foo", bar="bar") bj = jsonify(b) assert 'foo' in bj and 'bar' in bj no_descent_encoder = GenericJSON(descent_bases=False) bj = no_descent_encoder.encode(b) assert 'foo' not in bj and 'bar' in bj
def test_jsonify_user(self): """Test that User model objects are correctly jsonified.""" json = jsonify(self.test_user) assert json['user_name'] == u'test' assert json['display_name'] == u'Test User' assert json['email_address'] == u'*****@*****.**' assert 'password' not in json assert '_password' not in json assert json['groups'] == [u'test'] assert json['permissions'] == [u'test']
def GetUserPersona( db, user_id, personaId): persona = db.personas.selectfirst( db.personas.c.persona_id == persona_id, db.personas.c.user_id == user_id) return jsonify(persona)
def GetPersonaService( db, id): persona_services = db.persona_services.select( db.persona_services.c.persona_service_id == id) if persona_services: return jsonify(persona_services[0]) else: return None
def GetPersonaProperty( db, persona_id, name): pp = db.persona_properties.selectfirst( and_( db.persona_properties.c.persona_id == persona_id, db.persona_properties.c.name == name)) return jsonify(pp)
def GetUserPersonas( db, user_id): personas = db.personas.select( db.personas.c.user_id == user_id, order_by=db.personas.c.sequence) return [ jsonify(persona) for persona in personas ]
def GetPersonaServices( db): persona_services = db.persona_services.select( db.persona_services.c.enabled != 0, order_by=db.persona_services.c.sequence) persona_services = [ jsonify(ps) for ps in persona_services ] return persona_services
def GetPersonaProperties( db, persona_id): pps = db.persona_properties.select( db.persona_properties.c.persona_id == persona_id) pps = [ jsonify(pp) for pp in pps ] return pps
def GetPersonaServicePath( db, persona_service_id, pathName): path = db.persona_service_paths.selectfirst( and_( db.persona_service_paths.c.persona_service_id == persona_service_id, db.persona_service_paths.c.name == pathName)) if not path: return None return jsonify(path)
def GetPersonaServicePaths( db, persona_service_id): psps = db.persona_service_paths.select( db.persona_service_paths.c.persona_service_id == persona_service_id, order_by=db.persona_service_paths.c.sequence) psps = [ jsonify(psp) for psp in psps ] return psps
def jsonify_salist(obj): '''Transform SQLAlchemy InstrumentedLists into json. The one special thing is that we bind the special json_props into each descendent. This allows us to specify a json_props on the toplevel query result and it will pass to all of its children. :arg obj: One of the sqlalchemy list types to jsonify :Returns: list of jsonified elements ''' if 'json_props' in obj.__dict__: for element in obj: element.json_props = obj.json_props return [jsonify(element) for element in obj]
def GetUser( db, userName, password): # pw = md5.new(password).hexdigest() pw = password user = db.users.selectfirst( and_( db.users.c.login_name == userName, db.users.c.password == pw)) return jsonify(user)
def test_so_select_result(): p = Person(fname="Willy", mi="P", lname="Millowitsch") sr = Person.select(Person.q.fname == "Willy") srj = jsonify(sr) assert srj == [p]
def test_jsonify_permission(self): """Test that Permission model objects are correctly jsonified.""" json = jsonify(self.test_perm) assert json['permission_name'] == u'test' assert json['description'] == u'Test Permission' assert json['groups'] == [u'test']