Skip to content

Conversation

@NFUChen
Copy link
Contributor

@NFUChen NFUChen commented Jan 8, 2025

Refactor Logging and Enhance CRUD Repository with Tests

Summary

This PR introduces key updates to logging levels, CRUD repository methods, and test coverage for the py_spring_model module. The changes aim to improve logging granularity, enhance method functionality, and provide comprehensive test coverage to ensure code reliability.


Changes Made

  1. Logging Improvements:

    • Adjusted logging levels in PySpringModel from info to debug for better control over verbosity in managed session operations:
      • Session commit, close, and instance refresh messages.
  2. CRUD Repository Enhancements:

    • Fixed _find_by_query method to correctly unpack and return results.
    • Refined batch deletion methods:
      • delete_all: Uses a SELECT query to fetch entities for deletion.
      • delete_all_by_ids: Handles entity deletion by ID with a bulk query.
    • Improved error handling for cases where no entities are found during delete operations.
  3. Test Suite Addition:

    • Added a new test file: tests/test_crud_repository.py.
    • Test cases include:
      • find_by_id, find_all, and find_by_query.
      • delete, delete_by_id, delete_all, and delete_all_by_ids.
      • upsert functionality for both existing and new entities.
    • Utilized an in-memory SQLite database for isolated and repeatable tests.

Benefits

  • Improved Debugging: Developers can now use debug-level logs to trace session lifecycle events without cluttering the info log level.
  • Enhanced Code Reliability: Fixed and improved CRUD methods to handle edge cases more robustly.
  • Comprehensive Testing: New test suite ensures the repository behaves as expected across various scenarios.

How to Test

  1. Run the test suite using pytest:
    pytest tests/test_crud_repository.py
  2. Confirm all tests pass successfully.
  3. Inspect logs during test runs to validate the updated logging levels.
…methods - Updated logging levels from `info` to `debug` in `PySpringModel` for managed session operations. - Fixed return handling for `_find_by_query` in `CrudRepository` to properly unpack results. - Enhanced `delete_all` and `delete_all_by_ids` methods to handle batch deletions efficiently by selecting and deleting entities in bulk. - Added a comprehensive test suite (`test_crud_repository.py`) to cover CRUD repository functionalities: - Tests for find, delete, delete_all, delete_by_id, and upsert operations. - Ensures robust coverage for entity creation, updating, and removal scenarios.
@NFUChen NFUChen merged commit e657a52 into main Jan 8, 2025
@NFUChen NFUChen deleted the bugfix-crud-repository branch January 8, 2025 10:49
@NFUChen NFUChen self-assigned this Jan 8, 2025
@NFUChen NFUChen added the bug Something isn't working label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

3 participants