Files
blog.pyaqa.ru/tests/unit/infrastructure/test_transaction_manager.py
Sergey Vanyushkin ce2c052684
Some checks failed
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/type Pipeline failed
feat(tests): increase test coverage from 68% to 78%
Add comprehensive integration and API tests:
- Integration tests for SQLAlchemyPostRepository (34 tests)
- API tests for posts endpoints and error handlers (22 tests)
- Unit tests for PublishPostUseCase and ListPostsUseCase
- Unit tests for SessionTransactionManager

Also register generic exception handler in error_handler.py

All 167 tests pass, coverage now meets CI threshold of 70%
2026-05-02 18:40:29 +03:00

47 lines
1.3 KiB
Python

"""Tests for DI transaction manager.
Tests SessionTransactionManager implementation.
"""
from unittest.mock import AsyncMock, MagicMock
import pytest
from sqlalchemy.ext.asyncio import AsyncSession
from app.infrastructure.di.transaction_manager import SessionTransactionManager
@pytest.fixture
def mock_session() -> MagicMock:
"""Create mock async session."""
session = MagicMock(spec=AsyncSession)
session.commit = AsyncMock()
session.rollback = AsyncMock()
return session
@pytest.fixture
def transaction_manager(mock_session: MagicMock) -> SessionTransactionManager:
"""Create transaction manager with mock session."""
return SessionTransactionManager(mock_session)
class TestSessionTransactionManager:
"""Test suite for SessionTransactionManager."""
async def test_commit(
self, transaction_manager: SessionTransactionManager, mock_session: MagicMock
) -> None:
"""Test commit calls session commit."""
await transaction_manager.commit()
mock_session.commit.assert_called_once()
async def test_rollback(
self, transaction_manager: SessionTransactionManager, mock_session: MagicMock
) -> None:
"""Test rollback calls session rollback."""
await transaction_manager.rollback()
mock_session.rollback.assert_called_once()