def test_invalid_polyfield():
    Sticker = namedtuple('Sticker', ['shape', 'image'])
    with pytest.raises(TypeError):
        field = PolyField(
            serialization_schema_selector=shape_schema_serialization_disambiguation,
            deserialization_schema_selector=shape_schema_deserialization_disambiguation
        )
        field.serialize('shape', Sticker(3, 3))
Exemplo n.º 2
0
def test_invalid_polyfield():
    Sticker = namedtuple('Sticker', ['shape', 'image'])
    with pytest.raises(TypeError):
        field = PolyField(serialization_schema_selector=
                          shape_schema_serialization_disambiguation,
                          deserialization_schema_selector=
                          shape_schema_deserialization_disambiguation)
        field.serialize('shape', Sticker(3, 3))
Exemplo n.º 3
0
def test_serializing_polyfield_None():
    Sticker = namedtuple('Sticker', ['shape', 'image'])
    marshmallow_sticker = Sticker(None, "marshmallow.png")
    field = PolyField(
        serialization_schema_selector=shape_schema_serialization_disambiguation,
        deserialization_schema_selector=
        shape_schema_deserialization_disambiguation)
    rect_dict = field.serialize('shape', marshmallow_sticker)

    assert rect_dict is None
def test_serializing_polyfield_None():
    Sticker = namedtuple('Sticker', ['shape', 'image'])
    marshmallow_sticker = Sticker(None, "marshmallow.png")
    field = PolyField(
        serialization_schema_selector=shape_schema_serialization_disambiguation,
        deserialization_schema_selector=shape_schema_deserialization_disambiguation
    )
    rect_dict = field.serialize('shape', marshmallow_sticker)

    assert rect_dict is None
Exemplo n.º 5
0
def test_serializing_polyfield_by_parent_type():
    rect = Rectangle("blue", 4, 10)
    Sticker = namedtuple('Sticker', ['shape', 'image', 'type'])
    marshmallow_sticker = Sticker(rect, "marshmallow.png", 'rectangle')
    field = PolyField(serialization_schema_selector=
                      shape_property_schema_serialization_disambiguation,
                      deserialization_schema_selector=
                      shape_property_schema_deserialization_disambiguation)
    rect_dict = field.serialize('shape', marshmallow_sticker)

    assert rect_dict == {"length": 4, "width": 10, "color": "blue"}
def test_serializing_polyfield_rectangle():
    rect = Rectangle("blue", 4, 10)
    Sticker = namedtuple('Sticker', ['shape', 'image'])
    marshmallow_sticker = Sticker(rect, "marshmallow.png")
    field = PolyField(
        serialization_schema_selector=shape_schema_serialization_disambiguation,
        deserialization_schema_selector=shape_schema_deserialization_disambiguation
    )
    rect_dict = field.serialize('shape', marshmallow_sticker)

    assert rect_dict == {"length": 4, "width": 10, "color": "blue"}
def test_serializing_polyfield_many():
    rect = Rectangle("blue", 4, 10)
    tri = Triangle("red", 1, 100)
    StickerCollection = namedtuple('StickerCollection', ['shapes', 'image'])
    marshmallow_sticker_collection = StickerCollection([rect, tri], "marshmallow.png")
    field = PolyField(
        serialization_schema_selector=shape_schema_serialization_disambiguation,
        deserialization_schema_selector=shape_schema_deserialization_disambiguation,
        many=True
    )
    shapes = field.serialize('shapes', marshmallow_sticker_collection)
    expected_shapes = [
        {"length": 4, "width": 10, "color": "blue"},
        {"base": 1, "height": 100, "color": "red"}
    ]
    assert shapes == expected_shapes
Exemplo n.º 8
0
def test_serializing_polyfield_many():
    rect = Rectangle("blue", 4, 10)
    tri = Triangle("red", 1, 100)
    StickerCollection = namedtuple('StickerCollection', ['shapes', 'image'])
    marshmallow_sticker_collection = StickerCollection([rect, tri],
                                                       "marshmallow.png")
    field = PolyField(
        serialization_schema_selector=shape_schema_serialization_disambiguation,
        deserialization_schema_selector=
        shape_schema_deserialization_disambiguation,
        many=True)
    shapes = field.serialize('shapes', marshmallow_sticker_collection)
    expected_shapes = [{
        "length": 4,
        "width": 10,
        "color": "blue"
    }, {
        "base": 1,
        "height": 100,
        "color": "red"
    }]
    assert shapes == expected_shapes