forked from Aiven-Open/karapace
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_schema_avro_references.py
58 lines (48 loc) · 1.79 KB
/
test_schema_avro_references.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
karapace - schema tests
Copyright (c) 2023 Aiven Ltd
See LICENSE for details
"""
from karapace.client import Client
import json
baseurl = "http://localhost:8081"
async def test_avro_references(registry_async_client: Client) -> None:
schema_country = {
"type": "record",
"name": "Country",
"namespace": "com.netapp",
"fields": [{"name": "name", "type": "string"}, {"name": "code", "type": "string"}],
}
schema_address = {
"type": "record",
"name": "Address",
"namespace": "com.netapp",
"fields": [
{"name": "street", "type": "string"},
{"name": "city", "type": "string"},
{"name": "postalCode", "type": "string"},
{"name": "country", "type": "Country"},
],
}
res = await registry_async_client.post("subjects/country/versions", json={"schema": json.dumps(schema_country)})
assert res.status_code == 200
assert "id" in res.json()
country_references = [{"name": "country.proto", "subject": "country", "version": 1}]
res = await registry_async_client.post(
"subjects/address/versions",
json={"schemaType": "AVRO", "schema": json.dumps(schema_address), "references": country_references},
)
assert res.status_code == 200
assert "id" in res.json()
address_id = res.json()["id"]
# Check if the schema has now been registered under the subject
res = await registry_async_client.post(
"subjects/address",
json={"schemaType": "AVRO", "schema": json.dumps(schema_address), "references": country_references},
)
assert res.status_code == 200
assert "subject" in res.json()
assert "id" in res.json()
assert address_id == res.json()["id"]
assert "version" in res.json()
assert "schema" in res.json()