Complete architectural refactoring from simple MVC to Clean Architecture/DDD pattern: Domain Layer: - Add entities (Post, BaseEntity) with business logic - Add value objects (Title, Content, Slug) with validation - Add repository interfaces (PostRepository) - Add domain exceptions Application Layer: - Add use cases (CreatePost, GetPost, UpdatePost, DeletePost, ListPosts, PublishPost) - Add DTOs for data transfer - Add TransactionManager interface Infrastructure Layer: - Add SQLAlchemy models and async database connection - Add SQLAlchemyPostRepository implementation - Add Dishka DI container with providers - Add error handlers and middleware Presentation Layer: - Add FastAPI routes with Dishka integration - Add Pydantic schemas - Add dependency injection using FromDishka[T] Other Changes: - Remove old flat structure (api/, common/, core/, modules/) - Add hatchling build system for package scripts - Add blog CLI command - Update AGENTS.md with new architecture docs - All 48 tests passing, mypy clean, ruff clean
49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
"""Tests for domain exceptions."""
|
|
|
|
from app.domain.exceptions import (
|
|
AlreadyExistsException,
|
|
DomainException,
|
|
ForbiddenException,
|
|
NotFoundException,
|
|
UnauthorizedException,
|
|
ValidationException,
|
|
)
|
|
|
|
|
|
class TestDomainExceptions:
|
|
def test_base_exception(self) -> None:
|
|
"""Test base domain exception."""
|
|
exc = DomainException("Something went wrong")
|
|
assert exc.message == "Something went wrong"
|
|
assert str(exc) == "Something went wrong"
|
|
|
|
def test_validation_exception(self) -> None:
|
|
"""Test validation exception."""
|
|
exc = ValidationException("Invalid input")
|
|
assert isinstance(exc, DomainException)
|
|
assert exc.message == "Invalid input"
|
|
|
|
def test_not_found_exception(self) -> None:
|
|
"""Test not found exception."""
|
|
exc = NotFoundException("Resource not found")
|
|
assert isinstance(exc, DomainException)
|
|
assert exc.message == "Resource not found"
|
|
|
|
def test_already_exists_exception(self) -> None:
|
|
"""Test already exists exception."""
|
|
exc = AlreadyExistsException("Already exists")
|
|
assert isinstance(exc, DomainException)
|
|
assert exc.message == "Already exists"
|
|
|
|
def test_unauthorized_exception(self) -> None:
|
|
"""Test unauthorized exception."""
|
|
exc = UnauthorizedException("Unauthorized")
|
|
assert isinstance(exc, DomainException)
|
|
assert exc.message == "Unauthorized"
|
|
|
|
def test_forbidden_exception(self) -> None:
|
|
"""Test forbidden exception."""
|
|
exc = ForbiddenException("Forbidden")
|
|
assert isinstance(exc, DomainException)
|
|
assert exc.message == "Forbidden"
|