Coverage for opt/mealie/lib/python3.12/site-packages/mealie/schema/response/responses.py: 95%

20 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-11-25 17:29 +0000

1from pydantic import BaseModel 1a

2 

3from mealie.schema._mealie import MealieModel 1a

4 

5 

6class ErrorResponse(BaseModel): 1a

7 message: str 1a

8 error: bool = True 1a

9 exception: str | None = None 1a

10 

11 @classmethod 1a

12 def respond(cls, message: str, exception: str | None = None) -> dict: 1a

13 """ 

14 This method is an helper to create an object and convert to a dictionary 

15 in the same call, for use while providing details to a HTTPException 

16 """ 

17 return cls(message=message, exception=exception).model_dump() 1cdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYb

18 

19 

20class SuccessResponse(BaseModel): 1a

21 message: str 1a

22 error: bool = False 1a

23 

24 @classmethod 1a

25 def respond(cls, message: str = "") -> dict: 1a

26 """ 

27 This method is an helper to create an object and convert to a dictionary 

28 in the same call, for use while providing details to a HTTPException 

29 """ 

30 return cls(message=message).model_dump() 

31 

32 

33class FileTokenResponse(MealieModel): 1a

34 file_token: str 1a

35 

36 @classmethod 1a

37 def respond(cls, token: str) -> dict: 1a

38 """ 

39 This method is an helper to create an object and convert to a dictionary 

40 in the same call, for use while providing details to a HTTPException 

41 """ 

42 return cls(file_token=token).model_dump()