Skip to content

Commit

Permalink
Add test with record refs (#1932)
Browse files Browse the repository at this point in the history
  • Loading branch information
rayokota authored Mar 7, 2025
1 parent 8b9afc0 commit 3f40f19
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/schema_registry/test_avro_serdes.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,45 @@ def test_avro_serialize_union():
assert obj == obj2


def test_avro_serialize_union_with_record_references():
conf = {'url': _BASE_URL}
client = SchemaRegistryClient.new_client(conf)
ser_conf = {'auto.register.schemas': False, 'use.latest.version': True}

obj = {
'First': {'stringField': 'hi'},
'Second': {'stringField': 'hi'},
}
ref_schema = {
'type': 'record',
'namespace': 'test',
'name': 'B',
'fields': [
{'name': 'stringField', 'type': 'string'},
]
}
client.register_schema('ref', Schema(json.dumps(ref_schema)))
schema = ['null', {
'type': 'record',
'name': 'A',
'namespace': 'test',
'fields': [
{'name': 'First', 'type': 'B'},
{'name': 'Second', 'type': 'B'}
]
}]
refs = [SchemaReference('test.B', 'ref', 1)]
client.register_schema(_SUBJECT, Schema(json.dumps(schema), 'AVRO', refs))

ser = AvroSerializer(client, schema_str=None, conf=ser_conf)
ser_ctx = SerializationContext(_TOPIC, MessageField.VALUE)
obj_bytes = ser(obj, ser_ctx)

deser = AvroDeserializer(client)
obj2 = deser(obj_bytes, ser_ctx)
assert obj == obj2


def test_avro_serialize_union_with_references():
conf = {'url': _BASE_URL}
client = SchemaRegistryClient.new_client(conf)
Expand Down

0 comments on commit 3f40f19

Please sign in to comment.