From d89c03b3fd39e2e001575839bdc294c9959ccb7e Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Tue, 16 Dec 2025 15:41:42 +0100 Subject: [PATCH] Add test for `docs_src.graphql.tutorial001.py` --- requirements-tests.txt | 1 + tests/test_tutorial/test_graphql/__init__.py | 0 .../test_graphql/test_tutorial001.py | 62 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 tests/test_tutorial/test_graphql/__init__.py create mode 100644 tests/test_tutorial/test_graphql/test_tutorial001.py diff --git a/requirements-tests.txt b/requirements-tests.txt index c5de4157e..1cbede891 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -6,6 +6,7 @@ mypy ==1.14.1 dirty-equals ==0.9.0 sqlmodel==0.0.27 flask >=1.1.2,<4.0.0 +strawberry-graphql >=0.200.0,< 1.0.0 anyio[trio] >=3.2.1,<5.0.0 PyJWT==2.9.0 pyyaml >=5.3.1,<7.0.0 diff --git a/tests/test_tutorial/test_graphql/__init__.py b/tests/test_tutorial/test_graphql/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/test_tutorial/test_graphql/test_tutorial001.py b/tests/test_tutorial/test_graphql/test_tutorial001.py new file mode 100644 index 000000000..4e2e69e8c --- /dev/null +++ b/tests/test_tutorial/test_graphql/test_tutorial001.py @@ -0,0 +1,62 @@ +import pytest +from starlette.testclient import TestClient + +from docs_src.graphql.tutorial001 import app + + +@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", + }, + }, + }, + }