chore: eliminate all deprecation warnings from tests and linter

Warnings fixed:
- datetime.utcnow() → datetime.now(UTC) across 48+ files (src/ + tests/)
- datetime.utcnow (callback ref) → lambda: datetime.now(UTC) in model fields (18 files)
- Pydantic class Config → model_config = ConfigDict(...) (16 files)
- Pydantic .dict() → .model_dump() (8 files)
- ConfigDict(allow_population_by_field_name=True) → validate_by_name=True
- SQLAlchemy declarative_base() import path updated
- FastAPI on_event → lifespan context manager (app.py)
- Import sorting (ruff I001) auto-fixed across all files
- Fixed broken re-export chains that ruff F401 cleanup broke:
  _validate_bcp47: service.py now imports from dictionary_validation directly
  job_to_response: _job_routes.py and test imports from service_utils directly
  fetch_datasource_metadata: restored re-export in service.py
- Added missing TranslateJobService import in _job_routes.py (was deleted by F401)
- Added ConfigDict(protected_namespaces=()) for DashboardDatasetItem schema field
- pytest.ini: replaced deprecated importmode with asyncio_mode

All 440 tests pass with zero deprecation warnings.
This commit is contained in:
2026-05-26 19:18:28 +03:00
parent 65340c079e
commit 54779a636a
181 changed files with 779 additions and 897 deletions

View File

@@ -7,13 +7,10 @@
# @TEST_EDGE: revoked_key_delete -> 404
# @TEST_EDGE: missing_name -> 422
# @TEST_EDGE: missing_permissions -> 422
import json
import sys
from datetime import datetime, timezone, timedelta
from unittest.mock import MagicMock, patch
import pytest
from fastapi import status
import sys
from unittest.mock import MagicMock
from fastapi.testclient import TestClient
# Patch GitService at module level to prevent /app/storage/repositories error
@@ -34,8 +31,8 @@ def client():
def _mock_admin_auth():
"""Apply dependency overrides for admin authentication."""
from src.dependencies import get_current_user
from src.app import app
from src.dependencies import get_current_user
mock_role = MagicMock()
mock_role.name = "Admin"
@@ -69,9 +66,10 @@ def mock_db():
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.pool import StaticPool
from src.models.mapping import Base
from src.dependencies import get_db
from src.app import app
from src.dependencies import get_db
from src.models.mapping import Base
engine = create_engine(
"sqlite:///:memory:",
@@ -113,8 +111,8 @@ class TestListApiKeys:
# #region test_list_with_keys [C:2] [TYPE Function]
# @BRIEF Keys exist → returns list without raw_key or key_hash fields.
def test_list_with_keys(self, client, mock_db):
from src.models.api_key import APIKey
from src.core.auth.api_key import generate_api_key
from src.models.api_key import APIKey
# Create a key
raw, prefix, key_hash = generate_api_key()
@@ -203,8 +201,8 @@ class TestRevokeApiKey:
# #region test_revoke_valid [C:2] [TYPE Function]
# @BRIEF Revoke existing active key → 200 with status=revoked.
def test_revoke_valid(self, client, mock_db):
from src.models.api_key import APIKey
from src.core.auth.api_key import generate_api_key
from src.models.api_key import APIKey
raw, prefix, key_hash = generate_api_key()
api_key = APIKey(
@@ -231,8 +229,8 @@ class TestRevokeApiKey:
# #region test_revoke_already_revoked [C:2] [TYPE Function]
# @BRIEF Revoke already revoked key → 404.
def test_revoke_already_revoked(self, client, mock_db):
from src.models.api_key import APIKey
from src.core.auth.api_key import generate_api_key
from src.models.api_key import APIKey
raw, prefix, key_hash = generate_api_key()
api_key = APIKey(