def formatted_price_local(self): if self.price_local: return format_currency(settings.LOCAL_CURRENCY, self.price_local, symbol=True, grouping=True, international=False)
def formatted_price_usd(self): if self.price_usd: return format_currency('USD', self.price_usd, symbol=True, grouping=True, international=False)
def test_format_currency(self): # Test that our format_currency works the same as the built-in python locale.currency. # This doesn't provide complete coverage of the formatting code - we'd need to # use more currencies that have different formatting rules to do that - but this # should be good enough to make sure we're basically running it the same, and # we didn't really change that much of it anyway. val = 1.47 for currency_code in currencies.keys(): for symbol in [False, True]: for grouping in [False, True]: for international in [False, True]: our_output = format_currency(currency_code, val, symbol, grouping, international) with patch('locale.localeconv') as mock_localeconv: mock_localeconv.return_value = currencies[ currency_code] built_in_output = locale.currency( val, symbol, grouping, international) self.assertEqual( built_in_output, our_output, msg= "Failure: Built-in returned %s, our code returned %s, for currency" " %s symbol %s grouping %s international %s" % (built_in_output, our_output, currency_code, symbol, grouping, international))
def test_format_currency(self): # Test that our format_currency works the same as the built-in python locale.currency. # This doesn't provide complete coverage of the formatting code - we'd need to # use more currencies that have different formatting rules to do that - but this # should be good enough to make sure we're basically running it the same, and # we didn't really change that much of it anyway. val = 1.47 for currency_code in currencies.keys(): for symbol in [False, True]: for grouping in [False, True]: for international in [False, True]: our_output = format_currency(currency_code, val, symbol, grouping, international) with patch('locale.localeconv') as mock_localeconv: mock_localeconv.return_value = currencies[currency_code] built_in_output = locale.currency(val, symbol, grouping, international) self.assertEqual( built_in_output, our_output, msg="Failure: Built-in returned %s, our code returned %s, for currency" " %s symbol %s grouping %s international %s" % (built_in_output, our_output, currency_code, symbol, grouping, international))
def render(self, value): currency_code = "USD" return format_currency(currency_code, value)
def render(self, value): currency_code = settings.LOCAL_CURRENCY return format_currency(currency_code, value)