Coverage for tests / test_tutorial / test_graphql / test_tutorial001.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-12 18:15 +0000

1import warnings 1abdc

2 

3import pytest 1abdc

4from inline_snapshot import snapshot 1abdc

5from starlette.testclient import TestClient 1abdc

6 

7warnings.filterwarnings( 1abdc

8 "ignore", 

9 message=r"The 'lia' package has been renamed to 'cross_web'\..*", 

10 category=DeprecationWarning, 

11) 

12 

13from docs_src.graphql_.tutorial001_py310 import app # noqa: E402 1abdc

14 

15 

16@pytest.fixture(name="client") 1abdc

17def get_client() -> TestClient: 1abdc

18 return TestClient(app) 1abc

19 

20 

21def test_query(client: TestClient): 1abdc

22 response = client.post("/graphql", json={"query": "{ user { name, age } }"}) 1efg

23 assert response.status_code == 200 1efg

24 assert response.json() == {"data": {"user": {"name": "Patrick", "age": 100}}} 1efg

25 

26 

27def test_openapi(client: TestClient): 1abdc

28 response = client.get("/openapi.json") 1hij

29 assert response.status_code == 200 1hij

30 assert response.json() == snapshot( 1hij

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 )