mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add currency formatting test
This commit is contained in:
parent
eec82b52ee
commit
9fdf44f495
@ -330,6 +330,33 @@ class FormatTest(TestCase):
|
||||
"PO-###-{test}",
|
||||
)
|
||||
|
||||
def test_currency_formatting(self):
|
||||
"""Test that currency formatting works correctly for multiple currencies"""
|
||||
|
||||
test_data = (
|
||||
(Money( 3651.285718, "USD"), 4, "$3,651.2857" ), # noqa: E201,E202
|
||||
(Money(487587.849178, "CAD"), 5, "CA$487,587.84918"), # noqa: E201,E202
|
||||
(Money( 0.348102, "EUR"), 1, "€0.3" ), # noqa: E201,E202
|
||||
(Money( 0.916530, "GBP"), 1, "£0.9" ), # noqa: E201,E202
|
||||
(Money( 61.031024, "JPY"), 3, "¥61.031" ), # noqa: E201,E202
|
||||
(Money( 49609.694602, "JPY"), 1, "¥49,609.7" ), # noqa: E201,E202
|
||||
(Money(155565.264777, "AUD"), 2, "A$155,565.26" ), # noqa: E201,E202
|
||||
(Money( 0.820437, "CNY"), 4, "CN¥0.8204" ), # noqa: E201,E202
|
||||
(Money( 7587.849178, "EUR"), 0, "€7,588" ), # noqa: E201,E202
|
||||
(Money( 0.348102, "GBP"), 3, "£0.348" ), # noqa: E201,E202
|
||||
(Money( 0.652923, "CHF"), 0, "CHF1" ), # noqa: E201,E202
|
||||
(Money( 0.820437, "CNY"), 1, "CN¥0.8" ), # noqa: E201,E202
|
||||
(Money(98789.5295680, "CHF"), 0, "CHF98,790" ), # noqa: E201,E202
|
||||
(Money( 0.585787, "USD"), 1, "$0.6" ), # noqa: E201,E202
|
||||
(Money( 0.690541, "CAD"), 3, "CA$0.691" ), # noqa: E201,E202
|
||||
(Money( 427.814104, "AUD"), 5, "A$427.81410" ), # noqa: E201,E202
|
||||
)
|
||||
|
||||
with self.settings(LANGUAGE_CODE="en-us"):
|
||||
for value, decimal_places, expected_result in test_data:
|
||||
result = InvenTree.format.format_money(value, decimal_places=decimal_places)
|
||||
assert result == expected_result
|
||||
|
||||
|
||||
class TestHelpers(TestCase):
|
||||
"""Tests for InvenTree helper functions."""
|
||||
|
Loading…
Reference in New Issue
Block a user