Skip to content

Increase test coverage for undertested modules#12

Merged
vladiant merged 6 commits into
mainfrom
increase_test_coverage
Apr 2, 2026
Merged

Increase test coverage for undertested modules#12
vladiant merged 6 commits into
mainfrom
increase_test_coverage

Conversation

@vladiant
Copy link
Copy Markdown
Collaborator

@vladiant vladiant commented Apr 2, 2026

Summary

Adds 48 new tests targeting four modules that previously had low coverage: PostgresImageRepository (23%), ListImagesUseCase (64%), PillowImageProcessor sync workers (67%), and main.py lifespan (69%). All four modules now reach 100% coverage. Overall test count goes from 168 to 216.

Changes

Added

  • test_postgres_image_repository.py (28 tests)
    SQLite-backed integration tests for PostgresImageRepository. Exercises all 8 repository methods (save, get_by_id, list_images, delete, get_expired, delete_expired_batch, count) with real SQL queries and ORM mapping round-trips, using aiosqlite (already a dev dependency). PostgreSQL-specific column types (UUID, ARRAY) are swapped to SQLite equivalents at fixture time.

  • test_list_images.py (5 tests)
    Unit tests for ListImagesUseCase covering empty results, response mapping (metadata/thumbnail), pagination parameter forwarding, status filter forwarding, and total-vs-page-size distinction.

  • test_pillow_processor.py (12 new tests)
    Direct in-process tests for _generate_thumbnail_sync (aspect ratio, RGBA, small images, JPEG format, corrupt data) and _extract_metadata_sync (RGB/RGBA/grayscale, corrupt data), plus shutdown_executor lifecycle tests. These functions previously ran only in ProcessPoolExecutor child processes invisible to the coverage collector.

  • test_lifespan.py (3 tests)
    Integration tests for the FastAPI lifespan async context manager: startup table creation, shutdown cleanup (engine.dispose, shutdown_executor), and log message verification.

Fixed

  • Replaced deprecated HTTP_422_UNPROCESSABLE_ENTITY with HTTP_422_UNPROCESSABLE_CONTENT in the upload validation error response.

Coverage impact

Module Before After
postgres_image_repository.py 23% 100%
list_images.py 64% 100%
pillow_processor.py 67% 100%
main.py 69% 100%
Overall 96%

Version

PATCH bump: 2.0.12.0.2

Checklist

  • ruff check — no issues
  • mypy src/ — no issues
  • pytest — 216 passed
  • CHANGELOG.md updated
  • Version bumped in pyproject.toml
  • No source logic changes (tests only + deprecation fix)

@vladiant vladiant merged commit d8c75e2 into main Apr 2, 2026
4 checks passed
@vladiant vladiant deleted the increase_test_coverage branch April 2, 2026 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant