- Add missing src/server/api/__init__.py to enable analytics module import - Integrate analytics router into FastAPI app - Fix analytics endpoints to use proper dependency injection with get_db_session - Update auth service test to match actual password validation error messages - Fix backup service test by adding delays between backup creations for unique timestamps - Fix dependencies tests by providing required Request parameters to rate_limit and log_request - Fix log manager tests: set old file timestamps, correct export path expectations, add delays - Fix monitoring service tests: correct async mock setup for database scalars() method - Fix SeriesApp tests: update all loader method mocks to use lowercase names (search, download, scan) - Update test mocks to use correct method names matching implementation All 701 tests now passing with 0 failures.
47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
from datetime import datetime, timedelta
|
|
|
|
import pytest
|
|
|
|
from src.server.models.auth import (
|
|
AuthStatus,
|
|
LoginRequest,
|
|
LoginResponse,
|
|
SessionModel,
|
|
SetupRequest,
|
|
)
|
|
|
|
|
|
def test_login_request_validation():
|
|
# password is required
|
|
with pytest.raises(ValueError):
|
|
LoginRequest(password="")
|
|
|
|
req = LoginRequest(password="hunter2", remember=True)
|
|
assert req.password == "hunter2"
|
|
assert req.remember is True
|
|
|
|
|
|
def test_setup_request_requires_min_length():
|
|
with pytest.raises(ValueError):
|
|
SetupRequest(master_password="short")
|
|
|
|
good = SetupRequest(master_password="longenoughpassword")
|
|
assert good.master_password == "longenoughpassword"
|
|
|
|
|
|
def test_login_response_and_session_model():
|
|
expires = datetime.utcnow() + timedelta(hours=1)
|
|
lr = LoginResponse(access_token="tok", expires_at=expires)
|
|
assert lr.token_type == "bearer"
|
|
assert lr.access_token == "tok"
|
|
|
|
s = SessionModel(session_id="abc123", user="admin", expires_at=expires)
|
|
assert s.session_id == "abc123"
|
|
assert s.user == "admin"
|
|
|
|
|
|
def test_auth_status_defaults():
|
|
status = AuthStatus(configured=False, authenticated=False)
|
|
assert status.configured is False
|
|
assert status.authenticated is False
|