Coverage for tests/test_tutorial/test_custom_request_and_route/test_tutorial002.py: 100%

10 statements  

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

1from dirty_equals import IsDict 1abcde

2from fastapi.testclient import TestClient 1abcde

3 

4from docs_src.custom_request_and_route.tutorial002 import app 1abcde

5 

6client = TestClient(app) 1abcde

7 

8 

9def test_endpoint_works(): 1abcde

10 response = client.post("/", json=[1, 2, 3]) 1abcde

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

12 

13 

14def test_exception_handler_body_access(): 1abcde

15 response = client.post("/", json={"numbers": [1, 2, 3]}) 1abcde

16 assert response.json() == IsDict( 1abcde

17 { 

18 "detail": { 

19 "errors": [ 

20 { 

21 "type": "list_type", 

22 "loc": ["body"], 

23 "msg": "Input should be a valid list", 

24 "input": {"numbers": [1, 2, 3]}, 

25 } 

26 ], 

27 "body": '{"numbers": [1, 2, 3]}', 

28 } 

29 } 

30 ) | IsDict( 

31 # TODO: remove when deprecating Pydantic v1 

32 { 

33 "detail": { 

34 "body": '{"numbers": [1, 2, 3]}', 

35 "errors": [ 

36 { 

37 "loc": ["body"], 

38 "msg": "value is not a valid list", 

39 "type": "type_error.list", 

40 } 

41 ], 

42 } 

43 } 

44 )