From fade656e3be4d634dddeaed9f8242167ec50b06f Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Wed, 20 Jul 2016 13:55:08 +0100 Subject: [PATCH] add new get_detailed_service mock to tests that the dashboard --- tests/app/main/views/test_accept_invite.py | 5 ++++- tests/app/main/views/test_dashboard.py | 16 +++++++++++----- tests/app/main/views/test_sign_out.py | 1 + tests/conftest.py | 15 ++++++++------- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/tests/app/main/views/test_accept_invite.py b/tests/app/main/views/test_accept_invite.py index 9544c9cbe..f707e310b 100644 --- a/tests/app/main/views/test_accept_invite.py +++ b/tests/app/main/views/test_accept_invite.py @@ -314,7 +314,10 @@ def test_new_invited_user_verifies_and_added_to_service(app_, mock_get_service_statistics, mock_get_template_statistics, mock_get_jobs, - mock_has_permissions): + mock_has_permissions, + mock_get_users_by_service, + mock_get_detailed_service, + mock_get_usage): with app_.test_request_context(): with app_.test_client() as client: diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index ce4dca2b3..b9a23afda 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -69,6 +69,7 @@ def test_get_started( mock_login, mock_get_jobs, mock_has_permissions, + mock_get_detailed_service, mock_get_usage ): @@ -98,11 +99,11 @@ def test_get_started_is_hidden_once_templates_exist( mock_login, mock_get_jobs, mock_has_permissions, + mock_get_detailed_service, mock_get_usage ): 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(), app_.test_client() as client: client.login(api_user_active) response = client.get(url_for('main.service_dashboard', service_id=SERVICE_ONE_ID)) @@ -117,13 +118,13 @@ 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_aggregate_service_statistics, mock_get_user, mock_get_user_by_email, mock_login, mock_get_jobs, mock_has_permissions, + mock_get_detailed_service, mock_get_usage): mock_template_stats = mocker.patch('app.template_statistics_client.get_template_statistics_for_service', @@ -136,7 +137,6 @@ def test_should_show_recent_templates_on_dashboard(app_, assert response.status_code == 200 response.get_data(as_text=True) - mock_get_service_statistics.assert_called_once_with(SERVICE_ONE_ID, limit_days=7) mock_template_stats.assert_called_once_with(SERVICE_ONE_ID, limit_days=7) page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') @@ -210,6 +210,7 @@ def test_should_show_recent_jobs_on_dashboard( mock_get_user_by_email, mock_login, mock_get_template_statistics, + mock_get_detailed_service, mock_get_jobs, mock_has_permissions, mock_get_usage @@ -261,6 +262,7 @@ def test_menu_send_messages(mocker, mock_get_service_templates, mock_get_jobs, mock_get_template_statistics, + mock_get_detailed_service, mock_get_usage): with app_.test_request_context(): @@ -295,6 +297,7 @@ def test_menu_manage_service(mocker, mock_get_service_templates, mock_get_jobs, mock_get_template_statistics, + mock_get_detailed_service, mock_get_usage): with app_.test_request_context(): resp = _test_dashboard_menu( @@ -327,6 +330,7 @@ def test_menu_manage_api_keys(mocker, mock_get_service_templates, mock_get_jobs, mock_get_template_statistics, + mock_get_detailed_service, mock_get_usage): with app_.test_request_context(): resp = _test_dashboard_menu( @@ -358,6 +362,7 @@ def test_menu_all_services_for_platform_admin_user(mocker, mock_get_service_templates, mock_get_jobs, mock_get_template_statistics, + mock_get_detailed_service, mock_get_usage): with app_.test_request_context(): resp = _test_dashboard_menu( @@ -386,6 +391,7 @@ def test_route_for_service_permissions(mocker, mock_get_jobs, mock_get_service_statistics, mock_get_template_statistics, + mock_get_detailed_service, mock_get_usage): routes = [ 'main.service_dashboard'] @@ -424,10 +430,10 @@ def test_service_dashboard_updates_gets_dashboard_totals(mocker, mock_get_user, mock_get_service_templates, mock_get_template_statistics, + mock_get_detailed_service, mock_get_jobs, mock_get_service_statistics, - mock_get_usage, - mock_get_detailed_service): + mock_get_usage): dashboard_totals = mocker.patch('app.main.views.dashboard.get_dashboard_totals', return_value={ 'email': {'requested': 0, 'delivered': 0, 'failed': 0}, 'sms': {'requested': 0, 'delivered': 0, 'failed': 0} diff --git a/tests/app/main/views/test_sign_out.py b/tests/app/main/views/test_sign_out.py index 11dd86a96..6cfe07a38 100644 --- a/tests/app/main/views/test_sign_out.py +++ b/tests/app/main/views/test_sign_out.py @@ -21,6 +21,7 @@ def test_sign_out_user(app_, mock_get_jobs, mock_has_permissions, mock_get_template_statistics, + mock_get_detailed_service, mock_get_usage): with app_.test_request_context(): with app_.test_client() as client: diff --git a/tests/conftest.py b/tests/conftest.py index 106924dfd..4e373241b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -67,14 +67,15 @@ def mock_get_service(mocker, api_user_active): @pytest.fixture(scope='function') def mock_get_detailed_service(mocker, api_user_active): def _get(service_id): - service = service_json( - service_id, "Test Service", [api_user_active.id], message_limit=1000, - active=False, restricted=True) - service['statistics'] = { - 'email': {'requested': 0, 'delivered': 0, 'failed': 0}, - 'sms': {'requested': 0, 'delivered': 0, 'failed': 0} + return { + 'data': { + 'id': service_id, + 'statistics': { + 'email': {'requested': 0, 'delivered': 0, 'failed': 0}, + 'sms': {'requested': 0, 'delivered': 0, 'failed': 0} + } + } } - return {'data': service} return mocker.patch('app.service_api_client.get_detailed_service', side_effect=_get)