Add filter for formatting a number as currency

This is used on the usage page, but is likely to become useful in other
places now that letter rates can be greater than £1.
This commit is contained in:
Katie Smith
2020-07-14 14:45:37 +01:00
parent 355e981028
commit 756a17f8db
4 changed files with 30 additions and 10 deletions

View File

@@ -3,7 +3,10 @@ from functools import partial
import pytest
from flask import url_for
from app import format_notification_status_as_url
from app import (
format_notification_status_as_url,
format_number_in_pounds_as_currency,
)
@pytest.mark.parametrize('status, notification_type, expected', (
@@ -33,3 +36,19 @@ def test_format_notification_status_as_url(
assert format_notification_status_as_url(
status, notification_type
) == expected()
@pytest.mark.parametrize('input_number, formatted_number', [
(0, '0p'),
(0.01, '1p'),
(0.5, '50p'),
(1, '£1.00'),
(1.01, '£1.01'),
(1.006, '£1.01'),
(5.25, '£5.25'),
(5.7, '£5.70'),
(381, '£381.00'),
(144820, '£144,820.00'),
])
def test_format_number_in_pounds_as_currency(input_number, formatted_number):
assert format_number_in_pounds_as_currency(input_number) == formatted_number