/
semak
/
py-client-generator
Обзор
Документация
Войти
/
semak
/
py-client-generator
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
tests/test_models.py
97 строк
3 KB
semak
ruff
17 июн 2026, 17:15
17 июн 2026, 17:15
783585d
Код
Авторство
О чём код?
from py_client_generator.openapi.models import ( OpenAPISpec, Schema, Parameter, Operation, PathItem, Components, RequestBody, Response, Discriminator, HttpSecurityScheme, ) class TestSchema: def test_simple(self): assert Schema(type="string").type == "string" def test_with_ref(self): assert ( Schema(**{"$ref": "#/components/schemas/Pet"}).ref == "#/components/schemas/Pet" ) def test_with_enum(self): assert Schema(type="string", enum=["a", "b"]).enum == ["a", "b"] def test_discriminator(self): disc = Discriminator(propertyName="type") s = Schema(type="object", discriminator=disc) assert s.discriminator.property_name == "type" class TestOperation: def test_minimal(self): op = Operation(responses={"200": Response(description="OK")}) assert op.responses["200"].description == "OK" def test_with_body(self): rb = RequestBody(content={"application/json": {"schema": {"type": "object"}}}) op = Operation( operationId="create", responses={"200": Response(description="OK")}, requestBody=rb, ) assert op.operation_id == "create" and op.request_body is not None class TestPathItem: def test_get(self): op = Operation(responses={"200": Response(description="OK")}) p = PathItem(get=op) assert p.get is not None and p.post is None def test_multiple_methods(self): ok = {"200": Response(description="OK")} p = PathItem(get=Operation(responses=ok), post=Operation(responses=ok)) assert p.get and p.post class TestComponents: def test_schemas(self): c = Components(schemas={"Pet": Schema(type="object")}) assert "Pet" in c.schemas def test_security_schemes(self): c = Components(securitySchemes={"bearer": HttpSecurityScheme(scheme="bearer")}) assert "bearer" in c.security_schemes class TestOpenAPISpec: def test_minimal(self): s = OpenAPISpec( openapi="3.0.0", info={"title": "API", "version": "1.0.0"}, paths={} ) assert s.openapi == "3.0.0" def test_with_paths(self): s = OpenAPISpec( openapi="3.0.0", info={"title": "API", "version": "1.0.0"}, paths={ "/pets": PathItem( get=Operation(responses={"200": Response(description="OK")}) ) }, ) assert "/pets" in s.paths def test_with_components(self): s = OpenAPISpec( openapi="3.0.0", info={"title": "API", "version": "1.0.0"}, paths={}, components=Components(schemas={"Pet": Schema(type="object")}), ) assert s.components.schemas["Pet"].type == "object"