Ejemplo n.º 1
0
def test_inherit_parent_roles():

    class RoleMixin(object):

        __roles__ = {
            'id_only': ['id', ]
        }

    class Parent(Mapper, RoleMixin):

        __type__ = TestType

        id = TestField()
        name = TestField()

        __roles__ = {
            'parent': ['name'],
            'overview': ['id', 'name']
        }

    class Child(Parent):

        __type__ = TestType

        __roles__ = {
            'overview': ['name', ]
        }

    mapper = Child(data={})
    assert mapper.roles == {
        '__default__': whitelist('id', 'name'),
        'overview': whitelist('name', ),
        'parent': whitelist('name', ),
        'id_only': whitelist('id', ),
    }
Ejemplo n.º 2
0
def test_inherit_parent_roles():
    class RoleMixin(object):

        __roles__ = {
            'id_only': [
                'id',
            ]
        }

    class Parent(Mapper, RoleMixin):

        __type__ = TestType

        id = TestField()
        name = TestField()

        __roles__ = {'parent': ['name'], 'overview': ['id', 'name']}

    class Child(Parent):

        __type__ = TestType

        __roles__ = {
            'overview': [
                'name',
            ]
        }

    mapper = Child(data={})
    assert mapper.roles == {
        '__default__': whitelist('id', 'name'),
        'overview': whitelist('name', ),
        'parent': whitelist('name', ),
        'id_only': whitelist('id', ),
    }
Ejemplo n.º 3
0
def test_union_whitelist_roles():

    role = whitelist('name', 'id') | whitelist('name', 'email')
    assert 'name' in role
    assert 'id' in role
    assert 'email' in role
    assert role.whitelist
Ejemplo n.º 4
0
    class MapperB(MapperA):

        __roles__ = {
            '__default__': whitelist('id', 'name'),
            'type': whitelist('object_type'),
        }

        __mapper_args__ = {
            'polymorphic_name': 'B',
        }
Ejemplo n.º 5
0
class EventMapper(SchedulableMapper):

    __type__ = TestType
    location = field.String()

    __mapper_args__ = {
        'polymorphic_name': 'event'
    }

    __roles__ = {
        'public': SchedulableMapper.__roles__['public']
        | whitelist('location'),
        'event_only_role': whitelist('id', 'location'),
        'event_blacklist': blacklist('location')
    }
Ejemplo n.º 6
0
class TaskMapper(SchedulableMapper):

    __type__ = TestType
    status = field.String()

    __mapper_args__ = {
        'polymorphic_name': 'task'
    }

    __roles__ = {
        'public': SchedulableMapper.__roles__['public']
        | whitelist('status'),
        'task_only_role': whitelist('id', 'status'),
        'task_blacklist': blacklist('status')
    }
Ejemplo n.º 7
0
    class MapperA(PolymorphicMapper):

        __type__ = TestType
        id = Integer()
        name = String()
        object_type = String()

        __roles__ = {
            '__default__': whitelist('id'),
            'overview': whitelist('id', 'name', 'object_type'),
        }

        __mapper_args__ = {
            'polymorphic_on': 'object_type',
        }
Ejemplo n.º 8
0
def test_union_blacklist_and_whitelist():

    role = blacklist('name', 'id') | whitelist('name', 'email')
    assert 'email' in role
    assert 'name' not in role
    assert 'id' not in role
    assert role.whitelist
Ejemplo n.º 9
0
class CompanyMapper(Mapper):
    __type__ = User

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

    __roles__ = {'public': whitelist('name', 'id')}
Ejemplo n.º 10
0
    class MapperBase(Mapper):

        __type__ = TestType

        id = TestField()
        name = TestField()

        __roles__ = {'__default__': whitelist('id', )}
Ejemplo n.º 11
0
    class UserMapper(Mapper):

        __type__ = dict

        id = String(required=True, read_only=True)
        name = String()

        __roles__ = {'private': whitelist('name')}
Ejemplo n.º 12
0
class UserMapper(Mapper):
    __type__ = User

    id = field.String(read_only=True)
    name = field.String()
    password = field.String()
    is_admin = field.Boolean(required=False, default=False)

    __roles__ = {'public': whitelist('name', 'id', 'is_admin')}
Ejemplo n.º 13
0
    class MapperBase(Mapper):

        __type__ = TestType

        id = Integer()
        name = String()
        user = Nested(UserMapper, role='private')

        __roles__ = {'private': whitelist('name', 'user')}
Ejemplo n.º 14
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')
    }
Ejemplo n.º 15
0
def test_polymorphic_mappers_role_inheritance():

    class MapperA(PolymorphicMapper):

        __type__ = TestType
        id = Integer()
        name = String()
        object_type = String()

        __roles__ = {
            '__default__': whitelist('id'),
            'overview': whitelist('id', 'name', 'object_type'),
        }

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

    class MapperB(MapperA):

        __roles__ = {
            '__default__': whitelist('id', 'name'),
            'type': whitelist('object_type'),
        }

        __mapper_args__ = {
            'polymorphic_name': 'B',
        }

    mapper = MapperA(data={})
    assert mapper.roles == {
        '__default__': whitelist('id'),
        'overview': whitelist('id', 'name', 'object_type')
    }

    mapperb = MapperB(data={})
    assert mapperb.roles == {
        '__default__': whitelist('id', 'name'),
        'overview': whitelist('id', 'name', 'object_type'),
        'type': whitelist('object_type'),
    }
Ejemplo n.º 16
0
def test_override_default_role():
    class MapperBase(Mapper):

        __type__ = TestType

        id = TestField()
        name = TestField()

        __roles__ = {'__default__': whitelist('id', )}

    mapper = MapperBase(data={})
    assert mapper.roles == {'__default__': whitelist('id', )}
Ejemplo n.º 17
0
def test_polymorphic_mappers_role_inheritance():
    class MapperA(PolymorphicMapper):

        __type__ = TestType
        id = Integer()
        name = String()
        object_type = String()

        __roles__ = {
            '__default__': whitelist('id'),
            'overview': whitelist('id', 'name', 'object_type'),
        }

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

    class MapperB(MapperA):

        __roles__ = {
            '__default__': whitelist('id', 'name'),
            'type': whitelist('object_type'),
        }

        __mapper_args__ = {
            'polymorphic_name': 'B',
        }

    mapper = MapperA(data={})
    assert mapper.roles == {
        '__default__': whitelist('id'),
        'overview': whitelist('id', 'name', 'object_type')
    }

    mapperb = MapperB(data={})
    assert mapperb.roles == {
        '__default__': whitelist('id', 'name'),
        'overview': whitelist('id', 'name', 'object_type'),
        'type': whitelist('object_type'),
    }
Ejemplo n.º 18
0
def test_override_default_role():

    class MapperBase(Mapper):

        __type__ = TestType

        id = TestField()
        name = TestField()

        __roles__ = {
            '__default__': whitelist('id', )
        }

    mapper = MapperBase(data={})
    assert mapper.roles == {'__default__': whitelist('id', )}
Ejemplo n.º 19
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'),
    }
Ejemplo n.º 20
0
def test_new_mapper_sets_roles():
    class MapperBase(Mapper):

        __type__ = TestType

        id = TestField()
        name = TestField()

    class MyMapper(MapperBase):

        email = TestField()

        __roles__ = {
            'overview': [
                'email',
            ]
        }

    class OtherMapper(MyMapper):

        __roles__ = {
            'private': [
                'id',
            ]
        }

    mapper = MapperBase(data={})
    assert mapper.roles == {'__default__': whitelist('id', 'name')}

    mapper = MyMapper(data={})
    assert mapper.roles == {
        'overview': whitelist('email', ),
        '__default__': whitelist('id', 'name', 'email')
    }

    mapper = OtherMapper(data={})
    assert mapper.roles == {
        '__default__': whitelist('id', 'name', 'email'),
        'overview': whitelist('email'),
        'private': whitelist('id', )
    }
Ejemplo n.º 21
0
def test_new_mapper_sets_roles():

    class MapperBase(Mapper):

        __type__ = TestType

        id = TestField()
        name = TestField()

    class MyMapper(MapperBase):

        email = TestField()

        __roles__ = {
            'overview': ['email', ]
        }

    class OtherMapper(MyMapper):

        __roles__ = {
            'private': ['id', ]
        }

    mapper = MapperBase(data={})
    assert mapper.roles == {'__default__': whitelist('id', 'name')}

    mapper = MyMapper(data={})
    assert mapper.roles == {
        'overview': whitelist('email', ),
        '__default__': whitelist('id', 'name', 'email')}

    mapper = OtherMapper(data={})
    assert mapper.roles == {
        '__default__': whitelist('id', 'name', 'email'),
        'overview': whitelist('email'),
        'private': whitelist('id', )
    }
Ejemplo n.º 22
0
def test_whitelist_membership():

    role = whitelist('name', 'id')
    assert 'name' in role
    assert 'id' in role
    assert 'email' not in role