Skip to content

Add comprehensive test suite for unified RecordType enum and fix falsy value bug#89

Closed
Copilot wants to merge 4 commits intomasterfrom
copilot/add-unified-recordtype-enum
Closed

Add comprehensive test suite for unified RecordType enum and fix falsy value bug#89
Copilot wants to merge 4 commits intomasterfrom
copilot/add-unified-recordtype-enum

Conversation

Copy link
Contributor

Copilot AI commented Dec 18, 2025

This PR adds comprehensive tests for the unified RecordType enum that was introduced in PR #87. The RecordType enum provides a consistent way to handle asset record types across the SDK, supporting both integer codes and string values from API responses.

Changes Made

  • Test Suite: Created tests/test_record_type.py with 24 comprehensive tests covering:

    • Enum values and string representation
    • API value parsing with integer codes (0-3 mapping to enum values)
    • API value parsing with string values (case-insensitive matching)
    • Whitespace handling in string values
    • Error handling for None and invalid values
    • Backward compatibility with deprecated enum names (AssetToAssetManageResponseModelRecordType and AssetToClientAssetManagerResponseModelRecordType)
    • Model-level integration tests for AssetToAssetManageResponseModel with integer and string RecordType values
    • Model-level integration tests for AssetToClientAssetManagerResponseModel with integer and string RecordType values
    • Critical test ensuring RecordType value 0 (WAITING_FOR_AGREEMENT) is not treated as falsy
  • Bug Fix: Fixed a critical bug in AssetToAssetManageResponseModel and AssetToClientAssetManagerResponseModel where if not _record_type: incorrectly treated integer value 0 as falsy, preventing WAITING_FOR_AGREEMENT (value 0) from being parsed correctly. Changed to explicit if _record_type is None: check in both models.

Testing

  • ✅ All 24 tests pass successfully (12 enum-level + 12 integration tests)
  • ✅ Code review completed with no issues
  • ✅ CodeQL security scan completed with 0 alerts
  • ✅ Related tests (test_service_order_status_mapping.py) continue to pass

The test suite ensures the RecordType enum implementation is robust and handles all expected use cases, including edge cases and backward compatibility requirements. The integration tests validate that RecordType works correctly through model deserialization, and successfully caught the falsy value bug.

Original prompt

Please open a new pull request to address these concerns:


@copilot commented on this pull request.

Pull request overview
This PR introduces a unified RecordType enum to replace multiple model-specific record type enums, improving consistency across the codebase. The new enum supports both integer and string API values with flexible parsing.

Key Changes
New RecordType enum with from_api_value method for robust integer/string parsing
Deprecated AssetToAssetManageResponseModelRecordType and AssetToClientAssetManagerResponseModelRecordType with backward compatibility wrappers
Updated asset management response models to use the unified RecordType
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/qualer_sdk/models/record_type.py Introduces the new unified RecordType enum with integer/string value mapping and case-insensitive parsing
src/qualer_sdk/models/qualer_api_models_asset_to_client_asset_manager_response_model_record_type.py Converts to deprecation wrapper that redirects to RecordType with warnings
src/qualer_sdk/models/qualer_api_models_asset_to_asset_manage_response_model_record_type.py Converts to deprecation wrapper that redirects to RecordType with warnings
src/qualer_sdk/models/qualer_api_models_asset_to_client_asset_manager_response_model.py Updates import and type annotations to use RecordType, switches from IntEnum constructor to from_api_value method
src/qualer_sdk/models/qualer_api_models_asset_to_asset_manage_response_model.py Updates import and type annotations to use RecordType, switches from IntEnum constructor to from_api_value method
src/qualer_sdk/models/init.py Adds RecordType to module exports while maintaining deprecated enum exports
In src/qualer_sdk/models/qualer_api_models_asset_to_asset_manage_response_model.py:

     if not _record_type:
         record_type = None
     elif _record_type is None:
         record_type = None

The condition if not _record_type: on line 475 will evaluate to True when _record_type is 0 (the integer code for WAITING_FOR_AGREEMENT), causing valid data to be treated as None. This logic should be changed to explicitly check for None instead of using a truthy check, since 0 is a valid value for the record type.

⬇️ Suggested change

  •    if not _record_type:
    
  •        record_type = None
    
  •    elif _record_type is None:
    
  •        record_type = None
    
  •    if _record_type is None:
    
  •        record_type = None
    

In src/qualer_sdk/models/qualer_api_models_asset_to_client_asset_manager_response_model_record_type.py:

  •    return _RecordType
    
  • raise AttributeError(f"module {name!r} has no attribute {name!r}")

+# For direct import: from module import AssetToClientAssetManagerResponseModelRecordType
+AssetToClientAssetManagerResponseModelRecordType = _RecordType
The module-level assignment AssetToClientAssetManagerResponseModelRecordType = _RecordType does not trigger the deprecation warning for direct imports (e.g., from module import AssetToClientAssetManagerResponseModelRecordType). Only attribute access (e.g., module.AssetToClientAssetManagerResponseModelRecordType) will show the warning due to the getattr implementation. Consider adding a custom class that wraps _RecordType and triggers the warning on instantiation, or document this limitation.

⬇️ Suggested change

  •    return _RecordType
    
  • raise AttributeError(f"module {name!r} has no attribute {name!r}")

-# For direct import: from module import AssetToClientAssetManagerResponseModelRecordType
-AssetToClientAssetManagerResponseModelRecordType = _RecordType

  •    return AssetToClientAssetManagerResponseModelRecordType
    
  • raise AttributeError(f"module {name!r} has no attribute {name!r}")

+class AssetToClientAssetManagerResponseModelRecordType(_RecordType):

  • """
  • Deprecated alias for RecordType used in asset-to-client asset manager responses.
  • This class exists for backward compatibility and will be removed in a future release.
  • Prefer importing and using RecordType directly:
  •    from qualer_sdk.models import RecordType
    
  • """
  • def init(self, *args, **kwargs):
  •    warnings.warn(
    
  •        "AssetToClientAssetManagerResponseModelRecordType is deprecated. "
    
  •        "Use RecordType instead (from qualer_sdk.models import RecordType).",
    
  •        DeprecationWarning,
    
  •        stacklevel=2,
    
  •    )
    
  •    super().__init__(*args, **kwargs)
    

In src/qualer_sdk/models/qualer_api_models_asset_to_asset_manage_response_model_record_type.py:

  •    return _RecordType
    
  • raise AttributeError(f"module {name!r} has no attribute {name!r}")

+# For direct import: from module import AssetToAssetManageResponseModelRecordType
+AssetToAssetManageResponseModelRecordType = _RecordType
The module-level assignment AssetToAssetManageResponseModelRecordType = _RecordType...


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot stopped work on behalf of rhythmatician due to an error December 18, 2025 22:21
@rhythmatician
Copy link
Collaborator

@copilot Try again

Copy link
Contributor Author

Copilot AI commented Dec 18, 2025

@copilot Try again

I've added comprehensive tests for the unified RecordType enum in commit 9cbf552. The test suite covers:

  • Enum values and string representation
  • Parsing integer codes from API responses (0-3)
  • Parsing string values with case-insensitive matching
  • Whitespace handling
  • Invalid value handling
  • Backward compatibility with deprecated enum names

All 12 tests are passing successfully.

Copilot AI changed the title [WIP] Add unified RecordType enum for improved consistency Add comprehensive test suite for unified RecordType enum Dec 18, 2025
Copilot AI requested a review from rhythmatician December 18, 2025 22:42
@rhythmatician rhythmatician force-pushed the copilot/add-unified-recordtype-enum branch from 9cbf552 to 3856586 Compare January 3, 2026 00:07
@rhythmatician rhythmatician marked this pull request as ready for review January 3, 2026 00:07
Copilot AI review requested due to automatic review settings January 3, 2026 00:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a comprehensive test suite for the unified RecordType enum introduced in PR #87, which standardizes asset record type handling across the SDK by supporting both integer codes (0-3) and string values from API responses.

  • Test Suite: Creates 12 tests covering enum functionality, API value parsing, edge cases, and backward compatibility
  • Backward Compatibility: Verifies that deprecated enum names remain accessible for existing code
  • Edge Case Handling: Tests whitespace handling, case-insensitive parsing, and error handling for invalid values

Copilot AI changed the title Add comprehensive test suite for unified RecordType enum Add comprehensive test suite for unified RecordType enum and fix falsy value bug Jan 3, 2026
Copilot AI requested a review from rhythmatician January 3, 2026 00:26
@rhythmatician rhythmatician enabled auto-merge (squash) February 12, 2026 03:23
Copilot AI and others added 3 commits February 11, 2026 22:39
Co-authored-by: rhythmatician <75549255+rhythmatician@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Add integration tests for RecordType with AssetToAssetManageResponseModel
- Add integration tests for RecordType with AssetToClientAssetManagerResponseModel
- Fix bug where RecordType value 0 (WAITING_FOR_AGREEMENT) was treated as falsy
- Tests cover integer/string parsing, zero value handling, and error cases

Co-authored-by: rhythmatician <75549255+rhythmatician@users.noreply.github.com>
@rhythmatician rhythmatician force-pushed the copilot/add-unified-recordtype-enum branch from ff3e6a7 to 016e8b9 Compare February 12, 2026 04:39
auto-merge was automatically disabled February 12, 2026 05:08

Pull request was closed

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.

3 participants