mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-20 14:29:25 -04:00
Merge pull request #3502 from alphagov/provider-report
add new daily sms provider volume report
This commit is contained in:
@@ -10,6 +10,7 @@ from app.dao.fact_billing_dao import (
|
||||
delete_billing_data_for_service_for_day,
|
||||
fetch_billing_data_for_day,
|
||||
fetch_billing_totals_for_year,
|
||||
fetch_daily_sms_provider_volumes_for_platform,
|
||||
fetch_daily_volumes_for_platform,
|
||||
fetch_letter_costs_and_totals_for_all_services,
|
||||
fetch_letter_line_items_for_all_services,
|
||||
@@ -856,6 +857,84 @@ def test_fetch_daily_volumes_for_platform(
|
||||
assert results[1].letter_sheet_totals == 40
|
||||
|
||||
|
||||
def test_fetch_daily_sms_provider_volumes_for_platform_groups_values_by_provider(
|
||||
notify_db_session,
|
||||
):
|
||||
services = [
|
||||
create_service(service_name='a'),
|
||||
create_service(service_name='b')
|
||||
]
|
||||
templates = [
|
||||
create_template(services[0]),
|
||||
create_template(services[1])
|
||||
]
|
||||
|
||||
create_ft_billing('2022-02-01', templates[0], provider='foo', notifications_sent=1, billable_unit=2)
|
||||
create_ft_billing('2022-02-01', templates[1], provider='foo', notifications_sent=4, billable_unit=8)
|
||||
|
||||
create_ft_billing('2022-02-01', templates[0], provider='bar', notifications_sent=16, billable_unit=32)
|
||||
create_ft_billing('2022-02-01', templates[1], provider='bar', notifications_sent=64, billable_unit=128)
|
||||
|
||||
results = fetch_daily_sms_provider_volumes_for_platform(start_date='2022-02-01', end_date='2022-02-01')
|
||||
|
||||
assert len(results) == 2
|
||||
assert results[0].provider == 'bar'
|
||||
assert results[0].sms_totals == 80
|
||||
assert results[0].sms_fragment_totals == 160
|
||||
|
||||
assert results[1].provider == 'foo'
|
||||
assert results[1].sms_totals == 5
|
||||
assert results[1].sms_fragment_totals == 10
|
||||
|
||||
|
||||
def test_fetch_daily_sms_provider_volumes_for_platform_for_platform_calculates_chargeable_units_and_costs(
|
||||
sample_template,
|
||||
):
|
||||
create_ft_billing('2022-02-01', sample_template, rate_multiplier=3, rate=1.5, notifications_sent=1, billable_unit=2)
|
||||
|
||||
results = fetch_daily_sms_provider_volumes_for_platform(start_date='2022-02-01', end_date='2022-02-01')
|
||||
|
||||
assert len(results) == 1
|
||||
assert results[0].sms_totals == 1
|
||||
assert results[0].sms_fragment_totals == 2
|
||||
assert results[0].sms_chargeable_units == 6
|
||||
assert results[0].sms_cost == 9
|
||||
|
||||
|
||||
def test_fetch_daily_sms_provider_volumes_for_platform_for_platform_searches_dates_inclusively(sample_template):
|
||||
# too early
|
||||
create_ft_billing('2022-02-02', sample_template)
|
||||
|
||||
# just right
|
||||
create_ft_billing('2022-02-03', sample_template)
|
||||
create_ft_billing('2022-02-04', sample_template)
|
||||
create_ft_billing('2022-02-05', sample_template)
|
||||
|
||||
# too late
|
||||
create_ft_billing('2022-02-06', sample_template)
|
||||
|
||||
results = fetch_daily_sms_provider_volumes_for_platform(start_date='2022-02-03', end_date='2022-02-05')
|
||||
|
||||
assert len(results) == 3
|
||||
assert results[0].bst_date == date(2022, 2, 3)
|
||||
assert results[-1].bst_date == date(2022, 2, 5)
|
||||
|
||||
|
||||
def test_fetch_daily_sms_provider_volumes_for_platform_for_platform_only_returns_sms(
|
||||
sample_template,
|
||||
sample_email_template,
|
||||
sample_letter_template
|
||||
):
|
||||
create_ft_billing('2022-02-01', sample_template, notifications_sent=1)
|
||||
create_ft_billing('2022-02-01', sample_email_template, notifications_sent=2)
|
||||
create_ft_billing('2022-02-01', sample_letter_template, notifications_sent=4)
|
||||
|
||||
results = fetch_daily_sms_provider_volumes_for_platform(start_date='2022-02-01', end_date='2022-02-01')
|
||||
|
||||
assert len(results) == 1
|
||||
assert results[0].sms_totals == 1
|
||||
|
||||
|
||||
def test_fetch_volumes_by_service(notify_db_session):
|
||||
set_up_usage_data(datetime(2022, 2, 1))
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ from app.platform_stats.rest import (
|
||||
validate_date_range_is_within_a_financial_year,
|
||||
)
|
||||
from tests.app.db import (
|
||||
create_ft_billing,
|
||||
create_ft_notification_status,
|
||||
create_notification,
|
||||
create_service,
|
||||
@@ -238,3 +239,23 @@ def test_volumes_by_service_report(
|
||||
'service_id': str(fixture['service_with_sms_within_allowance'].id),
|
||||
'service_name': fixture['service_with_sms_within_allowance'].name,
|
||||
'sms_chargeable_units': 0, 'sms_notifications': 0}
|
||||
|
||||
|
||||
def test_daily_sms_provider_volumes_report(admin_request, sample_template):
|
||||
|
||||
create_ft_billing('2022-03-01', sample_template, provider='foo', rate=1.5, notifications_sent=1, billable_unit=3)
|
||||
resp = admin_request.get(
|
||||
'platform_stats.daily_sms_provider_volumes_report',
|
||||
start_date='2022-03-01',
|
||||
end_date='2022-03-01'
|
||||
)
|
||||
|
||||
assert len(resp) == 1
|
||||
assert resp[0] == {
|
||||
'day': '2022-03-01',
|
||||
'provider': 'foo',
|
||||
'sms_totals': 1,
|
||||
'sms_fragment_totals': 3,
|
||||
'sms_chargeable_units': 3,
|
||||
'sms_cost': 4.5,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user