From c509d3d24fe2ad360a3e9a4172c25277f2d3fb45 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Fri, 7 Apr 2017 10:54:52 +0100 Subject: [PATCH 1/2] remove unused imports --- tests/app/main/views/test_dashboard.py | 46 +------------------------- 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index ec1eb7b5f..4864eea95 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -1,4 +1,3 @@ -from datetime import datetime from functools import partial import copy from flask import url_for @@ -39,14 +38,8 @@ stub_template_stats = [ def test_get_started( logged_in_client, mocker, - api_user_active, - mock_get_service, mock_get_service_templates_when_no_templates_exist, - mock_get_user, - mock_get_user_by_email, - mock_login, mock_get_jobs, - mock_has_permissions, mock_get_detailed_service, mock_get_usage, ): @@ -63,14 +56,8 @@ def test_get_started( def test_get_started_is_hidden_once_templates_exist( logged_in_client, mocker, - api_user_active, - mock_get_service, mock_get_service_templates, - mock_get_user, - mock_get_user_by_email, - mock_login, mock_get_jobs, - mock_has_permissions, mock_get_detailed_service, mock_get_usage, ): @@ -86,14 +73,8 @@ def test_get_started_is_hidden_once_templates_exist( def test_should_show_recent_templates_on_dashboard( logged_in_client, mocker, - api_user_active, - mock_get_service, mock_get_service_templates, - mock_get_user, - mock_get_user_by_email, - mock_login, mock_get_jobs, - mock_has_permissions, mock_get_detailed_service, mock_get_usage, ): @@ -130,13 +111,7 @@ def test_should_show_recent_templates_on_dashboard( ]) def test_should_show_monthly_breakdown_of_template_usage( logged_in_client, - mocker, - api_user_active, - mock_get_service, mock_get_monthly_template_statistics, - mock_get_user, - mock_get_user_by_email, - mock_has_permissions, partial_url, ): response = logged_in_client.get( @@ -162,17 +137,10 @@ def test_should_show_monthly_breakdown_of_template_usage( @freeze_time("2016-01-01 11:09:00.061258") def test_should_show_upcoming_jobs_on_dashboard( logged_in_client, - mocker, - api_user_active, - mock_get_service, mock_get_service_templates, - mock_get_user, - mock_get_user_by_email, - mock_login, mock_get_template_statistics, mock_get_detailed_service, mock_get_jobs, - mock_has_permissions, mock_get_usage, ): response = logged_in_client.get(url_for('main.service_dashboard', service_id=SERVICE_ONE_ID)) @@ -199,17 +167,10 @@ def test_should_show_upcoming_jobs_on_dashboard( @freeze_time("2016-01-01 11:09:00.061258") def test_should_show_recent_jobs_on_dashboard( logged_in_client, - mocker, - api_user_active, - mock_get_service, mock_get_service_templates, - mock_get_user, - mock_get_user_by_email, - mock_login, mock_get_template_statistics, mock_get_detailed_service, mock_get_jobs, - mock_has_permissions, mock_get_usage, ): response = logged_in_client.get(url_for('main.service_dashboard', service_id=SERVICE_ONE_ID)) @@ -464,16 +425,13 @@ def test_aggregate_template_stats(): def test_service_dashboard_updates_gets_dashboard_totals( mocker, logged_in_client, - active_user_with_permissions, - service_one, - mock_get_user, mock_get_service_templates, mock_get_template_statistics, mock_get_detailed_service, mock_get_jobs, mock_get_usage, ): - dashboard_totals = mocker.patch('app.main.views.dashboard.get_dashboard_totals', return_value={ + mocker.patch('app.main.views.dashboard.get_dashboard_totals', return_value={ 'email': {'requested': 123, 'delivered': 0, 'failed': 0}, 'sms': {'requested': 456, 'delivered': 0, 'failed': 0} }) @@ -487,8 +445,6 @@ def test_service_dashboard_updates_gets_dashboard_totals( assert '123' in numbers assert '456' in numbers - table_rows = page.find_all('tbody')[0].find_all('tr') - def test_get_dashboard_totals_adds_percentages(): stats = { From 2bb0cba43068ba7697d24f41d33c574dc45ca335 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Fri, 7 Apr 2017 11:08:40 +0100 Subject: [PATCH 2/2] add new letter job statuses to job api client add test to test_dashboard to confirm we're getting for the right queus --- app/notify_client/job_api_client.py | 2 ++ tests/app/main/views/test_dashboard.py | 29 +++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/notify_client/job_api_client.py b/app/notify_client/job_api_client.py index ca487f303..d4dc8eb7e 100644 --- a/app/notify_client/job_api_client.py +++ b/app/notify_client/job_api_client.py @@ -12,6 +12,8 @@ class JobApiClient(NotifyAdminAPIClient): 'finished', 'cancelled', 'sending limits exceeded', + 'ready to send', + 'sent to dvla' } def __init__(self): diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index 4864eea95..17c51ce59 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -1,7 +1,8 @@ from functools import partial import copy -from flask import url_for +from unittest.mock import call, ANY +from flask import url_for import pytest from bs4 import BeautifulSoup from freezegun import freeze_time @@ -13,6 +14,7 @@ from app.main.views.dashboard import ( aggregate_status_types, format_template_stats_to_list, get_tuples_of_financial_years, + get_dashboard_partials ) from tests import validate_route_permission @@ -631,3 +633,28 @@ def test_get_tuples_of_financial_years_defaults_to_2015(): lambda year: 'http://example.com?year={}'.format(year), end=2040, ))[0] + + +@freeze_time("2016-01-01 11:09:00.061258") +def test_should_show_all_jobs_with_valid_statuses( + logged_in_client, + mock_get_template_statistics, + mock_get_detailed_service, + mock_get_jobs, + mock_get_usage, +): + get_dashboard_partials(service_id=SERVICE_ONE_ID) + + first_call = mock_get_jobs.call_args_list[0] + # first call - scheduled jobs only + assert first_call == call(ANY, statuses=['scheduled']) + # second call - everything but scheduled and cancelled + second_call = mock_get_jobs.call_args_list[1] + assert second_call == call(ANY, limit_days=ANY, statuses={ + 'pending', + 'in progress', + 'finished', + 'sending limits exceeded', + 'ready to send', + 'sent to dvla' + })