Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
228 changes: 118 additions & 110 deletions tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial001.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,115 +4,6 @@
from sqlmodel import create_engine
from sqlmodel.pool import StaticPool

openapi_schema = {
"openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/heroes/": {
"get": {
"summary": "Read Heroes",
"operationId": "read_heroes_heroes__get",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"title": "Response Read Heroes Heroes Get",
"type": "array",
"items": {"$ref": "#/components/schemas/HeroRead"},
}
}
},
}
},
},
"post": {
"summary": "Create Hero",
"operationId": "create_hero_heroes__post",
"requestBody": {
"content": {
"application/json": {
"schema": {"$ref": "#/components/schemas/HeroCreate"}
}
},
"required": True,
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {"$ref": "#/components/schemas/HeroRead"}
}
},
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
},
},
},
},
}
},
"components": {
"schemas": {
"HTTPValidationError": {
"title": "HTTPValidationError",
"type": "object",
"properties": {
"detail": {
"title": "Detail",
"type": "array",
"items": {"$ref": "#/components/schemas/ValidationError"},
}
},
},
"HeroCreate": {
"title": "HeroCreate",
"required": ["name", "secret_name"],
"type": "object",
"properties": {
"name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"},
},
},
"HeroRead": {
"title": "HeroRead",
"required": ["id", "name", "secret_name"],
"type": "object",
"properties": {
"id": {"title": "Id", "type": "integer"},
"name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"},
},
},
"ValidationError": {
"title": "ValidationError",
"required": ["loc", "msg", "type"],
"type": "object",
"properties": {
"loc": {
"title": "Location",
"type": "array",
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
},
},
}
},
}


def test_tutorial(clear_sqlmodel):
from docs_src.tutorial.fastapi.multiple_models import tutorial001 as mod
Expand Down Expand Up @@ -166,7 +57,124 @@ def test_tutorial(clear_sqlmodel):

assert response.status_code == 200, response.text

assert data == openapi_schema
assert data == {
"openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/heroes/": {
"get": {
"summary": "Read Heroes",
"operationId": "read_heroes_heroes__get",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"title": "Response Read Heroes Heroes Get",
"type": "array",
"items": {
"$ref": "#/components/schemas/HeroRead"
},
}
}
},
}
},
},
"post": {
"summary": "Create Hero",
"operationId": "create_hero_heroes__post",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HeroCreate"
}
}
},
"required": True,
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HeroRead"
}
}
},
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
},
},
},
},
}
},
"components": {
"schemas": {
"HTTPValidationError": {
"title": "HTTPValidationError",
"type": "object",
"properties": {
"detail": {
"title": "Detail",
"type": "array",
"items": {
"$ref": "#/components/schemas/ValidationError"
},
}
},
},
"HeroCreate": {
"title": "HeroCreate",
"required": ["name", "secret_name"],
"type": "object",
"properties": {
"name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"},
},
},
"HeroRead": {
"title": "HeroRead",
"required": ["id", "name", "secret_name"],
"type": "object",
"properties": {
"id": {"title": "Id", "type": "integer"},
"name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"},
},
},
"ValidationError": {
"title": "ValidationError",
"required": ["loc", "msg", "type"],
"type": "object",
"properties": {
"loc": {
"title": "Location",
"type": "array",
"items": {
"anyOf": [{"type": "string"}, {"type": "integer"}]
},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
},
},
}
},
}

# Test inherited indexes
insp: Inspector = inspect(mod.engine)
Expand Down
Loading