Пример #1
0
def test_it_jsonify_data__that_is_valid_params():
    from alchemyjsonschema.dictify import jsonify
    from jsonschema import validate

    target = _makeOne()
    schema = target(User, excludes=["pk", "group_id"])

    user = User(name="foo", group=Group(name="ravenclaw", color="blue", pk=1))
    jsondict = jsonify(user, schema)
    validate(jsondict, schema)
Пример #2
0
def jsonify2(obj, name):
    # TODO replace this with a cached definitions patch
    # this is inefficient to do each time...
    schemas = get_schemas()
    spec = copy.copy(schemas[name])
    spec['definitions'] = schemas
    for attr in obj.__dict__:
        if isinstance(getattr(obj, attr), Amount):
            setattr(obj, attr, getattr(obj, attr).to_double())
    return json.dumps(jsonify(obj, spec))
def test_User():
    user = lmodels.User(**USER)
    ses.add(user)
    ses.commit()
    user_schema = factory.__call__(lmodels.User)
    #print user_schema
    #print json.dumps(user_schema, indent=4)
    udict = jsonify(user, user_schema)
    assert validate(udict, user_schema) is None

    USER_KEY['user_id'] = user.id
    ukey = lmodels.UserKey(**USER_KEY)
    ses.add(ukey)
    ses.commit()
    ukey_schema = factory.__call__(lmodels.UserKey)
    ukey_dict = jsonify(ukey, ukey_schema)
    #print ukey_schema
    del ukey_dict['user']
    #print json.dumps(ukey_schema, indent=4)
    assert validate(ukey_dict, ukey_schema) is None
Пример #4
0
def _callFUT4(*args, **kwargs):
    from alchemyjsonschema.dictify import jsonify
    kwargs["verbose"] = True
    return jsonify(*args, **kwargs)
Пример #5
0
def jsonify2(obj, name):
    # TODO replace this with a cached definitions patch
    # this is inefficient to do each time...
    spec = copy.copy(SWAGGER_SPEC["definitions"][name])
    spec["definitions"] = SWAGGER_SPEC["definitions"]
    return jsonify(obj, spec)
def _callFUT(*args, **kwargs):
    # see: https://github.com/podhmo/alchemyjsonschema/pull/3
    from alchemyjsonschema.dictify import jsonify
    return jsonify(*args, **kwargs)