Allow filtering of billing info by financial year

We already filter the usage-by-month query by financial year. When we
show the total usage for a service, we should be able to filter this
by financial year.

Then, when the two lots of data are put side by side, it all adds up.
This commit is contained in:
Chris Hill-Scott
2017-01-26 16:40:52 +00:00
parent c3a9d6d5ed
commit 8ad0236f28
3 changed files with 29 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ from datetime import datetime
import uuid
import pytest
from freezegun import freeze_time
from app.models import NotificationHistory, KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST, NOTIFICATION_STATUS_TYPES
from app.dao.provider_statistics_dao import get_fragment_count
@@ -35,6 +36,20 @@ def test_get_fragment_count_filters_on_service_id(notify_db, sample_template, se
assert get_fragment_count(service_2.id)['sms_count'] == 0
@pytest.mark.parametrize('creation_time, expected_count', [
('2000-03-31 22:59:59', 0), # before the start of the year
('2000-04-01 00:00:00', 1), # after the start of the year
('2001-03-31 22:59:59', 1), # before the end of the year
('2001-04-01 00:00:00', 0), # after the end of the year
])
def test_get_fragment_count_filters_on_year(
notify_db, sample_template, creation_time, expected_count
):
with freeze_time(creation_time):
noti_hist(notify_db, sample_template)
assert get_fragment_count(sample_template.service_id, year=2000)['sms_count'] == expected_count
def test_get_fragment_count_sums_billable_units_for_sms(notify_db, sample_template):
noti_hist(notify_db, sample_template, billable_units=1)
noti_hist(notify_db, sample_template, billable_units=2)