예제 #1
0
class CharacterMapper(Mapper):

    __type__ = Character

    id = field.Integer(read_only=True)
    name = field.String()
    created_at = field.DateTime(read_only=True)
예제 #2
0
class MyMapper(Mapper):

    __type__ = MyObject

    id = field.Integer()
    name = field.String()

    __roles__ = {'name_only': ['name']}
예제 #3
0
class PlanetMapper(Mapper):

    __type__ = Planet

    id = field.Integer(read_only=True)
    name = field.String()
    description = field.String()
    created_at = field.DateTime(read_only=True)
예제 #4
0
def test_marshal_read_only_collection():

    f = field.Collection(field.Integer(), name='post_ids', read_only=True)
    output = {}
    data = {'post_ids': [2, 1]}
    mapper_session = get_mapper_session(data=data, output=output)
    f.marshal(mapper_session)
    assert output == {}
예제 #5
0
def test_serialize_flat_collection():

    f = field.Collection(field.Integer(), name='post_ids', source='posts')
    output = {}
    data = {'posts': [2, 1]}
    mapper_session = get_mapper_session(obj=data, output=output)
    f.serialize(mapper_session)
    assert output == {'post_ids': [2, 1]}
예제 #6
0
def test_marshal_collection_requires_list():

    f = field.Collection(field.Integer(), name='post_ids')
    output = {}

    mapper_session = get_mapper_session(data={'post_ids': 1}, output=output)
    with pytest.raises(field.FieldInvalid):
        f.marshal(mapper_session)
예제 #7
0
class UserMapper(Mapper):
    __type__ = User

    id = field.Integer(read_only=True)
    name = field.String()
    is_admin = field.Boolean(required=False, default=False)
    company = field.Nested(CompanyMapper, getter=company_getter)

    __roles__ = {
        'overview': whitelist('id', 'name')
    }
예제 #8
0
class SchedulableMapper(PolymorphicMapper):

    __type__ = TestType
    id = field.Integer(read_only=True)
    name = field.String()
    object_type = field.String(choices=['event', 'task'], read_only=True)

    __mapper_args__ = {
        'polymorphic_on': object_type,
        'allow_polymorphic_marshal': True,
    }

    __roles__ = {
        'name_only': ['name'],
        'public': whitelist('name', 'id'),
    }
예제 #9
0
def test_collection_proxies_name_to_wrapped_field():

    f = field.Collection(field.Integer(), name='post_ids')
    f2 = field.Collection(field.String(), name='test')

    with pytest.raises(field.FieldError):
        field.Collection(field.String(name='foo'))

    class UserMapper(Mapper):

        __type__ = TestType

        id = field.String(required=True)
        tags = field.Collection(field.String())

    assert f.name == 'post_ids'
    assert f2.name == 'test'

    mapper = UserMapper({})
    assert mapper.fields['tags'].name == 'tags'
예제 #10
0
파일: test_sqa.py 프로젝트: larsks/kim
    class UserMapper(Mapper):

        __type__ = User

        id = field.Integer(read_only=True)
        name = field.String()
예제 #11
0
파일: test_nested.py 프로젝트: larsks/kim
    class Outer(Mapper):
        __type__ = dict

        user = field.Nested(Inner, source='__self__', allow_create=True)
        status = field.Integer()
예제 #12
0
class BaseMapper(Mapper):

    id = field.Integer(read_only=True)
    created_at = field.DateTime()
    updated_at = field.DateTime()
예제 #13
0
class CompanyMapper(Mapper):
    __type__ = Company

    id = field.Integer(read_only=True)
    name = field.String()