Changes: - Fixed UserResponse schema datetime serialization bug - Fixed test_auth.py mock structure for external auth service - Updated conftest.py to create fresh database per test - Ran full test suite and verified results Test Results: ✅ test_auth.py: 5/5 passing (100%) ✅ test_tasks.py: 4/6 passing (67%) ✅ test_admin.py: 2/4 passing (50%) ❌ test_integration.py: 0/3 passing (0%) Total: 11/18 tests passing (61%) Known Issues: 1. Fixture isolation: test_user sometimes gets admin email 2. Admin API response structure doesn't match test expectations 3. Integration tests need mock fixes Production Bug Fixed: - UserResponse schema now properly serializes datetime fields to ISO format strings 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
75 lines
2.0 KiB
Python
75 lines
2.0 KiB
Python
"""
|
|
Tool_OCR - Authentication Schemas
|
|
"""
|
|
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class LoginRequest(BaseModel):
|
|
"""Login request schema"""
|
|
username: str = Field(..., min_length=3, max_length=50, description="Username")
|
|
password: str = Field(..., min_length=6, description="Password")
|
|
|
|
class Config:
|
|
json_schema_extra = {
|
|
"example": {
|
|
"username": "admin",
|
|
"password": "password123"
|
|
}
|
|
}
|
|
|
|
|
|
class UserInfo(BaseModel):
|
|
"""User information schema"""
|
|
id: int
|
|
email: str
|
|
display_name: Optional[str] = None
|
|
|
|
|
|
class Token(BaseModel):
|
|
"""JWT token response schema"""
|
|
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")
|
|
user: Optional[UserInfo] = Field(None, description="User information (V2 only)")
|
|
|
|
class Config:
|
|
json_schema_extra = {
|
|
"example": {
|
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
|
"token_type": "bearer",
|
|
"expires_in": 3600,
|
|
"user": {
|
|
"id": 1,
|
|
"email": "user@example.com",
|
|
"display_name": "User Name"
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
class TokenData(BaseModel):
|
|
"""Token payload data"""
|
|
user_id: Optional[int] = None
|
|
username: Optional[str] = None
|
|
email: Optional[str] = None
|
|
session_id: Optional[int] = None
|
|
|
|
|
|
class UserResponse(BaseModel):
|
|
"""User response schema"""
|
|
id: int
|
|
email: str
|
|
display_name: Optional[str] = None
|
|
created_at: Optional[datetime] = None
|
|
last_login: Optional[datetime] = None
|
|
is_active: bool = True
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
json_encoders = {
|
|
datetime: lambda v: v.isoformat() if v else None
|
|
}
|