Coverage for tests/test_response_model_invalid.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-01-13 13:38 +0000

1from typing import List 1abcde

2 

3import pytest 1abcde

4from fastapi import FastAPI 1abcde

5from fastapi.exceptions import FastAPIError 1abcde

6 

7 

8class NonPydanticModel: 1abcde

9 pass 1abcde

10 

11 

12def test_invalid_response_model_raises(): 1abcde

13 with pytest.raises(FastAPIError): 1fghij

14 app = FastAPI() 1fghij

15 

16 @app.get("/", response_model=NonPydanticModel) 1fghij

17 def read_root(): 1fghij

18 pass # pragma: nocover 

19 

20 

21def test_invalid_response_model_sub_type_raises(): 1abcde

22 with pytest.raises(FastAPIError): 1klmno

23 app = FastAPI() 1klmno

24 

25 @app.get("/", response_model=List[NonPydanticModel]) 1klmno

26 def read_root(): 1klmno

27 pass # pragma: nocover 

28 

29 

30def test_invalid_response_model_in_responses_raises(): 1abcde

31 with pytest.raises(FastAPIError): 1pqrst

32 app = FastAPI() 1pqrst

33 

34 @app.get("/", responses={"500": {"model": NonPydanticModel}}) 1pqrst

35 def read_root(): 1pqrst

36 pass # pragma: nocover 

37 

38 

39def test_invalid_response_model_sub_type_in_responses_raises(): 1abcde

40 with pytest.raises(FastAPIError): 1uvwxy

41 app = FastAPI() 1uvwxy

42 

43 @app.get("/", responses={"500": {"model": List[NonPydanticModel]}}) 1uvwxy

44 def read_root(): 1uvwxy

45 pass # pragma: nocover