Coverage for tests / test_tutorial / test_custom_response / test_tutorial001b.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-04-06 01:24 +0000

1import warnings 1abcd

2 

3import pytest 1abcd

4from fastapi.exceptions import FastAPIDeprecationWarning 1abcd

5from fastapi.testclient import TestClient 1abcd

6from inline_snapshot import snapshot 1abcd

7 

8with warnings.catch_warnings(): 1abcd

9 warnings.simplefilter("ignore", FastAPIDeprecationWarning) 1abcd

10 from docs_src.custom_response.tutorial001b_py310 import app 1abcd

11 

12client = TestClient(app) 1abcd

13 

14 

15@pytest.mark.filterwarnings("ignore::fastapi.exceptions.FastAPIDeprecationWarning") 1abcd

16def test_get_custom_response(): 1abcd

17 response = client.get("/items/") 1efgh

18 assert response.status_code == 200, response.text 1efgh

19 assert response.json() == [{"item_id": "Foo"}] 1efgh

20 

21 

22@pytest.mark.filterwarnings("ignore::fastapi.exceptions.FastAPIDeprecationWarning") 1abcd

23def test_openapi_schema(): 1abcd

24 response = client.get("/openapi.json") 1ijkl

25 assert response.status_code == 200, response.text 1ijkl

26 assert response.json() == snapshot( 1ijkl

27 { 

28 "openapi": "3.1.0", 

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

30 "paths": { 

31 "/items/": { 

32 "get": { 

33 "responses": { 

34 "200": { 

35 "description": "Successful Response", 

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

37 } 

38 }, 

39 "summary": "Read Items", 

40 "operationId": "read_items_items__get", 

41 } 

42 } 

43 }, 

44 } 

45 )