mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-06 00:48:46 -04:00
Add unit tests for dashboard template functions
Although we integration test the pages that depend on these, it’s probably a good idea to unit test them as well, to make sure, for example, that all the different statuses are counted when working out how many messages have been sent from a template.
This commit is contained in:
@@ -12,6 +12,8 @@ from app.main.views.dashboard import (
|
||||
format_monthly_stats_to_list,
|
||||
get_free_paid_breakdown_for_billable_units,
|
||||
aggregate_status_types,
|
||||
format_template_stats_to_list,
|
||||
get_tuples_of_financial_years,
|
||||
)
|
||||
|
||||
from tests import validate_route_permission
|
||||
@@ -613,3 +615,61 @@ def test_get_free_paid_breakdown_for_billable_units(now, expected_number_of_mont
|
||||
{'name': 'February', 'free': 0, 'paid': 1234},
|
||||
{'name': 'March', 'free': 0, 'paid': 0}
|
||||
][:expected_number_of_months]
|
||||
|
||||
|
||||
def test_format_template_stats_to_list_with_no_stats():
|
||||
assert list(format_template_stats_to_list({})) == []
|
||||
|
||||
|
||||
def test_format_template_stats_to_list():
|
||||
counts = {
|
||||
'created': 1,
|
||||
'pending': 1,
|
||||
'delivered': 1,
|
||||
'failed': 1,
|
||||
'temporary-failure': 1,
|
||||
'permanent-failure': 1,
|
||||
'technical-failure': 1,
|
||||
'do-not-count': 999,
|
||||
}
|
||||
stats_list = list(format_template_stats_to_list({
|
||||
'template_2_id': {
|
||||
'counts': {},
|
||||
'name': 'bar',
|
||||
},
|
||||
'template_1_id': {
|
||||
'counts': counts,
|
||||
'name': 'foo',
|
||||
},
|
||||
}))
|
||||
|
||||
# we don’t care about the order of this function’s output
|
||||
assert len(stats_list) == 2
|
||||
assert {
|
||||
'counts': counts,
|
||||
'name': 'foo',
|
||||
'requested_count': 7,
|
||||
} in stats_list
|
||||
assert {
|
||||
'counts': {},
|
||||
'name': 'bar',
|
||||
'requested_count': 0,
|
||||
} in stats_list
|
||||
|
||||
|
||||
def test_get_tuples_of_financial_years():
|
||||
assert list(get_tuples_of_financial_years(
|
||||
lambda year: 'http://example.com?year={}'.format(year),
|
||||
start=2040,
|
||||
end=2041,
|
||||
)) == [
|
||||
('financial year', 2040, 'http://example.com?year=2040', '2040 to 2041'),
|
||||
('financial year', 2041, 'http://example.com?year=2041', '2041 to 2042'),
|
||||
]
|
||||
|
||||
|
||||
def test_get_tuples_of_financial_years_defaults_to_2015():
|
||||
assert 2015 in list(get_tuples_of_financial_years(
|
||||
lambda year: 'http://example.com?year={}'.format(year),
|
||||
end=2040,
|
||||
))[0]
|
||||
|
||||
Reference in New Issue
Block a user