Skip to content

Commit 3f40f19

Browse files
authored
Add test with record refs (#1932)
1 parent 8b9afc0 commit 3f40f19

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/schema_registry/test_avro_serdes.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,45 @@ def test_avro_serialize_union():
247247
assert obj == obj2
248248

249249

250+
def test_avro_serialize_union_with_record_references():
251+
conf = {'url': _BASE_URL}
252+
client = SchemaRegistryClient.new_client(conf)
253+
ser_conf = {'auto.register.schemas': False, 'use.latest.version': True}
254+
255+
obj = {
256+
'First': {'stringField': 'hi'},
257+
'Second': {'stringField': 'hi'},
258+
}
259+
ref_schema = {
260+
'type': 'record',
261+
'namespace': 'test',
262+
'name': 'B',
263+
'fields': [
264+
{'name': 'stringField', 'type': 'string'},
265+
]
266+
}
267+
client.register_schema('ref', Schema(json.dumps(ref_schema)))
268+
schema = ['null', {
269+
'type': 'record',
270+
'name': 'A',
271+
'namespace': 'test',
272+
'fields': [
273+
{'name': 'First', 'type': 'B'},
274+
{'name': 'Second', 'type': 'B'}
275+
]
276+
}]
277+
refs = [SchemaReference('test.B', 'ref', 1)]
278+
client.register_schema(_SUBJECT, Schema(json.dumps(schema), 'AVRO', refs))
279+
280+
ser = AvroSerializer(client, schema_str=None, conf=ser_conf)
281+
ser_ctx = SerializationContext(_TOPIC, MessageField.VALUE)
282+
obj_bytes = ser(obj, ser_ctx)
283+
284+
deser = AvroDeserializer(client)
285+
obj2 = deser(obj_bytes, ser_ctx)
286+
assert obj == obj2
287+
288+
250289
def test_avro_serialize_union_with_references():
251290
conf = {'url': _BASE_URL}
252291
client = SchemaRegistryClient.new_client(conf)

0 commit comments

Comments
 (0)