Skip to content

Conversation

@NFUChen
Copy link
Contributor

@NFUChen NFUChen commented Jan 8, 2025

feat: Enhance _MetodQueryBuilder with validation and tests, and improve type hinting in PySpringModel


Description:

This pull request introduces key enhancements and new features for the PySpringModel framework.

Changes in _MetodQueryBuilder:

  • Validation: Ensures method names start with one of the following prefixes: get_by, find_by, find_all_by, or get_all_by. Invalid prefixes raise a ValueError with a detailed error message.
  • Error Handling: Handles cases with missing or invalid patterns gracefully.
  • Unit Tests:
    • Added a new test suite: test_method_query_builder.py.
    • Includes parameterized tests for valid method names and expected outputs.
    • Tests edge cases, such as invalid and empty method names, with proper validation of error messages.

Changes in PySpringModel:

  • Self Type Hint: Updated the clone method to use the Self type hint, enabling better type inference for inherited classes.
  • Enhanced Error Handling: Improved error messages in get_primary_key_columns when the table is not found in metadata.

Key Commits:

  1. feat(PySpringModel)

    • Add Self type hint for clone.
    • Enhance error handling in get_primary_key_columns.
    • Comprehensive unit tests for PySpringModel functionality.
  2. refactor&test(_MetodQueryBuilder)

    • Add validation for method names.
    • New test suite: test_method_query_builder.py.
  3. chore

    • Added a test for _find_all_by_query.
…or handling - Updated the `clone` method in `PySpringModel` to use the `Self` type hint for better type inference in subclasses. - Enhanced `get_primary_key_columns` to raise a clear error if the table is not found in metadata. - Added comprehensive tests for `PySpringModel` in `tests/test_py_spring_model.py` to verify engine, metadata, connection, and session management functionalities, as well as model cloning.
…ueryBuilder` - Added validation in `_MetodQueryBuilder` to ensure the method name starts with one of the following prefixes: `get_by`, `find_by`, `find_all_by`, or `get_all_by`. Raises a `ValueError` if the prefix is invalid. - Updated `parse_query` method to handle cases where no valid pattern is matched. - Introduced a new test suite `test_method_query_builder.py` to validate `_MetodQueryBuilder` functionality. - Includes parameterized tests for valid method names and their expected outputs. - Tests for invalid method names and empty method names to ensure proper error handling. - Validates that the correct error messages are raised for invalid inputs.
@NFUChen NFUChen merged commit 28a1284 into main Jan 8, 2025
1 check passed
@NFUChen NFUChen self-assigned this Jan 8, 2025
@NFUChen NFUChen added the test Add tests label Jan 8, 2025
@NFUChen NFUChen deleted the feat/self-type-hint-clone branch January 8, 2025 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test Add tests

3 participants