Skip to content

Commit 3839907

Browse files
authored
Merge pull request #1862 from tisnik/lcore-2400---
LCORE-2400: Unit test for dump_schema function
2 parents 716c165 + 11d5063 commit 3839907

1 file changed

Lines changed: 110 additions & 1 deletion

File tree

tests/unit/utils/test_schema_dumper.py

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"""Unit tests for utils/schema_dumper module."""
22

3+
from json import load
4+
from pathlib import Path
35
from typing import Any
46

5-
from utils.schema_dumper import recursive_update
7+
from utils.schema_dumper import dump_schema, recursive_update
68

79

810
def test_update_empty_input() -> None:
@@ -409,3 +411,110 @@ def test_anyof_with_additional_fields_more_items() -> None:
409411

410412
# non-empty dict with known content should be returned
411413
assert result == expected
414+
415+
416+
def test_dump_schema(tmpdir: Path) -> None:
417+
"""Test that schema can be dump into a JSON file.
418+
419+
An example of schema dump:
420+
{
421+
"openapi": "3.0.0",
422+
"info": {
423+
"title": "Lightspeed Core Stack",
424+
"version": "0.3.0"
425+
},
426+
"components": {
427+
"schemas": {
428+
"A2AStateConfiguration": {
429+
"additionalProperties": false,
430+
"description": "xyzzy",
431+
"properties": {
432+
"sqlite": {
433+
"anyOf": [
434+
{
435+
"$ref": "#/components/schemas/SQLiteDatabaseConfiguration"
436+
},
437+
{
438+
"type": "null"
439+
}
440+
],
441+
"default": null,
442+
"description": "SQLite database configuration for A2A state storage.",
443+
"title": "SQLite configuration"
444+
},
445+
...
446+
}
447+
...
448+
...
449+
...
450+
},
451+
"paths": {}
452+
}
453+
"""
454+
filename = tmpdir / "foo.json"
455+
dump_schema(str(filename))
456+
457+
with open(filename, "r", encoding="utf-8") as fin:
458+
# schema should be stored in JSON format
459+
content = load(fin)
460+
assert content is not None
461+
462+
# top-level keys test
463+
keys = ("openapi", "info", "components", "paths")
464+
for key in keys:
465+
assert key in content
466+
467+
# components should be top-level node
468+
components = content["components"]
469+
assert components is not None
470+
471+
# schemas should be a node stored inside components node
472+
assert "schemas" in components
473+
schemas = components["schemas"]
474+
assert schemas is not None
475+
476+
# list of schemas expected in a dump
477+
expected_schemas = (
478+
"A2AStateConfiguration",
479+
"APIKeyTokenConfiguration",
480+
"AccessRule",
481+
"Action",
482+
"ApprovalFilter",
483+
"ApprovalsConfiguration",
484+
"AuthenticationConfiguration",
485+
"AuthorizationConfiguration",
486+
"AzureEntraIdConfiguration",
487+
"ByokRag",
488+
"CORSConfiguration",
489+
"CompactionConfiguration",
490+
"Configuration",
491+
"ConversationHistoryConfiguration",
492+
"CustomProfile",
493+
"Customization",
494+
"DatabaseConfiguration",
495+
"InMemoryCacheConfig",
496+
"InferenceConfiguration",
497+
"JsonPathOperator",
498+
"JwkConfiguration",
499+
"JwtConfiguration",
500+
"JwtRoleRule",
501+
"LlamaStackConfiguration",
502+
"ModelContextProtocolServer",
503+
"OkpConfiguration",
504+
"PostgreSQLDatabaseConfiguration",
505+
"QuotaHandlersConfiguration",
506+
"QuotaLimiterConfiguration",
507+
"QuotaSchedulerConfiguration",
508+
"RHIdentityConfiguration",
509+
"RagConfiguration",
510+
"RerankerConfiguration",
511+
"RlsapiV1Configuration",
512+
"SQLiteDatabaseConfiguration",
513+
"ServiceConfiguration",
514+
"SkillsConfiguration",
515+
"SplunkConfiguration",
516+
"TLSConfiguration",
517+
"UserDataCollection",
518+
)
519+
for expected_schema in expected_schemas:
520+
assert expected_schema in schemas

0 commit comments

Comments
 (0)