- Updated test cases in `test_auth_endpoints.py` to ensure consistent formatting and style. - Enhanced `test_socket_endpoints.py` with consistent parameter formatting and improved readability. - Cleaned up `conftest.py` by ensuring consistent parameter formatting in fixtures. - Added comprehensive tests for API token dependencies in `test_api_token_dependencies.py`. - Refactored `test_auth_service.py` to maintain consistent parameter formatting. - Cleaned up `test_oauth_service.py` by removing unnecessary imports. - Improved `test_socket_service.py` with consistent formatting and readability. - Enhanced `test_cookies.py` by ensuring consistent formatting and readability. - Introduced new tests for token utilities in `test_token_utils.py` to validate token generation and expiration logic.
80 lines
2.7 KiB
Python
80 lines
2.7 KiB
Python
"""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")
|
|
|
|
|
|
class ApiTokenRequest(BaseModel):
|
|
"""Schema for API token generation request."""
|
|
|
|
expires_days: int = Field(
|
|
default=365,
|
|
ge=1,
|
|
le=3650,
|
|
description="Number of days until token expires (1-3650 days)",
|
|
)
|
|
|
|
|
|
class ApiTokenResponse(BaseModel):
|
|
"""Schema for API token response."""
|
|
|
|
api_token: str = Field(..., description="Generated API token")
|
|
expires_at: datetime = Field(..., description="Token expiration timestamp")
|
|
|
|
|
|
class ApiTokenStatusResponse(BaseModel):
|
|
"""Schema for API token status response."""
|
|
|
|
has_token: bool = Field(..., description="Whether user has an active API token")
|
|
expires_at: datetime | None = Field(None, description="Token expiration timestamp")
|
|
is_expired: bool = Field(..., description="Whether the token is expired")
|