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

35 statements  

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

1from typing import Annotated 1a

2 

3from pydantic import Field, StringConstraints, field_validator 1a

4from pydantic_core.core_schema import ValidationInfo 1a

5 

6from mealie.schema._mealie import MealieModel 1a

7from mealie.schema._mealie.validators import validate_locale 1a

8 

9 

10class CreateUserRegistration(MealieModel): 1a

11 group: str | None = None 1a

12 household: str | None = None 1a

13 group_token: Annotated[str | None, Field(validate_default=True)] = None 1a

14 email: Annotated[str, StringConstraints(to_lower=True, strip_whitespace=True)] 1a

15 username: Annotated[str, StringConstraints(to_lower=True, strip_whitespace=True)] 1a

16 full_name: Annotated[str, StringConstraints(strip_whitespace=True)] 1a

17 password: str 1a

18 password_confirm: str 1a

19 advanced: bool = False 1a

20 private: bool = False 1a

21 

22 seed_data: bool = False 1a

23 locale: str = "en-US" 1a

24 

25 @field_validator("locale") 1a

26 def valid_locale(cls, v): 1a

27 if not validate_locale(v): 27 ↛ 29line 27 didn't jump to line 29 because the condition on line 27 was always true1defbghinjklompqrc

28 raise ValueError("invalid locale") 1defbghinjklompqrc

29 return v 

30 

31 @field_validator("password_confirm") 1a

32 @classmethod 1a

33 def passwords_match(cls, value, info: ValidationInfo): 1a

34 if "password" in info.data and value != info.data["password"]: 1vdefsbwgxhyzinjkloAmpqrtuBc

35 raise ValueError("passwords do not match") 1defsbwgxhyzinjkloAmpqrtuBc

36 return value 1vesbc

37 

38 @field_validator("group_token") 1a

39 @classmethod 1a

40 def group_or_token(cls, value, info: ValidationInfo): 1a

41 if not bool(value) and not bool(info.data["group"]): 1vdefsbwgxhyzinjkloAmpqrtuBc

42 raise ValueError("group or group_token must be provided") 1defsbwgxhyzinjkloAmqrtuBc

43 

44 return value 1vdfbghijklmptuc