mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-21 04:39:06 +00:00
fix: Complete major SQLAlchemy 2.0 test migration
Fixed multiple test files for SQLAlchemy 2.0 compatibility: - test_search.py: Fixed query syntax and session parameters - test_room_ics.py: Added session parameter to all controller calls - test_ics_background_tasks.py: Fixed imports and query patterns - test_cleanup.py: Fixed model fields and session handling - test_calendar_event.py: Improved session fixture usage - calendar_events.py: Added commits for test compatibility - rooms.py: Fixed result parsing for scalars().all() - worker/cleanup.py: Added session parameter to remove_by_id Results: 116 tests now passing (up from 107), 29 failures (down from 38) Remaining issues are primarily async event loop isolation problems
This commit is contained in:
@@ -126,11 +126,21 @@ async def setup_database(postgres_service):
|
||||
@pytest.fixture
|
||||
async def session(setup_database):
|
||||
"""Provide a transactional database session for tests"""
|
||||
import sqlalchemy.exc
|
||||
|
||||
from reflector.db import get_session_factory
|
||||
|
||||
async with get_session_factory()() as session:
|
||||
yield session
|
||||
await session.rollback()
|
||||
# Start a transaction that we'll rollback at the end
|
||||
transaction = await session.begin()
|
||||
try:
|
||||
yield session
|
||||
finally:
|
||||
try:
|
||||
await transaction.rollback()
|
||||
except sqlalchemy.exc.ResourceClosedError:
|
||||
# Transaction was already closed (e.g., by a commit), ignore
|
||||
pass
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
Reference in New Issue
Block a user