From 31a032e678ac6f0d5c87a2706710260c5fc80d0c Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 25 Aug 2016 16:49:31 +0100 Subject: [PATCH] Show message on job page if job is scheduled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a job is scheduled then we can’t show the notifications yet, and the progress report will stay at 0%. In their place we should show what time a job will start. Later on (when the API is ready) this area of the page should also show a cancel button. --- app/main/views/jobs.py | 6 +- .../partials/jobs/notifications.html | 116 ++++++++++-------- tests/app/main/views/test_jobs.py | 23 ++++ tests/conftest.py | 14 +++ 4 files changed, 103 insertions(+), 56 deletions(-) diff --git a/app/main/views/jobs.py b/app/main/views/jobs.py index a9739a3f8..af6b2d8d7 100644 --- a/app/main/views/jobs.py +++ b/app/main/views/jobs.py @@ -277,7 +277,7 @@ def get_status_filters(service, message_type, statistics): def _get_job_counts(job, help_argument): - sending = 0 if job['job_status'] == 'pending' else ( + sending = 0 if job['job_status'] == 'scheduled' else ( job.get('notification_count', 0) - job.get('notifications_delivered', 0) - job.get('notifications_failed', 0) @@ -324,7 +324,6 @@ def get_job_partials(job): return { 'counts': render_template( 'partials/jobs/count.html', - job=job, counts=_get_job_counts(job, request.args.get('help', 0)), status=filter_args['status'] ), @@ -340,7 +339,8 @@ def get_job_partials(job): status=request.args.get('status') ), help=get_help_argument(), - time_left=get_time_left(job['created_at']) + time_left=get_time_left(job['created_at']), + job=job ), 'status': render_template( 'partials/jobs/status.html', diff --git a/app/templates/partials/jobs/notifications.html b/app/templates/partials/jobs/notifications.html index 5ae3c8c2a..052d5b2ec 100644 --- a/app/templates/partials/jobs/notifications.html +++ b/app/templates/partials/jobs/notifications.html @@ -1,61 +1,71 @@ {% from "components/table.html" import list_table, field, right_aligned_field_heading, date_field, row_heading %} -{% if notifications %} -
-{% endif %} +{% if job.job_status == 'scheduled' %} - {% if not help %} - {% if percentage_complete < 100 %} -

- Report is {{ "{:.0f}%".format(percentage_complete) }} complete… -

- {% elif notifications %} -

- Download this report -   - {{ time_left }} +

+ Sending will start at {{ job.scheduled_for|format_time }} +

+ +{% else %} + + {% if notifications %} +
+ {% endif %} + + {% if not help %} + {% if percentage_complete < 100 %} +

+ Report is {{ "{:.0f}%".format(percentage_complete) }} complete… +

+ {% elif notifications %} +

+ Download this report +   + {{ time_left }} +

+ {% endif %} + {% endif %} + + {% call(item, row_number) list_table( + notifications, + caption=uploaded_file_name, + caption_visible=False, + empty_message="No messages to show", + field_headings=[ + 'Recipient', + 'Time', + 'Status' + ], + field_headings_visible=False + ) %} + {% call row_heading() %} + {{ item.to }} + {% endcall %} + {{ date_field( + (item.updated_at or item.created_at)|format_datetime_short + ) }} + {% call field( + align='right', + status=item.status|format_notification_status_as_field_status + ) %} + {% if item.status|format_notification_status_as_url %} + + {% endif %} + {{ item.status|format_notification_status(item.template.template_type) }} + {% if item.status|format_notification_status_as_url %} + + {% endif %} + {% endcall %} + {% endcall %} + + {% if more_than_one_page %} + {% endif %} + + {% if notifications %} +
{% endif %} - {% call(item, row_number) list_table( - notifications, - caption=uploaded_file_name, - caption_visible=False, - empty_message="No messages to show", - field_headings=[ - 'Recipient', - 'Time', - 'Status' - ], - field_headings_visible=False - ) %} - {% call row_heading() %} - {{ item.to }} - {% endcall %} - {{ date_field( - (item.updated_at or item.created_at)|format_datetime_short - ) }} - {% call field( - align='right', - status=item.status|format_notification_status_as_field_status - ) %} - {% if item.status|format_notification_status_as_url %} - - {% endif %} - {{ item.status|format_notification_status(item.template.template_type) }} - {% if item.status|format_notification_status_as_url %} - - {% endif %} - {% endcall %} - {% endcall %} - - {% if more_than_one_page %} - - {% endif %} - -{% if notifications %} -
{% endif %} diff --git a/tests/app/main/views/test_jobs.py b/tests/app/main/views/test_jobs.py index 405cb4c62..d3cd0b758 100644 --- a/tests/app/main/views/test_jobs.py +++ b/tests/app/main/views/test_jobs.py @@ -126,6 +126,29 @@ def test_should_show_job_in_progress( assert page.find('p', {'class': 'hint'}).text.strip() == 'Report is 50% complete…' +def test_should_show_scheduled_job( + app_, + service_one, + active_user_with_permissions, + mock_get_service_template, + mock_get_scheduled_job, + mocker, + mock_get_notifications, + fake_uuid +): + with app_.test_request_context(), app_.test_client() as client: + client.login(active_user_with_permissions, mocker, service_one) + response = client.get(url_for( + 'main.view_job', + service_id=service_one['id'], + job_id=fake_uuid + )) + + assert response.status_code == 200 + page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') + assert page.find('main').find_all('p')[2].text.strip() == 'Sending will start at midnight' + + def test_should_show_not_show_csv_download_in_tour( app_, service_one, diff --git a/tests/conftest.py b/tests/conftest.py index 298dfb451..dbd9b6f9c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -858,6 +858,20 @@ def mock_get_job(mocker, api_user_active): return mocker.patch('app.job_api_client.get_job', side_effect=_get_job) +@pytest.fixture(scope='function') +def mock_get_scheduled_job(mocker, api_user_active): + def _get_job(service_id, job_id): + return {"data": job_json( + service_id, + api_user_active, + job_id=job_id, + job_status='scheduled', + scheduled_for='2016-01-01T00:00:00.061258' + )} + + return mocker.patch('app.job_api_client.get_job', side_effect=_get_job) + + @pytest.fixture(scope='function') def mock_get_job_in_progress(mocker, api_user_active): def _get_job(service_id, job_id):