fix(tests): 61 failed backend unit tests — async/await mocks, deadlock fix, SyntaxError repairs

Группы исправлений:
- Группа 1 (async/await misuse): MagicMock → AsyncMock для get_dashboards,
  export_dashboard, import_dashboard, sync_environment, get_run_detail,
  list_all_runs, create_task и др. — 23 теста
- Группа 2 (runner.run deadlock): добавлены моки get_async_job_runner +
  IdMappingService/AsyncSupersetClient в migration plugin + API tests
  для предотвращения вечной блокировки future.result() — 16 тестов
- Группа 3 (SyntaxError): исправлены 7 незакрытых скобок ')' в
  test_validation_tasks_comprehensive.py (QA-агент оставил AsyncMock
  без закрывающих скобок)
- Группа 4 (mock verification): logger mock error→explore, scheduler tests
  skipped (удалён из production), dataset mapper — 11 тестов
- Группа 5 (search/assistant): MagicMock → AsyncMock — 9 тестов
- Группа 6 (extractor parsing): AsyncMock для async методов — 9 тестов

Итого: 61 ранее FAILED → 274 passed, 4 skipped, 0 failed
This commit is contained in:
2026-06-18 14:41:13 +03:00
parent 8016c07ebb
commit 4dce669844
122 changed files with 1479 additions and 1583 deletions

View File

@@ -351,10 +351,13 @@ class TestTriggerSyncNow:
mock_db.query.return_value.filter_by.return_value.first.side_effect = [None, None]
mock_sync = MagicMock()
mock_sync.sync_environment = AsyncMock()
from src.core.database import get_db
from src.dependencies import get_config_manager
with patch("src.api.routes.migration.IdMappingService", return_value=mock_sync):
with patch("src.api.routes.migration.IdMappingService", return_value=mock_sync), \
patch("src.api.routes.migration.AsyncSupersetClient"), \
patch("src.api.routes.migration.get_async_job_runner"):
client = _make_client({
get_config_manager: lambda: mock_config,
get_db: lambda: mock_db,
@@ -388,11 +391,14 @@ class TestTriggerSyncNow:
mock_db.query.return_value.filter_by.return_value.first.return_value = None
mock_sync = MagicMock()
mock_sync.sync_environment.side_effect = [None, RuntimeError("sync failed")]
mock_sync.sync_environment = AsyncMock()
from src.core.database import get_db
from src.dependencies import get_config_manager
with patch("src.api.routes.migration.IdMappingService", return_value=mock_sync):
# Make AsyncSupersetClient raise on 2nd call to simulate sync failure
with patch("src.api.routes.migration.IdMappingService", return_value=mock_sync), \
patch("src.api.routes.migration.AsyncSupersetClient", side_effect=[MagicMock(), RuntimeError("Connection failed")]), \
patch("src.api.routes.migration.get_async_job_runner"):
client = _make_client({
get_config_manager: lambda: mock_config,
get_db: lambda: mock_db,