Debian Codegraph @

tests/test_tutorial/test_graphql/test_tutorial001.py

raw
1 import warnings
2
3 import pytest
4 from inline_snapshot import snapshot
5 from starlette.testclient import TestClient
6
7 warnings.filterwarnings(
8 "ignore",
9 message=r"The 'lia' package has been renamed to 'cross_web'\..*",
10 category=DeprecationWarning,
11 )
12
13 from docs_src.graphql_.tutorial001_py310 import app # noqa: E402
14
15
16 @pytest.fixture(name="client")
17 def get_client() -> TestClient:
18 return TestClient(app)
19
20
21 def test_query(client: TestClient):
22 response = client.post("/graphql", json={"query": "{ user { name, age } }"})
23 assert response.status_code == 200
24 assert response.json() == {"data": {"user": {"name": "Patrick", "age": 100}}}
25
26
27 def test_openapi(client: TestClient):
28 response = client.get("/openapi.json")
29 assert response.status_code == 200
30 assert response.json() == snapshot(
31 {
32 "info": {
33 "title": "FastAPI",
34 "version": "0.1.0",
35 },
36 "openapi": "3.1.0",
37 "paths": {
38 "/graphql": {
39 "get": {
40 "operationId": "handle_http_get_graphql_get",
41 "responses": {
42 "200": {
43 "content": {
44 "application/json": {
45 "schema": {},
46 },
47 },
48 "description": "The GraphiQL integrated development environment.",
49 },
50 "404": {
51 "description": "Not found if GraphiQL or query via GET are not enabled.",
52 },
53 },
54 "summary": "Handle Http Get",
55 },
56 "post": {
57 "operationId": "handle_http_post_graphql_post",
58 "responses": {
59 "200": {
60 "content": {
61 "application/json": {
62 "schema": {},
63 },
64 },
65 "description": "Successful Response",
66 },
67 },
68 "summary": "Handle Http Post",
69 },
70 },
71 },
72 }
73 )