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

11 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

1from fastapi.testclient import TestClient 1abcde

2 

3from docs_src.path_operation_advanced_configuration.tutorial006 import app 1abcde

4 

5client = TestClient(app) 1abcde

6 

7 

8def test_post(): 1abcde

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

10 assert response.status_code == 200, response.text 1abcde

11 assert response.json() == { 1abcde

12 "size": 30, 

13 "content": { 

14 "name": "Maaaagic", 

15 "price": 42, 

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

17 }, 

18 } 

19 

20 

21def test_openapi_schema(): 1abcde

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

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

24 assert response.json() == { 1abcde

25 "openapi": "3.1.0", 

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

27 "paths": { 

28 "/items/": { 

29 "post": { 

30 "summary": "Create Item", 

31 "operationId": "create_item_items__post", 

32 "requestBody": { 

33 "content": { 

34 "application/json": { 

35 "schema": { 

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

37 "type": "object", 

38 "properties": { 

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

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

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

42 }, 

43 } 

44 } 

45 }, 

46 "required": True, 

47 }, 

48 "responses": { 

49 "200": { 

50 "description": "Successful Response", 

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

52 } 

53 }, 

54 } 

55 } 

56 }, 

57 }