Add tests for authentication and utilities, and update dependencies

- Created a new test package for services and added tests for AuthService.
- Implemented tests for user registration, login, and token creation.
- Added a new test package for utilities and included tests for password and JWT utilities.
- Updated `uv.lock` to include new dependencies: bcrypt, email-validator, pyjwt, and pytest-asyncio.
This commit is contained in:
JSC
2025-07-25 17:48:43 +02:00
parent af20bc8724
commit e456d34897
23 changed files with 2381 additions and 8 deletions

53
app/schemas/auth.py Normal file
View File

@@ -0,0 +1,53 @@
"""Authentication schemas."""
from datetime import datetime
from typing import Any
from pydantic import BaseModel, EmailStr, Field
class UserRegisterRequest(BaseModel):
"""Schema for user registration request."""
email: EmailStr = Field(..., description="User email address")
password: str = Field(
..., min_length=8, description="User password (minimum 8 characters)",
)
name: str = Field(..., min_length=1, max_length=100, description="User full name")
class UserLoginRequest(BaseModel):
"""Schema for user login request."""
email: EmailStr = Field(..., description="User email address")
password: str = Field(..., description="User password")
class TokenResponse(BaseModel):
"""Schema for authentication token response."""
access_token: str = Field(..., description="JWT access token")
token_type: str = Field(default="bearer", description="Token type")
expires_in: int = Field(..., description="Token expiration time in seconds")
class UserResponse(BaseModel):
"""Schema for user information response."""
id: int = Field(..., description="User ID")
email: str = Field(..., description="User email address")
name: str = Field(..., description="User full name")
picture: str | None = Field(None, description="User profile picture URL")
role: str = Field(..., description="User role")
credits: int = Field(..., description="User credits")
is_active: bool = Field(..., description="Whether user is active")
plan: dict[str, Any] = Field(..., description="User plan information")
created_at: datetime = Field(..., description="User creation timestamp")
updated_at: datetime = Field(..., description="User last update timestamp")
class AuthResponse(BaseModel):
"""Schema for authentication response."""
user: UserResponse = Field(..., description="User information")
token: TokenResponse = Field(..., description="Authentication token")