Add missing tests for code examples (#14569)

Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Nils-Hero Lindemann <nilsherolindemann@proton.me>
This commit is contained in:
Motov Yurii
2025-12-26 11:43:02 +01:00
committed by GitHub
parent 5eb8d6ed8a
commit 3063ada72f
183 changed files with 10459 additions and 86 deletions

View File

View File

@@ -0,0 +1,70 @@
import warnings
import pytest
from starlette.testclient import TestClient
warnings.filterwarnings(
"ignore",
message=r"The 'lia' package has been renamed to 'cross_web'\..*",
category=DeprecationWarning,
)
from docs_src.graphql_.tutorial001_py39 import app # noqa: E402
@pytest.fixture(name="client")
def get_client() -> TestClient:
return TestClient(app)
def test_query(client: TestClient):
response = client.post("/graphql", json={"query": "{ user { name, age } }"})
assert response.status_code == 200
assert response.json() == {"data": {"user": {"name": "Patrick", "age": 100}}}
def test_openapi(client: TestClient):
response = client.get("/openapi.json")
assert response.status_code == 200
assert response.json() == {
"info": {
"title": "FastAPI",
"version": "0.1.0",
},
"openapi": "3.1.0",
"paths": {
"/graphql": {
"get": {
"operationId": "handle_http_get_graphql_get",
"responses": {
"200": {
"content": {
"application/json": {
"schema": {},
},
},
"description": "The GraphiQL integrated development environment.",
},
"404": {
"description": "Not found if GraphiQL or query via GET are not enabled.",
},
},
"summary": "Handle Http Get",
},
"post": {
"operationId": "handle_http_post_graphql_post",
"responses": {
"200": {
"content": {
"application/json": {
"schema": {},
},
},
"description": "Successful Response",
},
},
"summary": "Handle Http Post",
},
},
},
}