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%
This commit is contained in:
46
tests/unit/infrastructure/test_transaction_manager.py
Normal file
46
tests/unit/infrastructure/test_transaction_manager.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""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()
|
||||
Reference in New Issue
Block a user