From 2dbf522932923f70f4e307a8264eb26a9410a09b Mon Sep 17 00:00:00 2001 From: Adam Shimali Date: Wed, 6 Apr 2016 15:06:02 +0100 Subject: [PATCH] Add date field back into template stats --- .../views/dashboard/template-statistics.html | 7 ++-- tests/app/main/views/test_dashboard.py | 33 ++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/app/templates/views/dashboard/template-statistics.html b/app/templates/views/dashboard/template-statistics.html index beccff247..9f6ba180d 100644 --- a/app/templates/views/dashboard/template-statistics.html +++ b/app/templates/views/dashboard/template-statistics.html @@ -3,7 +3,7 @@ template_statistics, caption="Recent templates used", empty_message='You haven’t sent any batch messages yet', - field_headings=['Template', 'Type', right_aligned_field_heading('Usage')] + field_headings=['Template', 'Type', 'Date', right_aligned_field_heading('Usage')] ) %} {% call field() %} @@ -13,7 +13,10 @@ {% call field() %} {{item.template.template_type}} {% endcall %} - {% call field(align='right') %} + {% call field() %} + {{item.day|format_date}} + {% endcall %} + {% call field(align='right') %} {{ item.usage_count }} {% endcall %} {% endcall %} diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index 418623bd1..78eabfcfe 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -1,20 +1,22 @@ from flask import url_for +from bs4 import BeautifulSoup + from tests import validate_route_permission from tests.conftest import SERVICE_ONE_ID -def test_should_show_recent_jobs_on_dashboard(app_, - api_user_active, - mock_get_service, - mock_get_service_templates, - mock_get_service_statistics, - mock_get_template_statistics, - mock_get_user, - mock_get_user_by_email, - mock_login, - mock_get_jobs, - mock_has_permissions): +def test_should_show_recent_templates_on_dashboard(app_, + api_user_active, + mock_get_service, + mock_get_service_templates, + mock_get_service_statistics, + mock_get_template_statistics, + mock_get_user, + mock_get_user_by_email, + mock_login, + mock_get_jobs, + mock_has_permissions): with app_.test_request_context(): with app_.test_client() as client: client.login(api_user_active) @@ -22,10 +24,17 @@ def test_should_show_recent_jobs_on_dashboard(app_, assert response.status_code == 200 text = response.get_data(as_text=True) - assert 'Test Service' in text mock_get_service_statistics.assert_called_once_with(SERVICE_ONE_ID) mock_get_template_statistics.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')] + assert 'Test Service' in headers + assert 'Sent today' in headers + template_usage_headers = [th.text.strip() for th in page.thead.find_all('th')] + for th in ['Template', 'Type', 'Date', 'Usage']: + assert th in template_usage_headers + def _test_dashboard_menu(mocker, app_, usr, service, permissions): with app_.test_request_context():