Coverage for api/account/schema.py: 100.00%

28 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-09-03 15:30 +0000

1from datetime import datetime 

2 

3from pydantic import BaseModel, EmailStr, Field, model_validator 

4 

5from core.config import settings 

6 

7 

8class UserProfile(BaseModel): 

9 id: str = Field(..., description="User ID") 

10 first_name: str = Field(..., description="First name") 

11 last_name: str = Field(..., description="Last name") 

12 email: EmailStr = Field(..., description="User email address") 

13 pending_email: EmailStr | None = Field(None, description="Pending email awaiting verification") 

14 phone: str = Field(..., description="Phone number") 

15 status: bool = Field(..., description="User status") 

16 created_at: datetime = Field(..., description="User creation time") 

17 

18 

19class UserUpdate(BaseModel): 

20 first_name: str | None = Field(None, min_length=1, max_length=50, description="First name") 

21 last_name: str | None = Field(None, min_length=1, max_length=50, description="Last name") 

22 email: EmailStr | None = Field(None, description="User email address") 

23 phone: str | None = Field(None, min_length=1, max_length=20, description="Phone number") 

24 

25 

26class PasswordChange(BaseModel): 

27 current_password: str = Field( 

28 ..., min_length=settings.PASSWORD_MIN_LENGTH, max_length=50, description="Current password" 

29 ) 

30 new_password: str = Field( 

31 ..., min_length=settings.PASSWORD_MIN_LENGTH, max_length=50, description="New password" 

32 ) 

33 logout_other_devices: bool = Field(True, description="Logout other devices") 

34 

35 @model_validator(mode="before") 

36 @classmethod 

37 def migrate_legacy_logout_field(cls, data): 

38 if ( 

39 isinstance(data, dict) 

40 and "logout_other_devices" not in data 

41 and "logout_all_devices" in data 

42 ): 

43 data = data.copy() 

44 data["logout_other_devices"] = data.pop("logout_all_devices") 

45 return data