-
Notifications
You must be signed in to change notification settings - Fork 37
Add account_id parameter to get_balances method for single account filtering #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: dasco144 <10575019+dasco144@users.noreply.github.com>
|
WalkthroughThe Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Assessment against linked issues
Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
luno_python/client.py (1)
171-173: Update type annotation to reflect actual implementation.The type annotation specifies
strbut the implementation handles both string and integer values throughstr()conversion on line 184. Consider updating to indicate this flexibility.- :param account_id: Only return balance for the account with this ID. If provided, - returns a single account object instead of the full response. - :type account_id: str + :param account_id: Only return balance for the account with this ID. If provided, + returns a single account object instead of the full response. + Accepts both string and integer values. + :type account_id: Union[str, int]
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
luno_python/client.py(2 hunks)tests/test_client.py(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
tests/test_client.py (2)
luno_python/client.py (1)
get_balances(159-190)luno_python/base_client.py (1)
set_base_url(45-52)
luno_python/client.py (1)
luno_python/base_client.py (1)
do(63-89)
🔇 Additional comments (9)
luno_python/client.py (2)
159-159: LGTM! Method signature enhancement maintains backward compatibility.The addition of the optional
account_idparameter is well-designed and preserves existing functionality.
180-190: Excellent client-side filtering implementation.The filtering logic is robust:
- Handles missing 'balance' key gracefully
- Uses string conversion for type-agnostic comparison
- Returns
Nonefor non-existent account IDs- Maintains backward compatibility when
account_idis not specifiedtests/test_client.py (7)
53-77: Excellent backward compatibility test coverage.This test properly verifies that existing calls without
account_idcontinue to work as before, returning the full API response.
79-107: Comprehensive testing of the core filtering functionality.Well-structured test that validates both positive cases with different account IDs. The assertions properly verify the filtered response matches expected single account objects.
109-130: Good coverage of error condition handling.This test correctly verifies that non-existent account IDs return
None, which matches the expected behaviour described in the PR objectives.
132-154: Validates combined parameter usage effectively.This test ensures that the
account_idfiltering works correctly when combined with the existingassetsparameter, demonstrating proper integration.
156-178: Excellent type conversion testing.This test validates the robust string conversion logic in the implementation, ensuring compatibility when the API returns integer account IDs but string values are provided as input.
180-200: Thorough edge case coverage for empty responses.Good validation that empty balance arrays are handled correctly - returning
Nonewhen filtering by account ID, but preserving the original response structure for backward compatibility.
202-222: Robust malformed response handling.This test ensures graceful degradation when the API response lacks the expected
balancekey, maintaining backward compatibility while properly handling the filtering case.
echarrod
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM


This PR adds an optional
account_idparameter to theget_balances()method, allowing users to retrieve balance information for a specific account instead of all accounts.Changes
get_balances()method: Added optionalaccount_idparameter that filters the API response to return only the specified accountaccount_idcontinue to work exactly as beforeNonewhen the specified account ID is not foundUsage
Implementation Details
The implementation uses client-side filtering of the API response rather than modifying the API call itself. This ensures:
Testing
Added comprehensive test coverage including:
Fixes #25.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.
Summary by CodeRabbit
New Features
Tests