mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-28 09:59:59 -04:00
add new daily sms provider volumes report
nearly identical to the daily-volumes-report but sms only, and split up by provider
This commit is contained in:
@@ -381,6 +381,46 @@ def get_daily_volumes():
|
||||
return render_template('views/platform-admin/daily-volumes-report.html', form=form)
|
||||
|
||||
|
||||
@main.route("/platform-admin/reports/daily-sms-provider-volumes-report", methods=['GET', 'POST'])
|
||||
@user_is_platform_admin
|
||||
def get_daily_sms_provider_volumes():
|
||||
form = BillingReportDateFilterForm()
|
||||
|
||||
if form.validate_on_submit():
|
||||
start_date = form.start_date.data
|
||||
end_date = form.end_date.data
|
||||
headers = [
|
||||
"day",
|
||||
"provider",
|
||||
"sms totals",
|
||||
"sms fragment totals",
|
||||
"sms chargeable units",
|
||||
"sms cost",
|
||||
]
|
||||
result = billing_api_client.get_data_for_daily_sms_provider_volumes_report(start_date, end_date)
|
||||
|
||||
rows = [
|
||||
[
|
||||
r["day"],
|
||||
r["provider"],
|
||||
r["sms_totals"],
|
||||
r["sms_fragment_totals"],
|
||||
r["sms_chargeable_units"],
|
||||
r["sms_cost"]
|
||||
]
|
||||
for r in result
|
||||
]
|
||||
if rows:
|
||||
return Spreadsheet.from_rows([headers] + rows).as_csv_data, 200, {
|
||||
'Content-Type': 'text/csv; charset=utf-8',
|
||||
'Content-Disposition':
|
||||
f'attachment; filename="Daily SMS provider volumes report from {start_date} to {end_date}.csv"'
|
||||
}
|
||||
else:
|
||||
flash('No results for dates')
|
||||
return render_template('views/platform-admin/daily-sms-provider-volumes-report.html', form=form)
|
||||
|
||||
|
||||
@main.route("/platform-admin/complaints")
|
||||
@user_is_platform_admin
|
||||
def platform_admin_list_complaints():
|
||||
|
||||
@@ -95,6 +95,7 @@ class HeaderNavigation(Navigation):
|
||||
'notifications_sent_by_service',
|
||||
'get_billing_report',
|
||||
'get_daily_volumes',
|
||||
'get_daily_sms_provider_volumes',
|
||||
'get_volumes_by_service',
|
||||
'organisations',
|
||||
'platform_admin',
|
||||
|
||||
@@ -55,5 +55,14 @@ class BillingAPIClient(NotifyAdminAPIClient):
|
||||
'end_date': str(end_date),
|
||||
})
|
||||
|
||||
def get_data_for_daily_sms_provider_volumes_report(self, start_date, end_date):
|
||||
return self.get(
|
||||
url='/platform-stats/daily-sms-provider-volumes-report',
|
||||
params={
|
||||
'start_date': str(start_date),
|
||||
'end_date': str(end_date),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
billing_api_client = BillingAPIClient()
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
{% extends "views/platform-admin/_base_template.html" %}
|
||||
{% from "components/form.html" import form_wrapper %}
|
||||
{% from "components/table.html" import mapping_table, row, text_field %}
|
||||
|
||||
{% block per_page_title %}
|
||||
Daily SMS provider volumes Report
|
||||
{% endblock %}
|
||||
|
||||
{% block platform_admin_content %}
|
||||
|
||||
<h1 class="heading-large">
|
||||
Daily SMS provider volumes Report
|
||||
</h1>
|
||||
|
||||
{% call form_wrapper() %}
|
||||
{{ form.start_date(param_extensions={"hint": {"text": "Use the format YYYY-MM-DD"}}) }}
|
||||
{{ form.end_date(param_extensions={"hint": {"text": "Use the format YYYY-MM-DD"}}) }}
|
||||
{{ page_footer('Download report') }}
|
||||
{% endcall %}
|
||||
|
||||
<h2 class="heading-medium">
|
||||
Data included in the report
|
||||
</h2>
|
||||
<div class="bottom-gutter-3-2">
|
||||
{% call mapping_table(
|
||||
caption='Descriptions of daily SMS provider volumes data',
|
||||
field_headings=['Name', 'Description'],
|
||||
field_headings_visible=True,
|
||||
caption_visible=False
|
||||
) %}
|
||||
{% for message_length, description in [
|
||||
('day', 'The whole business day in BST'),
|
||||
('provider', 'The SMS provider'),
|
||||
('sms totals', 'The number of text messages sent'),
|
||||
('sms fragments', 'The number of text message fragments sent'),
|
||||
('sms chargeable units', 'The number of text message fragments sent times the rate multiplier'),
|
||||
('sms cost', 'The cost of text messages sent'),
|
||||
] %}
|
||||
{% call row() %}
|
||||
{{ text_field(message_length) }}
|
||||
{{ text_field(description | safe) }}
|
||||
{% endcall %}
|
||||
{% endfor %}
|
||||
{% endcall %}
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
@@ -25,4 +25,7 @@
|
||||
<p class="govuk-body">
|
||||
<a class="govuk-link govuk-link--no-visited-state" href="{{ url_for('main.get_daily_volumes') }}">Daily volumes Report</a>
|
||||
</p>
|
||||
<p class="govuk-body">
|
||||
<a class="govuk-link govuk-link--no-visited-state" href="{{ url_for('main.get_daily_sms_provider_volumes') }}">Daily SMS provider volumes Report</a>
|
||||
</p>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1113,3 +1113,46 @@ def test_get_daily_volumes_report_when_calls_api_and_download_data(
|
||||
|
||||
'\r\n'
|
||||
)
|
||||
|
||||
|
||||
def test_get_daily_sms_provider_volumes_report_when_calls_api_and_download_data(
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker
|
||||
):
|
||||
mocker.patch(
|
||||
"app.main.views.platform_admin.billing_api_client.get_data_for_daily_sms_provider_volumes_report",
|
||||
return_value=[{
|
||||
"day": '2019-01-01',
|
||||
"provider": 'foo',
|
||||
"sms_totals": 20,
|
||||
"sms_fragment_totals": 40,
|
||||
"sms_chargeable_units": 60,
|
||||
"sms_cost": 80,
|
||||
}]
|
||||
)
|
||||
|
||||
client_request.login(platform_admin_user)
|
||||
response = client_request.post_response(
|
||||
'main.get_daily_sms_provider_volumes',
|
||||
_data={'start_date': '2019-01-01', 'end_date': '2019-03-31'},
|
||||
_expected_status=200,
|
||||
)
|
||||
|
||||
assert response.content_type == 'text/csv; charset=utf-8'
|
||||
assert response.headers['Content-Disposition'] == (
|
||||
'attachment; filename="Daily SMS provider volumes report from {} to {}.csv"'.format('2019-01-01', '2019-03-31')
|
||||
)
|
||||
|
||||
assert response.get_data(as_text=True) == (
|
||||
"day,provider,sms totals,sms fragment totals,sms chargeable units,sms cost\r\n" +
|
||||
|
||||
'2019-01-01,' +
|
||||
'foo,' +
|
||||
'20,' +
|
||||
'40,' +
|
||||
'60,' +
|
||||
'80'
|
||||
|
||||
'\r\n'
|
||||
)
|
||||
|
||||
@@ -132,6 +132,7 @@ EXCLUDED_ENDPOINTS = tuple(map(Navigation.get_endpoint_with_blueprint, {
|
||||
'forgot_password',
|
||||
'get_billing_report',
|
||||
'get_daily_volumes',
|
||||
'get_daily_sms_provider_volumes',
|
||||
'get_volumes_by_service',
|
||||
'get_example_csv',
|
||||
'get_notifications_as_json',
|
||||
|
||||
Reference in New Issue
Block a user