Browse Source

Add test for `docs_src.graphql.tutorial001.py`

pull/14569/head
Yurii Motov 7 months ago
parent
commit
d89c03b3fd
  1. 1
      requirements-tests.txt
  2. 0
      tests/test_tutorial/test_graphql/__init__.py
  3. 62
      tests/test_tutorial/test_graphql/test_tutorial001.py

1
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

0
tests/test_tutorial/test_graphql/__init__.py

62
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",
},
},
},
}
Loading…
Cancel
Save