diff --git a/app/main/views/platform_admin.py b/app/main/views/platform_admin.py index a5485b988..d6494620f 100644 --- a/app/main/views/platform_admin.py +++ b/app/main/views/platform_admin.py @@ -1,6 +1,9 @@ import itertools -from flask import render_template +from flask import ( + render_template, + request +) from flask_login import login_required from app import service_api_client @@ -13,10 +16,15 @@ from app.statistics_utils import get_formatted_percentage @login_required @user_has_permissions(admin_override=True) def platform_admin(): + include_from_test_key = request.args.get('include_from_test_key') != 'False' # specifically DO get inactive services - services = service_api_client.get_services({'detailed': True})['data'] + api_args = {'detailed': True} + if not include_from_test_key: + api_args['include_from_test_key'] = False + services = service_api_client.get_services(api_args)['data'] return render_template( 'views/platform-admin.html', + include_from_test_key=include_from_test_key, **get_statistics(sorted( services, key=lambda service: (service['active'], service['created_at']), diff --git a/app/templates/admin_template.html b/app/templates/admin_template.html index 14e399d36..ebc1d29cc 100644 --- a/app/templates/admin_template.html +++ b/app/templates/admin_template.html @@ -47,6 +47,9 @@
  • Platform admin
  • +
  • + Providers +
  • {% endif %}
  • Sign out diff --git a/app/templates/views/platform-admin.html b/app/templates/views/platform-admin.html index e548cf802..52eb48d4b 100644 --- a/app/templates/views/platform-admin.html +++ b/app/templates/views/platform-admin.html @@ -1,7 +1,6 @@ {% extends "withoutnav_template.html" %} {% from "components/big-number.html" import big_number, big_number_with_status %} {% from "components/message-count-label.html" import message_count_label %} -{% from "components/browse-list.html" import browse_list %} {% from "components/table.html" import mapping_table, field, stats_fields, row_group, row, right_aligned_field_heading, hidden_field_heading, text_field %} {% macro stats_fields(channel, data) -%} @@ -88,15 +87,15 @@ Platform admin - {{ browse_list([ - { - 'title': 'View providers', - 'link': url_for('.view_providers') - }, - ]) }} +

    + Showing stats for today  + {% if include_from_test_key %} + Including test keys (change) + {% else %} + Excluding test keys (change) + {% endif %} +

    - -

    Today

    {{ big_number_with_status( diff --git a/tests/app/main/views/test_platform_admin.py b/tests/app/main/views/test_platform_admin.py index 77295bedc..6f6fd5411 100644 --- a/tests/app/main/views/test_platform_admin.py +++ b/tests/app/main/views/test_platform_admin.py @@ -81,12 +81,49 @@ def test_should_render_platform_admin_page( assert response.status_code == 200 resp_data = response.get_data(as_text=True) assert 'Platform admin' in resp_data - assert 'Today' in resp_data + assert 'Showing stats for today' in resp_data assert 'Live services' in resp_data assert 'Trial mode services' in resp_data mock_get_detailed_services.assert_called_once_with({'detailed': True}) +@pytest.mark.parametrize('include_from_test_key, expected_text, unexpected_text, api_args', [ + (True, 'Including test keys', 'Excluding test keys', {'detailed': True}), + (False, 'Excluding test keys', 'Including test keys', {'detailed': True, 'include_from_test_key': False}) +]) +def test_platform_admin_toggle_including_from_test_key( + include_from_test_key, + expected_text, + unexpected_text, + api_args, + app_, + platform_admin_user, + mocker, + mock_get_detailed_services +): + with app_.test_request_context(): + with app_.test_client() as client: + 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=str(include_from_test_key))) + + assert response.status_code == 200 + resp_data = response.get_data(as_text=True) + assert expected_text in resp_data + assert unexpected_text not in resp_data + + page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') + change_link = page.find('a', text='change') + assert change_link['href'] + query_param = 'include_from_test_key=False' + if include_from_test_key: + assert query_param in change_link['href'] + else: + assert query_param not in change_link['href'] + + mock_get_detailed_services.assert_called_once_with(api_args) + + def test_create_global_stats_sets_failure_rates(fake_uuid): services = [ service_json(fake_uuid, 'a', []),