Coverage for tests / test_tutorial / test_path_operation_advanced_configurations / test_tutorial006.py: 100%

12 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_advanced_configuration.tutorial006_py310 import app 1abcd

5 

6client = TestClient(app) 1abcd

7 

8 

9def test_post(): 1abcd

10 response = client.post("/items/", content=b"this is actually not validated") 1efg

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

12 assert response.json() == { 1efg

13 "size": 30, 

14 "content": { 

15 "name": "Maaaagic", 

16 "price": 42, 

17 "description": "Just kiddin', no magic here. ✨", 

18 }, 

19 } 

20 

21 

22def test_openapi_schema(): 1abcd

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

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

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

26 { 

27 "openapi": "3.1.0", 

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

29 "paths": { 

30 "/items/": { 

31 "post": { 

32 "summary": "Create Item", 

33 "operationId": "create_item_items__post", 

34 "requestBody": { 

35 "content": { 

36 "application/json": { 

37 "schema": { 

38 "required": ["name", "price"], 

39 "type": "object", 

40 "properties": { 

41 "name": {"type": "string"}, 

42 "price": {"type": "number"}, 

43 "description": {"type": "string"}, 

44 }, 

45 } 

46 } 

47 }, 

48 "required": True, 

49 }, 

50 "responses": { 

51 "200": { 

52 "description": "Successful Response", 

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

54 } 

55 }, 

56 } 

57 } 

58 }, 

59 } 

60 )