mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-06-20 05:02:30 -04:00
Merge pull request #2152 from alphagov/remove-old-platform-stats
Use new platform-admin page
This commit is contained in:
@@ -28,33 +28,6 @@ ZERO_FAILURE_THRESHOLD = 0
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
def platform_admin():
|
||||
form = DateFilterForm(request.args)
|
||||
api_args = {'detailed': True,
|
||||
'only_active': False, # specifically DO get inactive services
|
||||
'include_from_test_key': form.include_from_test_key.data,
|
||||
}
|
||||
|
||||
if form.start_date.data:
|
||||
api_args['start_date'] = form.start_date.data
|
||||
api_args['end_date'] = form.end_date.data or datetime.utcnow().date()
|
||||
|
||||
platform_stats = service_api_client.get_aggregate_platform_stats(api_args)
|
||||
|
||||
for stat in platform_stats.values():
|
||||
stat['failure_rate'] = get_formatted_percentage(stat['failed'], stat['requested'])
|
||||
|
||||
return render_template(
|
||||
'views/platform-admin/index.html',
|
||||
include_from_test_key=form.include_from_test_key.data,
|
||||
form=form,
|
||||
global_stats=platform_stats,
|
||||
)
|
||||
|
||||
|
||||
@main.route("/platform-admin-new")
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
def platform_admin_new():
|
||||
form = DateFilterForm(request.args, meta={'csrf': False})
|
||||
api_args = {}
|
||||
|
||||
@@ -68,7 +41,7 @@ def platform_admin_new():
|
||||
number_of_complaints = complaint_api_client.get_complaint_count(api_args)
|
||||
|
||||
return render_template(
|
||||
'views/platform-admin/index_new.html',
|
||||
'views/platform-admin/index.html',
|
||||
form=form,
|
||||
global_stats=make_columns(platform_stats, number_of_complaints)
|
||||
)
|
||||
|
||||
@@ -79,7 +79,6 @@ class HeaderNavigation(Navigation):
|
||||
'live_services',
|
||||
'organisations',
|
||||
'platform_admin',
|
||||
'platform_admin_new',
|
||||
'suspend_service',
|
||||
'trial_services',
|
||||
'update_email_branding',
|
||||
@@ -425,7 +424,6 @@ class MainNavigation(Navigation):
|
||||
'organisation_settings',
|
||||
'organisations',
|
||||
'platform_admin',
|
||||
'platform_admin_new',
|
||||
'platform_admin_list_complaints',
|
||||
'preview_basic_view',
|
||||
'pricing',
|
||||
@@ -599,7 +597,6 @@ class CaseworkNavigation(Navigation):
|
||||
'organisation_settings',
|
||||
'organisations',
|
||||
'platform_admin',
|
||||
'platform_admin_new',
|
||||
'platform_admin_list_complaints',
|
||||
'preview_basic_view',
|
||||
'pricing',
|
||||
@@ -818,7 +815,6 @@ class OrgNavigation(Navigation):
|
||||
'old_using_notify',
|
||||
'organisations',
|
||||
'platform_admin',
|
||||
'platform_admin_new',
|
||||
'platform_admin_list_complaints',
|
||||
'preview_basic_view',
|
||||
'pricing',
|
||||
|
||||
@@ -412,9 +412,6 @@ class ServiceAPIClient(NotifyAdminAPIClient):
|
||||
}
|
||||
)
|
||||
|
||||
def get_aggregate_platform_stats(self, params_dict=None):
|
||||
return self.get("/service/platform-stats", params=params_dict)
|
||||
|
||||
def get_sms_senders(self, service_id):
|
||||
return self.get(
|
||||
"/service/{}/sms-sender".format(service_id)
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
{% extends "views/platform-admin/_base_template.html" %}
|
||||
{% from "components/textbox.html" import textbox %}
|
||||
{% from "components/big-number.html" import big_number %}
|
||||
{% from "components/checkbox.html" import checkbox %}
|
||||
{% from "components/page-footer.html" import page_footer %}
|
||||
{% from "components/table.html" import mapping_table, field, stats_fields, row_group, row, right_aligned_field_heading, hidden_field_heading, text_field %}
|
||||
{% from "components/big-number.html" import big_number_simple %}
|
||||
{% from "components/message-count-label.html" import message_count_label %}
|
||||
{% from "components/status-box.html" import status_box %}
|
||||
|
||||
{% block per_page_title %}
|
||||
Platform admin
|
||||
@@ -14,18 +13,46 @@
|
||||
<h1 class="heading-large">
|
||||
Summary
|
||||
</h1>
|
||||
|
||||
<details>
|
||||
<details {% if form.errors %}open{% endif %}>
|
||||
<summary>Apply filters</summary>
|
||||
<form autocomplete="off" method="get">
|
||||
{{ textbox(form.start_date, hint="Enter start date in format YYYY-MM-DD") }}
|
||||
{{ textbox(form.end_date, hint="Enter end date in format YYYY-MM-DD") }}
|
||||
{{ checkbox(form.include_from_test_key) }}
|
||||
</br>
|
||||
<button type="submit" class="button">Filter</button>
|
||||
</form>
|
||||
</details>
|
||||
|
||||
{% include "views/platform-admin/_global_stats.html" %}
|
||||
<div class="grid-row bottom-gutter">
|
||||
{% for noti_type in global_stats %}
|
||||
<div class="column-third">
|
||||
{{ big_number_simple(
|
||||
noti_type.black_box.number,
|
||||
message_count_label(noti_type.black_box.number, noti_type.black_box.notification_type)
|
||||
) }}
|
||||
|
||||
{% for item in noti_type.other_data %}
|
||||
{{ status_box(
|
||||
number=item.number,
|
||||
label=item.label,
|
||||
failing=item.failing,
|
||||
percentage=item.percentage,
|
||||
url=item.url)
|
||||
}}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="grid-row bottom-gutter">
|
||||
{% for noti_type in global_stats %}
|
||||
<div class="column-third">
|
||||
<div class="bordered-text-box">
|
||||
<span class="big-number-number">{{ "{:,}".format(noti_type.test_data.number) }}</span>
|
||||
{{ noti_type.test_data.label }}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
{% extends "views/platform-admin/_base_template.html" %}
|
||||
{% from "components/textbox.html" import textbox %}
|
||||
{% from "components/big-number.html" import big_number_simple %}
|
||||
{% from "components/message-count-label.html" import message_count_label %}
|
||||
{% from "components/status-box.html" import status_box %}
|
||||
|
||||
{% block per_page_title %}
|
||||
Platform admin
|
||||
{% endblock %}
|
||||
|
||||
{% block platform_admin_content %}
|
||||
|
||||
<h1 class="heading-large">
|
||||
Summary
|
||||
</h1>
|
||||
<details {% if form.errors %}open{% endif %}>
|
||||
<summary>Apply filters</summary>
|
||||
<form autocomplete="off" method="get">
|
||||
{{ textbox(form.start_date, hint="Enter start date in format YYYY-MM-DD") }}
|
||||
{{ textbox(form.end_date, hint="Enter end date in format YYYY-MM-DD") }}
|
||||
</br>
|
||||
<button type="submit" class="button">Filter</button>
|
||||
</form>
|
||||
</details>
|
||||
|
||||
<div class="grid-row bottom-gutter">
|
||||
{% for noti_type in global_stats %}
|
||||
<div class="column-third">
|
||||
{{ big_number_simple(
|
||||
noti_type.black_box.number,
|
||||
message_count_label(noti_type.black_box.number, noti_type.black_box.notification_type)
|
||||
) }}
|
||||
|
||||
{% for item in noti_type.other_data %}
|
||||
{{ status_box(
|
||||
number=item.number,
|
||||
label=item.label,
|
||||
failing=item.failing,
|
||||
percentage=item.percentage,
|
||||
url=item.url)
|
||||
}}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="grid-row bottom-gutter">
|
||||
{% for noti_type in global_stats %}
|
||||
<div class="column-third">
|
||||
<div class="bordered-text-box">
|
||||
<span class="big-number-number">{{ "{:,}".format(noti_type.test_data.number) }}</span>
|
||||
{{ noti_type.test_data.label }}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
@@ -137,28 +137,6 @@ def test_live_trial_services_toggle_including_from_test_key(
|
||||
'include_from_test_key': inc})
|
||||
|
||||
|
||||
@pytest.mark.parametrize('include_from_test_key, inc', [
|
||||
("Y", True),
|
||||
("N", False)
|
||||
])
|
||||
def test_platform_admin_toggle_including_from_test_key(
|
||||
include_from_test_key,
|
||||
client,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
mock_get_aggregate_platform_stats,
|
||||
inc
|
||||
):
|
||||
mock_get_user(mocker, user=platform_admin_user)
|
||||
client.login(platform_admin_user)
|
||||
response = client.get(url_for('main.platform_admin', include_from_test_key=include_from_test_key))
|
||||
|
||||
assert response.status_code == 200
|
||||
mock_get_aggregate_platform_stats.assert_called_once_with({'detailed': True,
|
||||
'only_active': False,
|
||||
'include_from_test_key': inc})
|
||||
|
||||
|
||||
@pytest.mark.parametrize('endpoint', [
|
||||
'main.live_services',
|
||||
'main.trial_services'
|
||||
@@ -186,59 +164,6 @@ def test_live_trial_services_with_date_filter(
|
||||
})
|
||||
|
||||
|
||||
def test_platform_admin_with_date_filter(
|
||||
client,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
mock_get_aggregate_platform_stats
|
||||
):
|
||||
mock_get_user(mocker, user=platform_admin_user)
|
||||
client.login(platform_admin_user)
|
||||
response = client.get(url_for('main.platform_admin', start_date='2016-12-20', end_date='2016-12-28'))
|
||||
|
||||
assert response.status_code == 200
|
||||
resp_data = response.get_data(as_text=True)
|
||||
assert 'Platform admin' in resp_data
|
||||
mock_get_aggregate_platform_stats.assert_called_once_with({
|
||||
'include_from_test_key': False,
|
||||
'end_date': datetime.date(2016, 12, 28),
|
||||
'start_date': datetime.date(2016, 12, 20),
|
||||
'detailed': True,
|
||||
'only_active': False,
|
||||
})
|
||||
|
||||
|
||||
def test_should_show_total_on_platform_admin_page(
|
||||
client,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
mock_get_aggregate_platform_stats
|
||||
):
|
||||
stats = {
|
||||
'email': {'requested': 61, 'delivered': 55, 'failed': 6},
|
||||
'sms': {'requested': 121, 'delivered': 110, 'failed': 11},
|
||||
'letter': {'requested': 45, 'delivered': 32, 'failed': 13}
|
||||
}
|
||||
expected = (
|
||||
'61 emails sent 6 failed – 9.8%',
|
||||
'121 text messages sent 11 failed – 9.1%',
|
||||
'45 letters sent 13 failed – 28.9%'
|
||||
)
|
||||
|
||||
mock_get_aggregate_platform_stats.return_value = stats
|
||||
|
||||
mock_get_user(mocker, user=platform_admin_user)
|
||||
client.login(platform_admin_user)
|
||||
response = client.get(url_for('main.platform_admin'))
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert (
|
||||
normalize_spaces(page.select('.big-number-with-status')[0].text),
|
||||
normalize_spaces(page.select('.big-number-with-status')[1].text),
|
||||
normalize_spaces(page.select('.big-number-with-status')[2].text),
|
||||
) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize('endpoint, expected_big_numbers', [
|
||||
(
|
||||
'main.live_services', (
|
||||
@@ -522,37 +447,6 @@ def test_shows_archived_label_instead_of_live_or_research_mode_label(
|
||||
assert service_mode == 'archived'
|
||||
|
||||
|
||||
def test_should_show_correct_sent_totals_for_platform_admin(
|
||||
client,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
mock_get_aggregate_platform_stats,
|
||||
fake_uuid,
|
||||
):
|
||||
stats = {
|
||||
'email': {'requested': 100, 'delivered': 20, 'failed': 40},
|
||||
'sms': {'requested': 100, 'delivered': 10, 'failed': 30},
|
||||
'letter': {'requested': 60, 'delivered': 40, 'failed': 5}
|
||||
|
||||
}
|
||||
mock_get_aggregate_platform_stats.return_value = stats
|
||||
mock_get_user(mocker, user=platform_admin_user)
|
||||
client.login(platform_admin_user)
|
||||
response = client.get(url_for('main.platform_admin'))
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
totals = page.find_all('div', 'big-number-with-status')
|
||||
email_total = int(totals[0].find_all('div', 'big-number-number')[0].text.strip())
|
||||
sms_total = int(totals[1].find_all('div', 'big-number-number')[0].text.strip())
|
||||
letter_total = int(totals[2].find_all('div', 'big-number-number')[0].text.strip())
|
||||
|
||||
assert email_total == 60
|
||||
assert sms_total == 40
|
||||
assert letter_total == 60
|
||||
|
||||
|
||||
@pytest.mark.parametrize('endpoint, restricted, research_mode', [
|
||||
('main.trial_services', True, False),
|
||||
('main.live_services', False, False)
|
||||
@@ -739,7 +633,7 @@ def test_get_tech_failure_status_box_data_removes_percentage_data():
|
||||
assert 'percentage' not in tech_failure_data
|
||||
|
||||
|
||||
def test_platform_admin_new_with_start_and_end_dates_provided(mocker, logged_in_platform_admin_client):
|
||||
def test_platform_admin_with_start_and_end_dates_provided(mocker, logged_in_platform_admin_client):
|
||||
start_date = '2018-01-01'
|
||||
end_date = '2018-06-01'
|
||||
api_args = {'start_date': datetime.date(2018, 1, 1), 'end_date': datetime.date(2018, 6, 1)}
|
||||
@@ -750,7 +644,7 @@ def test_platform_admin_new_with_start_and_end_dates_provided(mocker, logged_in_
|
||||
complaint_count_mock = mocker.patch('app.main.views.platform_admin.complaint_api_client.get_complaint_count')
|
||||
|
||||
logged_in_platform_admin_client.get(
|
||||
url_for('main.platform_admin_new', start_date=start_date, end_date=end_date)
|
||||
url_for('main.platform_admin', start_date=start_date, end_date=end_date)
|
||||
)
|
||||
|
||||
aggregate_stats_mock.assert_called_with(api_args)
|
||||
@@ -758,7 +652,7 @@ def test_platform_admin_new_with_start_and_end_dates_provided(mocker, logged_in_
|
||||
|
||||
|
||||
@freeze_time('2018-6-11')
|
||||
def test_platform_admin_new_with_only_a_start_date_provided(mocker, logged_in_platform_admin_client):
|
||||
def test_platform_admin_with_only_a_start_date_provided(mocker, logged_in_platform_admin_client):
|
||||
start_date = '2018-01-01'
|
||||
api_args = {'start_date': datetime.date(2018, 1, 1), 'end_date': datetime.datetime.utcnow().date()}
|
||||
|
||||
@@ -767,13 +661,13 @@ def test_platform_admin_new_with_only_a_start_date_provided(mocker, logged_in_pl
|
||||
'app.main.views.platform_admin.platform_stats_api_client.get_aggregate_platform_stats')
|
||||
complaint_count_mock = mocker.patch('app.main.views.platform_admin.complaint_api_client.get_complaint_count')
|
||||
|
||||
logged_in_platform_admin_client.get(url_for('main.platform_admin_new', start_date=start_date))
|
||||
logged_in_platform_admin_client.get(url_for('main.platform_admin', start_date=start_date))
|
||||
|
||||
aggregate_stats_mock.assert_called_with(api_args)
|
||||
complaint_count_mock.assert_called_with(api_args)
|
||||
|
||||
|
||||
def test_platform_admin_new_without_dates_provided(mocker, logged_in_platform_admin_client):
|
||||
def test_platform_admin_without_dates_provided(mocker, logged_in_platform_admin_client):
|
||||
api_args = {}
|
||||
|
||||
mocker.patch('app.main.views.platform_admin.make_columns')
|
||||
@@ -781,13 +675,13 @@ def test_platform_admin_new_without_dates_provided(mocker, logged_in_platform_ad
|
||||
'app.main.views.platform_admin.platform_stats_api_client.get_aggregate_platform_stats')
|
||||
complaint_count_mock = mocker.patch('app.main.views.platform_admin.complaint_api_client.get_complaint_count')
|
||||
|
||||
logged_in_platform_admin_client.get(url_for('main.platform_admin_new'))
|
||||
logged_in_platform_admin_client.get(url_for('main.platform_admin'))
|
||||
|
||||
aggregate_stats_mock.assert_called_with(api_args)
|
||||
complaint_count_mock.assert_called_with(api_args)
|
||||
|
||||
|
||||
def test_platform_admin_new_displays_stats_in_right_boxes_and_with_correct_styling(
|
||||
def test_platform_admin_displays_stats_in_right_boxes_and_with_correct_styling(
|
||||
mocker,
|
||||
logged_in_platform_admin_client,
|
||||
):
|
||||
@@ -809,7 +703,7 @@ def test_platform_admin_new_displays_stats_in_right_boxes_and_with_correct_styli
|
||||
return_value=platform_stats)
|
||||
mocker.patch('app.main.views.platform_admin.complaint_api_client.get_complaint_count', return_value=15)
|
||||
|
||||
response = logged_in_platform_admin_client.get(url_for('main.platform_admin_new'))
|
||||
response = logged_in_platform_admin_client.get(url_for('main.platform_admin'))
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
# Email permanent failure status box - number is correct
|
||||
|
||||
@@ -2670,17 +2670,6 @@ def normalize_spaces(input):
|
||||
return normalize_spaces(' '.join(item.text for item in input))
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_get_aggregate_platform_stats(mocker):
|
||||
stats = {
|
||||
'email': {'requested': 0, 'delivered': 0, 'failed': 0},
|
||||
'sms': {'requested': 0, 'delivered': 0, 'failed': 0},
|
||||
'letter': {'requested': 0, 'delivered': 0, 'failed': 0}
|
||||
|
||||
}
|
||||
return mocker.patch('app.service_api_client.get_aggregate_platform_stats', return_value=stats)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_get_free_sms_fragment_limit(mocker):
|
||||
sample_limit = 250000
|
||||
|
||||
Reference in New Issue
Block a user