Coverage for tests / test_tutorial / test_path_operation_configurations / test_tutorial002b.py: 100%

16 statements  

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

1from fastapi.testclient import TestClient 1abcd

2from inline_snapshot import snapshot 1abcd

3 

4from docs_src.path_operation_configuration.tutorial002b_py310 import app 1abcd

5 

6client = TestClient(app) 1abcd

7 

8 

9def test_get_items(): 1abcd

10 response = client.get("/items/") 1efg

11 assert response.status_code == 200, response.text 1efg

12 assert response.json() == ["Portal gun", "Plumbus"] 1efg

13 

14 

15def test_get_users(): 1abcd

16 response = client.get("/users/") 1hij

17 assert response.status_code == 200, response.text 1hij

18 assert response.json() == ["Rick", "Morty"] 1hij

19 

20 

21def test_openapi_schema(): 1abcd

22 response = client.get("/openapi.json") 1klm

23 assert response.status_code == 200, response.text 1klm

24 assert response.json() == snapshot( 1klm

25 { 

26 "openapi": "3.1.0", 

27 "info": {"title": "FastAPI", "version": "0.1.0"}, 

28 "paths": { 

29 "/items/": { 

30 "get": { 

31 "tags": ["items"], 

32 "summary": "Get Items", 

33 "operationId": "get_items_items__get", 

34 "responses": { 

35 "200": { 

36 "description": "Successful Response", 

37 "content": {"application/json": {"schema": {}}}, 

38 } 

39 }, 

40 } 

41 }, 

42 "/users/": { 

43 "get": { 

44 "tags": ["users"], 

45 "summary": "Read Users", 

46 "operationId": "read_users_users__get", 

47 "responses": { 

48 "200": { 

49 "description": "Successful Response", 

50 "content": {"application/json": {"schema": {}}}, 

51 } 

52 }, 

53 } 

54 }, 

55 }, 

56 } 

57 )