Пример #1
0
 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}
Пример #2
0
 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}
Пример #3
0
 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']
Пример #4
0
 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
Пример #5
0
 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']
Пример #6
0
 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']
Пример #7
0
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)
Пример #8
0
 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']
Пример #9
0
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
Пример #10
0
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)
Пример #11
0
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
    ]
Пример #12
0
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
Пример #13
0
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
Пример #14
0
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)
Пример #15
0
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
Пример #16
0
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]
Пример #17
0
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)
Пример #18
0
 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]
Пример #19
0
 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']
Пример #20
0
 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']