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
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
class UserMapper(BaseMapper): __type__ = User name = field.String() email = field.String() __roles__ = {'__default__': role.blacklist('password')}
class MapperBase(Mapper): __type__ = TestType id = Integer() name = String() __roles__ = {'private': blacklist('id')}
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')}
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'}
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') }
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') }
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
def test_union_of_built_in_types_not_supported(): with pytest.raises(RoleError): blacklist('name', 'id') | set('name')
def test_blacklist_membership(): role = blacklist('name', 'id') res = 'name' in role assert res is False