Skip to content

Commit 468bea8

Browse files
committed
sr/dt: test subject query param for GET /schemas/ids/{id}/subjects
The GET /schemas/ids/{id}/subjects endpoint now supports an optional subject query parameter for context-based schema lookup. This commit adds a ducktape test covering: - Baseline lookup without a subject param (default context) - Context-only lookup using ":.ctx1:" to scope results to a context - Error case for a non-existent context Extended search behavior is already covered by test_get_schema_versions_with_subject, so this test focuses on verifying the param is wired through and the response format is correct.
1 parent 6b2f820 commit 468bea8

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

tests/rptest/tests/schema_registry_test.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,11 +1035,17 @@ def get_schemas_ids_id_versions(
10351035
)
10361036

10371037
def get_schemas_ids_id_subjects(
1038-
self, id, deleted=False, headers=HTTP_GET_HEADERS, **kwargs
1038+
self, id, deleted=False, subject=None, headers=HTTP_GET_HEADERS, **kwargs
10391039
):
1040+
query_params = []
1041+
if deleted:
1042+
query_params.append("deleted=true")
1043+
if subject is not None:
1044+
query_params.append(f"subject={subject}")
1045+
query_string = f"?{'&'.join(query_params)}" if query_params else ""
10401046
return self.request(
10411047
"GET",
1042-
f"schemas/ids/{id}/subjects{'?deleted=true' if deleted else ''}",
1048+
f"schemas/ids/{id}/subjects{query_string}",
10431049
headers=headers,
10441050
**kwargs,
10451051
)
@@ -5812,6 +5818,52 @@ def test_get_schema_versions_with_subject(self):
58125818
)
58135819
self.assert_equal(result.status_code, requests.codes.not_found)
58145820

5821+
@cluster(num_nodes=1)
5822+
def test_get_schema_subjects_with_subject(self):
5823+
"""Test GET /schemas/ids/{id}/subjects with subject query parameter for context lookup.
5824+
5825+
Extended search (resolve_schema_id_extended) is already covered by
5826+
test_get_schema_versions_with_subject; here we only verify the param
5827+
is wired up and the response format is correct.
5828+
"""
5829+
5830+
# Register schema1 in default context under sub1 and sub2
5831+
result = self.sr_client.post_subjects_subject_versions(
5832+
subject="sub1", data=json.dumps({"schema": schema1_def})
5833+
)
5834+
self.assert_equal(result.status_code, requests.codes.ok)
5835+
default_schema1_id = result.json()["id"]
5836+
5837+
result = self.sr_client.post_subjects_subject_versions(
5838+
subject="sub2", data=json.dumps({"schema": schema1_def})
5839+
)
5840+
self.assert_equal(result.status_code, requests.codes.ok)
5841+
5842+
# Register schema1 in ctx1 context
5843+
result = self.sr_client.post_subjects_subject_versions(
5844+
subject=":.ctx1:sub1", data=json.dumps({"schema": schema1_def})
5845+
)
5846+
self.assert_equal(result.status_code, requests.codes.ok)
5847+
ctx1_schema1_id = result.json()["id"]
5848+
5849+
# Without subject param - returns subjects from default context
5850+
result = self.sr_client.get_schemas_ids_id_subjects(id=default_schema1_id)
5851+
self.assert_equal(result.status_code, requests.codes.ok)
5852+
self.assert_equal(set(result.json()), {"sub1", "sub2"})
5853+
5854+
# With context-only param ":.ctx1:" - returns subjects from ctx1
5855+
result = self.sr_client.get_schemas_ids_id_subjects(
5856+
id=ctx1_schema1_id, subject=":.ctx1:"
5857+
)
5858+
self.assert_equal(result.status_code, requests.codes.ok)
5859+
self.assert_equal(result.json(), [":.ctx1:sub1"])
5860+
5861+
# Error case - schema ID not found in specified context
5862+
result = self.sr_client.get_schemas_ids_id_subjects(
5863+
id=ctx1_schema1_id, subject=":.nonexistent:"
5864+
)
5865+
self.assert_equal(result.status_code, requests.codes.not_found)
5866+
58155867

58165868
class SchemaRegistryBasicAuthTest(SchemaRegistryEndpoints):
58175869
"""

0 commit comments

Comments
 (0)