Coverage for tests / test_tutorial / test_path_params / test_tutorial003b.py: 100%

15 statements  

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

1import asyncio 1abcd

2 

3from fastapi.testclient import TestClient 1abcd

4from inline_snapshot import snapshot 1abcd

5 

6from docs_src.path_params.tutorial003b_py310 import app, read_users2 1abcd

7 

8client = TestClient(app) 1abcd

9 

10 

11def test_get_users(): 1abcd

12 response = client.get("/users") 1efg

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

14 assert response.json() == ["Rick", "Morty"] 1efg

15 

16 

17def test_read_users2(): # Just for coverage 1abcd

18 assert asyncio.run(read_users2()) == ["Bean", "Elfo"] 1klm

19 

20 

21def test_openapi_schema(): 1abcd

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

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

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

25 { 

26 "openapi": "3.1.0", 

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

28 "paths": { 

29 "/users": { 

30 "get": { 

31 "operationId": "read_users2_users_get", 

32 "responses": { 

33 "200": { 

34 "content": { 

35 "application/json": { 

36 "schema": {}, 

37 }, 

38 }, 

39 "description": "Successful Response", 

40 }, 

41 }, 

42 "summary": "Read Users2", 

43 }, 

44 }, 

45 }, 

46 } 

47 )