Coverage for src/moai_adk/auth/models.py: 0.00%

14 statements  

« prev     ^ index     » next       coverage.py v7.11.3, created at 2025-11-19 06:02 +0900

1"""User model for authentication module.""" 

2 

3import uuid 

4import time 

5from dataclasses import dataclass 

6from datetime import datetime, timezone 

7 

8 

9@dataclass 

10class User: 

11 """User model for authentication. 

12 

13 Represents a user in the authentication system with unique identifier, 

14 email, hashed password, and creation timestamp. 

15 """ 

16 

17 id: str 

18 email: str 

19 hashed_password: str 

20 created_at: datetime 

21 

22 @classmethod 

23 def create(cls, email: str, hashed_password: str) -> "User": 

24 """Create a new user instance. 

25 

26 Args: 

27 email: User's email address 

28 hashed_password: Already hashed password 

29 

30 Returns: 

31 New User instance with generated UUID and current timestamp 

32 """ 

33 # Use timezone-aware datetime for better compatibility 

34 created_at = datetime.now(timezone.utc) 

35 return cls( 

36 id=str(uuid.uuid4()), 

37 email=email, 

38 hashed_password=hashed_password, 

39 created_at=created_at 

40 ) 

41 

42 def to_dict(self) -> dict: 

43 """Convert user to dictionary representation. 

44 

45 Returns: 

46 Dictionary with user's public information (excluding password) 

47 """ 

48 return { 

49 "id": self.id, 

50 "email": self.email, 

51 "created_at": self.created_at.isoformat() 

52 } 

53 

54 def __repr__(self) -> str: 

55 """String representation of the user.""" 

56 return f"User(id={self.id}, email={self.email}, created_at={self.created_at})"