def test_nested_schema_with_register_codec(client):
    nested_schema = schema.AvroSchema(data_gen.NESTED_SCHENA)
    order_schema = schema.AvroSchema(data_gen.ORDER_SCHENA)

    customer_serializer = serializer.FaustSerializer(client,
                                                     "test-nested-schema",
                                                     nested_schema)
    order_serializer = serializer.FaustSerializer(client, "test-order-schema",
                                                  order_schema)

    faust.serializers.codecs.register("customer_serializer",
                                      customer_serializer)
    faust.serializers.codecs.register("order_serializer", order_serializer)

    class Order(faust.Record, serializer="order_serializer"):
        uid: int

    class Customer(faust.Record, serializer="customer_serializer"):
        name: str
        uid: int
        order: Order

    payload = data_gen.create_nested_schema()

    customer = Customer(**payload)

    message_encoded = customer.dumps()

    assert message_encoded
    assert len(message_encoded) > 5
    assert isinstance(message_encoded, bytes)

    message_decoded = Customer.loads(message_encoded)
    assert message_decoded == customer
Example #2
0
def test_nested_schema(client):
    nested_schema = schema.AvroSchema(data_gen.NESTED_SCHENA)
    faust_serializer = serializer.FaustSerializer(client, "test-nested-schema", nested_schema)

    record = data_gen.create_nested_schema()
    message_encoded = faust_serializer._dumps(record)

    assert message_encoded
    assert len(message_encoded) > 5
    assert isinstance(message_encoded, bytes)

    message_decoded = faust_serializer._loads(message_encoded)
    assert message_decoded == record