Ejemplo n.º 1
0
def test_serialize_polymorphic_child_mapper_deferred_role_disallowed_fields():

    obj = TestType(id=2, name='bob', object_type='event', location='London')
    obj2 = TestType(id=3, name='bob', object_type='task', status='failed')

    mapper = SchedulableMapper(obj=obj)
    data = mapper.serialize(role='name_only',
                            deferred_role=whitelist('id', 'name'))

    assert data == {'name': 'bob'}
Ejemplo n.º 2
0
def test_serialize_polymorphic_child_mapper_deferred_role_fields_across_types(
):

    obj = TestType(id=2, name='bob', object_type='event', location='London')
    obj2 = TestType(id=3, name='bob', object_type='task', status='failed')

    mapper = SchedulableMapper(obj=obj)
    data = mapper.serialize(role='public',
                            deferred_role=whitelist('id', 'status',
                                                    'location'))

    assert data == {'id': 2, 'location': 'London'}

    mapper = SchedulableMapper(obj=obj2)
    data = mapper.serialize(role='public',
                            deferred_role=whitelist('id', 'status',
                                                    'location'))

    assert data == {'id': 3, 'status': 'failed'}
Ejemplo n.º 3
0
def test_serialize_polymorphic_child_mapper_existing_blacklist_with_deferred():

    obj = TestType(id=2, name='bob', object_type='event', location='London')

    mapper = SchedulableMapper(obj=obj)
    data = mapper.serialize(role='event_blacklist',
                            deferred_role=whitelist('id'))

    assert data == {
        'id': 2,
    }
Ejemplo n.º 4
0
def test_serialize_polymorphic_child_mapper_with_deferred_role():

    obj = TestType(id=2, name='bob', object_type='event', location='London')

    mapper = EventMapper(obj=obj)
    data = mapper.serialize(role='event_only_role',
                            deferred_role=whitelist('id'))

    assert data == {
        'id': 2,
    }
Ejemplo n.º 5
0
def test_serialize_polymorphic_child_mapper_with_deferred_role():


    obj = TestType(id=2, name='bob', object_type='event', location='London')

    mapper = EventMapper(obj=obj)
    data = mapper.serialize(role='event_only_role', deferred_role=whitelist('id'))

    assert data == {
        'id': 2,
    }
Ejemplo n.º 6
0
def test_serialize_polymorphic_child_mapper_existing_blacklist_with_deferred():


    obj = TestType(id=2, name='bob', object_type='event', location='London')

    mapper = SchedulableMapper(obj=obj)
    data = mapper.serialize(
        role='event_blacklist', deferred_role=whitelist('id'))

    assert data == {
        'id': 2,
    }
Ejemplo n.º 7
0
def test_serialize_polymorphic_child_mapper_deferred_role_disallowed_fields():


    obj = TestType(id=2, name='bob', object_type='event', location='London')
    obj2 = TestType(id=3, name='bob', object_type='task', status='failed')

    mapper = SchedulableMapper(obj=obj)
    data = mapper.serialize(
        role='name_only', deferred_role=whitelist('id', 'name'))

    assert data == {
        'name': 'bob'
    }
Ejemplo n.º 8
0
def test_serialize_polymorphic_mapper_many_with_deferred_role():

    obj1 = TestType(id=2, name='bob', location='London', object_type='event')
    obj2 = TestType(id=3, name='fred', status='Done', object_type='task')

    result = SchedulableMapper.many().serialize([obj1, obj2],
                                                role='public',
                                                deferred_role=whitelist('id'))

    assert result == [{
        'id': 2,
    }, {
        'id': 3,
    }]
Ejemplo n.º 9
0
def test_serialize_polymorphic_child_mapper_deferred_role_fields_across_types():


    obj = TestType(id=2, name='bob', object_type='event', location='London')
    obj2 = TestType(id=3, name='bob', object_type='task', status='failed')

    mapper = SchedulableMapper(obj=obj)
    data = mapper.serialize(
        role='public', deferred_role=whitelist('id', 'status', 'location'))

    assert data == {
        'id': 2,
        'location': 'London'
    }

    mapper = SchedulableMapper(obj=obj2)
    data = mapper.serialize(
        role='public', deferred_role=whitelist('id', 'status', 'location'))

    assert data == {
        'id': 3,
        'status': 'failed'
    }
Ejemplo n.º 10
0
def test_serialize_polymorphic_mapper_many_with_deferred_role():

    obj1 = TestType(id=2, name='bob', location='London', object_type='event')
    obj2 = TestType(id=3, name='fred', status='Done', object_type='task')

    result = SchedulableMapper.many().serialize(
        [obj1, obj2], role='public', deferred_role=whitelist('id'))

    assert result == [
        {
            'id': 2,
        },
        {
            'id': 3,
        }
    ]