-
Notifications
You must be signed in to change notification settings - Fork 214
Convert to Using Decimal and Fix Related Test #356
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
Modified imports and removed unused json imports Modified calls to set use_decimal for serialization/deserialization
tests/unit/test_client.py
Outdated
| def content(self): | ||
| return '' | ||
|
|
||
| class MockResponseSimpleJson: |
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.
I was not sure why MockResponse had set the text field in the way that it did, so I created my own mock object that replaces it for the test that needed text to provide a valid json string.
| from ..client import QuickBooks | ||
| from .creditcardpayment import CreditCardPayment | ||
| from ..mixins import DeleteMixin, VoidMixin | ||
| import json |
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.
unused import
Put the decode on the test, removed the name for clarity
|
Added toggle to enable the decoding to decimals as per @justmobilize suggestion |
This pull request changes the datatype returned from the library to Decimal where floats are returned in the current version.
Rationale:
Using Decimal ensures precise handling of financial data, which is critical for the integrity of financial applications. The json library provides support through parse_float on decode and a helper cls for encoding. I have used a monkeypatched version and decided to contribute a clean version upstream. Here is what I did:
Convert to Using Decimal with json:
UPDATE:
Changed json parsing and added a decimaldecorder helper to seamlessly convert into and out of Decimal type when encoding an decoding json.
Update Tests:
Modified the existing tests to align with the changes introduced.
Specifically, fixed the test_make_request to ensure compatibility with handling of Decimal.
Changes Made:
Test Fix:
Testing:
Manual Testing: Conducted manual testing to ensure that the changes do not introduce any regressions.
Additional Notes:
Backward Compatibility: This change could break other projects that expect the amounts to be in floats, expecially if they are serializing the data. In general, however, Decimals work almost everywhere in python where floats work and I think anyone doing maths for currencies have, like me, been converting to Decimal all along anyway.
Documentation: No changes have been made yet I wanted to get feedback first before investing more time.