diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index edb6c521e..d72158abf 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -54,6 +54,18 @@ def service_dashboard_updates(service_id): }) +@main.route("/services//template-activity") +@login_required +@user_has_permissions('view_activity', admin_override=True) +def template_history(service_id): + return render_template( + 'views/dashboard/all-template-statistics.html', + template_statistics=aggregate_usage( + template_statistics_client.get_template_statistics_for_service(service_id) + ) + ) + + def add_rates_to(delivery_statistics): if not delivery_statistics or not delivery_statistics[0]: @@ -125,4 +137,4 @@ def get_dashboard_statistics_for_service(service_id): 'template_statistics': aggregate_usage( template_statistics_client.get_template_statistics_for_service(service_id, limit_days=7) ) - } \ No newline at end of file + } diff --git a/app/templates/views/dashboard/all-template-statistics.html b/app/templates/views/dashboard/all-template-statistics.html new file mode 100644 index 000000000..3404df5f5 --- /dev/null +++ b/app/templates/views/dashboard/all-template-statistics.html @@ -0,0 +1,17 @@ +{% extends "withnav_template.html" %} + +{% block page_title %} + {{ current_service.name }} – GOV.UK Notify +{% endblock %} + +{% block maincolumn_content %} +

+ Templates used this year +

+

+ 1 April 2016 to date +

+ {% with period = "" %} + {% include 'views/dashboard/template-statistics.html' %} + {% endwith %} +{% endblock %} diff --git a/app/templates/views/dashboard/template-statistics.html b/app/templates/views/dashboard/template-statistics.html index d3a75867d..53070ef4a 100644 --- a/app/templates/views/dashboard/template-statistics.html +++ b/app/templates/views/dashboard/template-statistics.html @@ -3,7 +3,7 @@ template_statistics, caption="By template", caption_visible=False, - empty_message='You haven’t set up any templates yet', + empty_message='You haven’t used any templates {}'.format(period), field_headings=['Template', hidden_field_heading('Type'), right_aligned_field_heading('Messages processed')] ) %} {% call field() %} diff --git a/app/templates/views/dashboard/today.html b/app/templates/views/dashboard/today.html index 7912ffae7..3c2377642 100644 --- a/app/templates/views/dashboard/today.html +++ b/app/templates/views/dashboard/today.html @@ -25,5 +25,9 @@ ) }} - -{% include 'views/dashboard/template-statistics.html' %} +{% with period = "in the last 7 days" %} + {% include 'views/dashboard/template-statistics.html' %} +{% endwith %} + diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index 12082f1c7..9fc7f57cc 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -101,6 +101,49 @@ def test_should_show_recent_templates_on_dashboard(app_, assert table_data[2].text.strip() == '13' +def test_should_show_all_templates_on_template_statistics_page( + app_, + mocker, + api_user_active, + mock_get_service, + mock_get_service_templates, + mock_get_service_statistics, + mock_get_user, + mock_get_user_by_email, + mock_login, + mock_get_jobs, + mock_has_permissions +): + + mock_template_stats = mocker.patch('app.template_statistics_client.get_template_statistics_for_service', + return_value=copy.deepcopy(stub_template_stats)) + + with app_.test_request_context(): + with app_.test_client() as client: + client.login(api_user_active) + response = client.get(url_for('main.template_history', service_id=SERVICE_ONE_ID)) + + assert response.status_code == 200 + response.get_data(as_text=True) + mock_template_stats.assert_called_once_with(SERVICE_ONE_ID) + + page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') + headers = [header.text.strip() for header in page.find_all('h2')] + table_rows = page.tbody.find_all('tr') + + assert len(table_rows) == 2 + + first_row = page.tbody.find_all('tr')[0] + table_data = first_row.find_all('td') + assert len(table_data) == 3 + assert table_data[2].text.strip() == '206' + + second_row = page.tbody.find_all('tr')[1] + table_data = second_row.find_all('td') + assert len(table_data) == 3 + assert table_data[2].text.strip() == '13' + + def _test_dashboard_menu(mocker, app_, usr, service, permissions): with app_.test_request_context(): with app_.test_client() as client: