Skip to content

Commit

Permalink
Make money formatting test locale independent
Browse files Browse the repository at this point in the history
  • Loading branch information
WojtekMs committed Feb 9, 2024
1 parent 057e99c commit 0d8cee2
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tests/banker/formatter/test_html_transactions_formatter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest
from moneyed import format_money

from banker.common.locale import get_numeric_locale
from banker.formatter.html_transactions_formatter import HtmlTransactionsFormatter


Expand Down Expand Up @@ -31,9 +33,8 @@ def test_given_empty_transactions_when_format_transactions_then_return_empty_tab

def test_given_transactions_when_format_transactions_then_return_html_table_with_headers_and_rows(
html_transactions_formatter_sut, transaction1, transaction2):
html_hard_space = "\xa0"
expected_transaction_1_value = f"-37,35{html_hard_space}zł"
expected_transaction_2_value = f"-200,00{html_hard_space}zł"
expected_transaction_1_value = format_money(transaction1.value, locale=get_numeric_locale())
expected_transaction_2_value = format_money(transaction2.value, locale=get_numeric_locale())
expected_result = ('<table border="1" class="dataframe">\n'
' <thead>\n'
' <tr style="text-align: right;">\n'
Expand Down Expand Up @@ -65,3 +66,8 @@ def test_given_transactions_when_format_transactions_then_return_html_table_with
actual_result = html_transactions_formatter_sut.format_transactions([transaction1, transaction2])

assert actual_result == expected_result
# exact format is dependent on locale; try to make tests locale-independent
assert "37" in expected_transaction_1_value
assert "-" in expected_transaction_1_value
assert "200" in expected_transaction_2_value
assert "-" in expected_transaction_2_value

0 comments on commit 0d8cee2

Please sign in to comment.