Ejemplo n.º 1
0
def test_union_blacklist_and_blacklist():

    role = blacklist('name', 'id') | blacklist('name', 'email')
    # use fields here to test for membership as it's a blacklist so membership
    # is negated
    assert 'name' in role.fields
    assert 'id' in role.fields
    assert 'email' in role.fields
    assert role.whitelist is False
Ejemplo n.º 2
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.º 3
0
class UserMapper(BaseMapper):

    __type__ = User

    name = field.String()
    email = field.String()

    __roles__ = {'__default__': role.blacklist('password')}
Ejemplo n.º 4
0
    class MapperBase(Mapper):

        __type__ = TestType

        id = Integer()
        name = String()

        __roles__ = {'private': blacklist('id')}
Ejemplo n.º 5
0
class UserMapper(BaseMapper):

    __type__ = User

    name = field.String()
    email = field.String()
    website = field.String()
    street_address = field.String()
    city = field.String()
    state = field.String()
    zip = field.String()
    phone = field.String()

    __roles__ = {'__default__': role.blacklist('password')}
Ejemplo n.º 6
0
def test_mapper_serialize_with_role_as_role():
    class MapperBase(Mapper):

        __type__ = TestType

        id = Integer()
        name = String()

    obj = TestType(id=2, name='bob')

    mapper = MapperBase(obj)
    result = mapper.serialize(role=blacklist('id'))

    assert result == {'name': 'bob'}
Ejemplo n.º 7
0
def test_mapper_serialize_with_role_as_role():

    class MapperBase(Mapper):

        __type__ = TestType

        id = Integer()
        name = String()

    obj = TestType(id=2, name='bob')

    mapper = MapperBase(obj)
    result = mapper.serialize(role=blacklist('id'))

    assert result == {'name': 'bob'}
Ejemplo n.º 8
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.º 9
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.º 10
0
def test_mapper_marshal_with_role_as_role():
    class MyType(TestType):
        def __init__(self, **params):
            self.id = 2
            super(MyType, self).__init__(**params)

    class MapperBase(Mapper):

        __type__ = MyType

        id = Integer()
        name = String()

    data = {'name': 'mike', 'id': 3}
    mapper = MapperBase(data=data)
    obj = mapper.marshal(role=blacklist('id'))

    assert obj.name == 'mike'
    assert obj.id == 2
Ejemplo n.º 11
0
def test_mapper_marshal_with_role_as_role():

    class MyType(TestType):

        def __init__(self, **params):
            self.id = 2
            super(MyType, self).__init__(**params)

    class MapperBase(Mapper):

        __type__ = MyType

        id = Integer()
        name = String()

    data = {'name': 'mike', 'id': 3}
    mapper = MapperBase(data=data)
    obj = mapper.marshal(role=blacklist('id'))

    assert obj.name == 'mike'
    assert obj.id == 2
Ejemplo n.º 12
0
def test_union_of_built_in_types_not_supported():

    with pytest.raises(RoleError):
        blacklist('name', 'id') | set('name')
Ejemplo n.º 13
0
def test_blacklist_membership():

    role = blacklist('name', 'id')
    res = 'name' in role
    assert res is False