diff --git a/app/main/views/jobs.py b/app/main/views/jobs.py index 9905c912f..394b98d72 100644 --- a/app/main/views/jobs.py +++ b/app/main/views/jobs.py @@ -112,29 +112,6 @@ def cancel_job(service_id, job_id): return redirect(url_for('main.service_dashboard', service_id=service_id)) -@main.route("/services//jobs//cancel", methods=['GET', 'POST']) -@user_has_permissions() -def cancel_letter_job(service_id, job_id): - if request.method == 'POST': - job = Job.from_id(job_id, service_id=service_id) - - if job.status != 'finished' or job.notifications_created < job.notification_count: - flash("We are still processing these letters, please try again in a minute.", 'try again') - return view_job(service_id, job_id) - try: - number_of_letters = job.cancel() - except HTTPError as e: - flash(e.message, 'dangerous') - return redirect(url_for('main.view_job', service_id=service_id, job_id=job_id)) - flash("Cancelled {} letters from {}".format( - format_thousands(number_of_letters), job.original_file_name - ), 'default_with_tick') - return redirect(url_for('main.service_dashboard', service_id=service_id)) - - flash("Are you sure you want to cancel sending these letters?", 'cancel') - return view_job(service_id, job_id) - - @main.route("/services//jobs/.json") @user_has_permissions() def view_job_updates(service_id, job_id): diff --git a/app/main/views/notifications.py b/app/main/views/notifications.py index f4550d6ee..302a86161 100644 --- a/app/main/views/notifications.py +++ b/app/main/views/notifications.py @@ -185,31 +185,6 @@ def view_notification(service_id, notification_id): ) -@main.route("/services//notification//cancel", methods=['GET', 'POST']) -@user_has_permissions('view_activity', 'send_messages') -def cancel_letter(service_id, notification_id): - - if request.method == 'POST': - try: - notification_api_client.update_notification_to_cancelled(current_service.id, notification_id) - except HTTPError as e: - message_fragments = ["already been cancelled", "too late to cancel"] - if e.status_code == 400 and any(fragment in e.message for fragment in message_fragments): - flash(e.message) - else: - raise e - return redirect(url_for('main.view_notification', service_id=service_id, notification_id=notification_id)) - - flash("Are you sure you want to cancel sending this letter?", 'cancel') - return view_notification(service_id, notification_id) - - -def get_preview_error_image(): - path = os.path.join(os.path.dirname(__file__), "..", "..", "static", "images", "preview_error.png") - with open(path, "rb") as file: - return file.read() - - @main.route("/services//notification/.") @user_has_permissions('view_activity', 'send_messages') def view_letter_notification_as_preview( diff --git a/app/models/job.py b/app/models/job.py index 9a5e6dc2c..dacb1264c 100644 --- a/app/models/job.py +++ b/app/models/job.py @@ -199,10 +199,7 @@ class Job(JSONModel): ) def cancel(self): - if self.template_type == 'letter': - return job_api_client.cancel_letter_job(self.service, self.id) - else: - return job_api_client.cancel_job(self.service, self.id) + return job_api_client.cancel_job(self.service, self.id) class ImmediateJobs(ModelList): diff --git a/app/notify_client/job_api_client.py b/app/notify_client/job_api_client.py index ee9dc0022..7fd8af213 100644 --- a/app/notify_client/job_api_client.py +++ b/app/notify_client/job_api_client.py @@ -115,12 +115,5 @@ class JobApiClient(NotifyAdminAPIClient): data={} ) - @cache.delete('has_jobs-{service_id}') - def cancel_letter_job(self, service_id, job_id): - return self.post( - url='/service/{}/job/{}/cancel-letter-job'.format(service_id, job_id), - data={} - ) - job_api_client = JobApiClient() diff --git a/app/templates/views/jobs/job.html b/app/templates/views/jobs/job.html index 13f8c05eb..f7895a29c 100644 --- a/app/templates/views/jobs/job.html +++ b/app/templates/views/jobs/job.html @@ -9,10 +9,6 @@ {{ job.original_file_name }} {% endblock %} -{% block backLink %} - {{ govukBackLink({ "href": url_for('main.uploads', service_id=current_service.id) }) }} -{% endblock %} - {% block maincolumn_content %} {{ page_header(job.original_file_name) }} diff --git a/app/templates/views/notifications/notification.html b/app/templates/views/notifications/notification.html index cc0405b49..34296c689 100644 --- a/app/templates/views/notifications/notification.html +++ b/app/templates/views/notifications/notification.html @@ -50,20 +50,7 @@ {{ template|string }} - {% if template.template_type == 'letter' %} -
- -
- {% elif template.template_type == 'email' %} + {% if template.template_type == 'email' %}
{{ ajax_block(partials, updates_url, 'status', finished=finished) }}
diff --git a/tests/app/main/views/test_conversation.py b/tests/app/main/views/test_conversation.py index b94af8b27..b8247e443 100644 --- a/tests/app/main/views/test_conversation.py +++ b/tests/app/main/views/test_conversation.py @@ -73,7 +73,7 @@ def test_get_user_phone_number_raises_if_both_api_requests_fail(mocker): (True, 'Hello hidden'), (False, 'Hello Jo'), ]) -@freeze_time("2012-01-01 00:00:00") +@freeze_time("2012-01-01 05:00:00") def test_view_conversation( client_request, mocker, diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index dc726d538..4751ed68c 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -230,7 +230,7 @@ def test_inbound_messages_shows_count_of_messages_when_there_are_messages( banner = page.select('a.banner-dashboard')[1] assert normalize_spaces( banner.text - ) == '9,999 text messages received latest message just now' + ) == '9,999 text messages received latest message 5 hours ago' assert banner['href'] == url_for( 'main.inbox', service_id=SERVICE_ONE_ID ) @@ -264,14 +264,14 @@ def test_inbound_messages_shows_count_of_messages_when_there_are_no_messages( @pytest.mark.parametrize('index, expected_row', enumerate([ - '07900 900000 message-1 1 hour ago', - '07900 900000 message-2 1 hour ago', - '07900 900000 message-3 1 hour ago', - '07900 900002 message-4 3 hours ago', - '+33 1 12 34 56 78 message-5 5 hours ago', - '+1 202-555-0104 message-6 7 hours ago', - '+1 202-555-0104 message-7 9 hours ago', - '+682 12345 message-8 9 hours ago', + '07900 900000 message-1 6 hours ago', + '07900 900000 message-2 6 hours ago', + '07900 900000 message-3 6 hours ago', + '07900 900002 message-4 8 hours ago', + '+33 1 12 34 56 78 message-5 10 hours ago', + '+1 202-555-0104 message-6 12 hours ago', + '+1 202-555-0104 message-7 14 hours ago', + '+682 12345 message-8 14 hours ago', ])) def test_inbox_showing_inbound_messages( client_request, @@ -411,7 +411,7 @@ def test_view_inbox_updates( mock_get_partials.assert_called_once_with(SERVICE_ONE_ID) -@freeze_time("2016-07-01 13:00") +@freeze_time("2016-07-01 18:00") def test_download_inbox( client_request, mock_get_inbound_sms, @@ -498,115 +498,6 @@ def test_returned_letters_not_visible_if_service_has_no_returned_letters( assert not page.select('#total-returned-letters') -@pytest.mark.parametrize('reporting_date, expected_message', ( - ('2020-01-10 00:00:00.000000', ( - '4,000 returned letters latest report today' - )), - ('2020-01-09 23:59:59.000000', ( - '4,000 returned letters latest report yesterday' - )), - ('2020-01-08 12:12:12.000000', ( - '4,000 returned letters latest report 2 days ago' - )), - ('2019-12-10 00:00:00.000000', ( - '4,000 returned letters latest report 1 month ago' - )), -)) -@freeze_time('2020-01-10 12:34:00.000000') -def test_returned_letters_shows_count_of_recently_returned_letters( - client_request, - mocker, - service_one, - mock_get_service_templates_when_no_templates_exist, - mock_get_jobs, - mock_get_scheduled_job_stats, - mock_get_service_statistics, - mock_get_template_statistics, - mock_get_annual_usage_for_service, - mock_get_free_sms_fragment_limit, - mock_get_inbound_sms_summary, - reporting_date, - expected_message, -): - mocker.patch( - 'app.service_api_client.get_returned_letter_statistics', - return_value={ - 'returned_letter_count': 4000, - 'most_recent_report': reporting_date, - }, - ) - page = client_request.get( - 'main.service_dashboard', - service_id=SERVICE_ONE_ID, - ) - banner = page.select_one('#total-returned-letters') - assert normalize_spaces(banner.text) == expected_message - assert banner['href'] == url_for( - 'main.returned_letter_summary', service_id=SERVICE_ONE_ID - ) - - -@pytest.mark.parametrize('reporting_date, count, expected_message', ( - ('2020-02-02', 1, ( - '1 returned letter latest report today' - )), - ('2020-02-01', 1, ( - '1 returned letter latest report yesterday' - )), - ('2020-01-31', 1, ( - '1 returned letter latest report 2 days ago' - )), - ('2020-01-26', 1, ( - '1 returned letter latest report 7 days ago' - )), - ('2020-01-25', 0, ( - '0 returned letters latest report 8 days ago' - )), - ('2020-01-01', 0, ( - '0 returned letters latest report 1 month ago' - )), - ('2019-09-09', 0, ( - '0 returned letters latest report 4 months ago' - )), - ('2010-10-10', 0, ( - '0 returned letters latest report 9 years ago' - )), -)) -@freeze_time('2020-02-02') -def test_returned_letters_only_counts_recently_returned_letters( - client_request, - mocker, - service_one, - mock_get_service_templates_when_no_templates_exist, - mock_get_jobs, - mock_get_scheduled_job_stats, - mock_get_service_statistics, - mock_get_template_statistics, - mock_get_annual_usage_for_service, - mock_get_free_sms_fragment_limit, - mock_get_inbound_sms_summary_with_no_messages, - reporting_date, - count, - expected_message, -): - mocker.patch( - 'app.service_api_client.get_returned_letter_statistics', - return_value={ - 'returned_letter_count': count, - 'most_recent_report': reporting_date, - }, - ) - page = client_request.get( - 'main.service_dashboard', - service_id=SERVICE_ONE_ID, - ) - banner = page.select_one('#total-returned-letters') - assert normalize_spaces(banner.text) == expected_message - assert banner['href'] == url_for( - 'main.returned_letter_summary', service_id=SERVICE_ONE_ID - ) - - def test_should_show_recent_templates_on_dashboard( client_request, mocker, @@ -846,7 +737,7 @@ def test_should_show_upcoming_jobs_on_dashboard( page.select_one('a.banner-dashboard').text ) == ( '2 files waiting to send ' - 'sending starts today at 11:09am' + 'sending starts today at 6:09am' ) assert page.select_one('a.banner-dashboard')['href'] == url_for( diff --git a/tests/app/main/views/test_find_users.py b/tests/app/main/views/test_find_users.py index 3d117545a..fd209de97 100644 --- a/tests/app/main/views/test_find_users.py +++ b/tests/app/main/views/test_find_users.py @@ -121,7 +121,7 @@ def test_user_information_page_shows_information_about_user( 'test@gsa.gov', '+447700900986', 'Text message code', - 'Last logged in just now', + 'Last logged in 5 hours ago', ] assert '0 failed login attempts' not in page.text diff --git a/tests/app/main/views/test_jobs.py b/tests/app/main/views/test_jobs.py index bc4a576ba..ac0967c8a 100644 --- a/tests/app/main/views/test_jobs.py +++ b/tests/app/main/views/test_jobs.py @@ -64,7 +64,7 @@ def test_old_jobs_hub_redirects( ) ] ) -@freeze_time("2016-01-01 11:09:00.061258") +@freeze_time("2016-01-01 16:09:00.061258") def test_should_show_page_for_one_job( client_request, mock_get_service_template, @@ -86,9 +86,6 @@ def test_should_show_page_for_one_job( ) assert page.h1.text.strip() == 'thisisatest.csv' - assert page.select_one('.govuk-back-link')['href'] == url_for( - 'main.uploads', service_id=SERVICE_ONE_ID, - ) assert ' '.join(page.find('tbody').find('tr').text.split()) == ( '07123456789 template content Delivered 1 January at 11:10am' ) @@ -259,7 +256,7 @@ def test_should_show_job_with_sending_limit_exceeded_status( 'No messages to show yet…' )), # Created a while ago, started just within the last 24h - (datetime(2020, 1, 1, 0, 0, 0), datetime(2020, 1, 9, 1, 0, 1), ( + (datetime(2020, 1, 1, 12, 0, 0), datetime(2020, 1, 9, 6, 0, 1), ( 'No messages to show yet…' )), # Created a while ago, started exactly 24h ago @@ -317,148 +314,7 @@ def test_should_show_old_job( ] -@freeze_time("2016-01-01 11:09:00.061258") -def test_should_show_letter_job( - client_request, - mock_get_service_letter_template, - mock_get_letter_job, - mock_get_service_data_retention, - fake_uuid, - mocker, -): - notifications = create_notifications(template_type='letter', subject='template subject') - get_notifications = mocker.patch( - 'app.notification_api_client.get_notifications_for_service', - return_value=notifications, - ) - - page = client_request.get( - 'main.view_job', - service_id=SERVICE_ONE_ID, - job_id=fake_uuid, - ) - assert normalize_spaces(page.h1.text) == 'thisisatest.csv' - assert normalize_spaces(page.select('p.bottom-gutter')[0].text) == ( - 'Sent by Test User on 1 January at 11:09am Printing starts today at 5:30pm' - ) - assert page.select('.banner-default-with-tick') == [] - assert normalize_spaces(page.select('tbody tr')[0].text) == ( - '1 Example Street template subject 1 January at 11:09am' - ) - assert normalize_spaces(page.select('.keyline-block')[0].text) == ( - '1 Letter' - ) - assert normalize_spaces(page.select('.keyline-block')[1].text) == ( - '6 January Estimated delivery date' - ) - assert page.select_one('a[download]')['href'] == url_for( - 'main.view_job_csv', - service_id=SERVICE_ONE_ID, - job_id=fake_uuid, - ) - assert page.select('.hint') == [] - - get_notifications.assert_called_with( - SERVICE_ONE_ID, - fake_uuid, - status=[ - 'created', - 'pending', - 'sending', - 'pending-virus-check', - 'delivered', - 'sent', - 'returned-letter', - 'failed', - 'temporary-failure', - 'permanent-failure', - 'technical-failure', - 'virus-scan-failed', - 'validation-failed' - ], - ) - - -@freeze_time("2016-01-01 11:09:00") -def test_should_show_letter_job_with_banner_after_sending_before_1730( - mocker, - client_request, - mock_get_service_letter_template, - mock_get_letter_job, - mock_get_service_data_retention, - fake_uuid, -): - mocker.patch( - 'app.notification_api_client.get_notifications_for_service', - return_value=create_notifications(template_type='letter', postage='second') - ) - - page = client_request.get( - 'main.view_job', - service_id=SERVICE_ONE_ID, - job_id=fake_uuid, - ) - - assert page.select('p.bottom-gutter') == [] - assert normalize_spaces(page.select('.banner-default-with-tick')[0].text) == ( - 'Your letter has been sent. Printing starts today at 5:30pm.' - ) - assert not page.select_one('.govuk-back-link') - - -@freeze_time("2016-01-01 11:09:00") -def test_should_show_letter_job_with_banner_when_there_are_multiple_CSV_rows( - mocker, - client_request, - mock_get_service_letter_template, - mock_get_letter_job_in_progress, - mock_get_service_data_retention, - fake_uuid, -): - mocker.patch( - 'app.notification_api_client.get_notifications_for_service', - return_value=create_notifications(template_type='letter', postage='second') - ) - - page = client_request.get( - 'main.view_job', - service_id=SERVICE_ONE_ID, - job_id=fake_uuid, - ) - - assert page.select('p.bottom-gutter') == [] - assert normalize_spaces(page.select('.banner-default-with-tick')[0].text) == ( - 'Your letters have been sent. Printing starts today at 5:30pm.' - ) - - -@freeze_time("2016-01-01 18:09:00") -def test_should_show_letter_job_with_banner_after_sending_after_1730( - mocker, - client_request, - mock_get_service_letter_template, - mock_get_letter_job, - mock_get_service_data_retention, - fake_uuid, -): - mocker.patch( - 'app.notification_api_client.get_notifications_for_service', - return_value=create_notifications(template_type='letter', postage='second') - ) - - page = client_request.get( - 'main.view_job', - service_id=SERVICE_ONE_ID, - job_id=fake_uuid, - ) - - assert page.select('p.bottom-gutter') == [] - assert normalize_spaces(page.select('.banner-default-with-tick')[0].text) == ( - 'Your letter has been sent. Printing starts tomorrow at 5:30pm.' - ) - - -@freeze_time("2016-01-01T00:00:00.061258") +@freeze_time("2016-01-01T05:00:00.061258") def test_should_show_scheduled_job( client_request, mock_get_service_template, @@ -483,7 +339,6 @@ def test_should_show_scheduled_job( version=1, ) assert page.select_one('main button[type=submit]').text.strip() == 'Cancel sending' - assert not page.select_one('.govuk-back-link') def test_should_cancel_job( @@ -522,159 +377,7 @@ def test_should_not_show_cancelled_job( ) -def test_should_cancel_letter_job( - client_request, - mocker, - mock_get_service_letter_template, - active_user_with_permissions -): - job_id = str(uuid.uuid4()) - job = job_json( - SERVICE_ONE_ID, - active_user_with_permissions, - job_id=job_id, - created_at="2019-06-20T15:30:00.000001+00:00", - job_status="finished", - template_type="letter", - ) - mocker.patch('app.job_api_client.get_job', side_effect=[{"data": job}]) - notifications_json = notification_json(SERVICE_ONE_ID, job=job, status="created", template_type="letter") - mocker.patch('app.job_api_client.get_job', side_effect=[{"data": job}]) - mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications_json) - mocker.patch('app.notification_api_client.get_notification_count_for_job_id', return_value=5) - mock_cancel = mocker.patch('app.job_api_client.cancel_letter_job', return_value=5) - client_request.post( - 'main.cancel_letter_job', - service_id=SERVICE_ONE_ID, - job_id=job_id, - _expected_status=302, - _expected_redirect=url_for( - 'main.service_dashboard', - service_id=SERVICE_ONE_ID, - ) - ) - mock_cancel.assert_called_once_with(SERVICE_ONE_ID, job_id) - - -@freeze_time("2019-06-20 17:30:00.000001") -@pytest.mark.parametrize("job_created_at, expected_fragment", [ - ("2019-06-20T15:30:00.000001+00:00", "today"), - ("2019-06-19T15:30:00.000001+00:00", "yesterday"), - ("2019-06-18T15:30:00.000001+00:00", "on 18 June"), -]) -def test_should_not_show_cancel_link_for_letter_job_if_too_late( - client_request, - mocker, - mock_get_service_letter_template, - mock_get_service_data_retention, - active_user_with_permissions, - job_created_at, - expected_fragment, -): - job_id = uuid.uuid4() - job = job_json( - SERVICE_ONE_ID, active_user_with_permissions, job_id=job_id, created_at=job_created_at - ) - notifications_json = notification_json(SERVICE_ONE_ID, job=job, status="created", template_type="letter") - mocker.patch('app.job_api_client.get_job', side_effect=[{"data": job}]) - mocker.patch( - 'app.notification_api_client.get_notifications_for_service', - return_value=notifications_json - ) - - page = client_request.get( - 'main.view_job', - service_id=SERVICE_ONE_ID, - job_id=str(job_id) - ) - - assert "Cancel sending these letters" not in page - assert page.find('p', {'id': 'printing-info'}).text.strip() == "Printed {} at 5:30pm".format(expected_fragment) - - -@freeze_time("2019-06-20 15:32:00.000001") -@pytest.mark.parametrize(" job_status", [ - "finished", "in progress" -]) -def test_should_show_cancel_link_for_letter_job( - client_request, - mocker, - mock_get_service_letter_template, - mock_get_service_data_retention, - active_user_with_permissions, - job_status, -): - job_id = uuid.uuid4() - job = job_json( - SERVICE_ONE_ID, - active_user_with_permissions, - job_id=job_id, - created_at="2019-06-20T15:30:00.000001+00:00", - job_status=job_status - ) - notifications_json = notification_json(SERVICE_ONE_ID, job=job, status="created", template_type="letter") - mocker.patch('app.job_api_client.get_job', side_effect=[{"data": job}]) - mocker.patch( - 'app.notification_api_client.get_notifications_for_service', - return_value=notifications_json, - ) - - page = client_request.get( - 'main.view_job', - service_id=SERVICE_ONE_ID, - job_id=str(job_id) - ) - - assert page.find('a', text='Cancel sending these letters').attrs["href"] == url_for( - "main.cancel_letter_job", service_id=SERVICE_ONE_ID, job_id=job_id - ) - assert page.find('p', {'id': 'printing-info'}).text.strip() == "Printing starts today at 5:30pm" - - -@freeze_time("2019-06-20 15:31:00.000001") -@pytest.mark.parametrize('job_status,number_of_processed_notifications', [['in progress', 2], ['finished', 1]]) -def test_dont_cancel_letter_job_when_to_early_to_cancel( - client_request, - mocker, - mock_get_service_letter_template, - mock_get_service_data_retention, - active_user_with_permissions, - job_status, - number_of_processed_notifications, -): - job_id = uuid.uuid4() - job = job_json( - SERVICE_ONE_ID, - active_user_with_permissions, - job_id=job_id, - created_at="2019-06-20T15:30:00.000001+00:00", - job_status=job_status, - notification_count=2 - ) - mocker.patch('app.job_api_client.get_job', side_effect=[{"data": job}, {"data": job}]) - - notifications_json = notification_json( - SERVICE_ONE_ID, job=job, status="created", template_type="letter", rows=number_of_processed_notifications - ) - mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications_json) - mocker.patch( - 'app.notification_api_client.get_notification_count_for_job_id', return_value=number_of_processed_notifications - ) - - mock_cancel = mocker.patch('app.job_api_client.cancel_letter_job') - page = client_request.post( - 'main.cancel_letter_job', - service_id=SERVICE_ONE_ID, - job_id=str(job_id), - _expected_status=200, - ) - assert mock_cancel.called is False - flash_message = normalize_spaces(page.find('div', class_='banner-dangerous').text) - - assert 'We are still processing these letters, please try again in a minute.' in flash_message - - -@freeze_time("2016-01-01 00:00:00.000001") +@freeze_time("2016-01-01 05:00:00.000001") def test_should_show_updates_for_one_job_as_json( client_request, service_one, @@ -704,7 +407,7 @@ def test_should_show_updates_for_one_job_as_json( assert 'Sent by Test User on 1 January at midnight' in content['status'] -@freeze_time("2016-01-01 00:00:00.000001") +@freeze_time("2016-01-01 05:00:00.000001") def test_should_show_updates_for_scheduled_job_as_json( client_request, service_one, @@ -719,8 +422,8 @@ def test_should_show_updates_for_scheduled_job_as_json( service_one['id'], created_by=user_json(), job_id=fake_uuid, - scheduled_for='2016-06-01T13:00:00+00:00', - processing_started='2016-06-01T15:00:00+00:00', + scheduled_for='2016-06-01T18:00:00+00:00', + processing_started='2016-06-01T20:00:00+00:00', )}) response = client_request.get_response( diff --git a/tests/app/main/views/test_notifications.py b/tests/app/main/views/test_notifications.py index ee4153992..fdcd862c4 100644 --- a/tests/app/main/views/test_notifications.py +++ b/tests/app/main/views/test_notifications.py @@ -922,96 +922,6 @@ def test_should_show_image_of_precompiled_letter_notification( assert mock_pdf_page_count.called_once() -@freeze_time('2016-01-01 15:00') -def test_show_cancel_letter_confirmation( - client_request, - mocker, - fake_uuid, -): - notification = create_notification(template_type='letter', notification_status='created') - mocker.patch('app.notification_api_client.get_notification', return_value=notification) - mocker.patch( - 'app.main.views.notifications.get_page_count_for_letter', - return_value=1 - ) - - page = client_request.get( - 'main.cancel_letter', - service_id=SERVICE_ONE_ID, - notification_id=fake_uuid, - ) - - flash_message = normalize_spaces(page.find('div', class_='banner-dangerous').text) - - assert 'Are you sure you want to cancel sending this letter?' in flash_message - - -@freeze_time('2016-01-01 15:00') -def test_cancelling_a_letter_calls_the_api( - client_request, - mocker, - fake_uuid, -): - notification = create_notification(template_type='letter', notification_status='created') - mocker.patch('app.notification_api_client.get_notification', return_value=notification) - mocker.patch( - 'app.main.views.notifications.get_page_count_for_letter', - return_value=1 - ) - cancel_endpoint = mocker.patch( - 'app.main.views.notifications.notification_api_client.update_notification_to_cancelled' - ) - - client_request.post( - 'main.cancel_letter', - service_id=SERVICE_ONE_ID, - notification_id=fake_uuid, - _follow_redirects=True, - _expected_redirect=None, - ) - - assert cancel_endpoint.called - - -@freeze_time('2016-01-01 15:00') -@pytest.mark.parametrize('error_message', [ - "It’s too late to cancel this letter. Printing started on 1 January at 5.30pm", - "This letter has already been cancelled", - pytest.param("other message", marks=pytest.mark.xfail()) -]) -def test_cancel_letter_catches_errors_from_API( - client_request, - mocker, - fake_uuid, - error_message -): - notification = create_notification(template_type='letter', notification_status='created') - mocker.patch('app.notification_api_client.get_notification', return_value=notification) - mocker.patch( - 'app.main.views.notifications.get_page_count_for_letter', - return_value=1 - ) - mocker.patch( - 'app.main.views.notifications.notification_api_client.update_notification_to_cancelled', - side_effect=HTTPError(response=Mock( - status_code=400, - json=Mock( - return_value={'message': error_message} - ) - )) - ) - - page = client_request.post( - 'main.cancel_letter', - service_id=SERVICE_ONE_ID, - notification_id=fake_uuid, - _follow_redirects=True, - ) - - assert page.find('h1').text.strip() == "Letter" - assert page.select_one('div.banner-dangerous').text.strip() == error_message - - @pytest.mark.parametrize('notification_type', ['sms', 'email']) def test_should_show_reply_to_from_notification( mocker, diff --git a/tests/app/test_navigation.py b/tests/app/test_navigation.py index 276fe638b..8be15d9c6 100644 --- a/tests/app/test_navigation.py +++ b/tests/app/test_navigation.py @@ -34,8 +34,6 @@ EXCLUDED_ENDPOINTS = tuple(map(Navigation.get_endpoint_with_blueprint, { 'cancel_invited_org_user', 'cancel_invited_user', 'cancel_job', - 'cancel_letter', - 'cancel_letter_job', 'change_user_auth', 'check_and_resend_text_code', 'check_and_resend_verification_code', diff --git a/tests/conftest.py b/tests/conftest.py index d0853fca4..3c699dc1a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1471,7 +1471,7 @@ def mock_get_scheduled_job(mocker, api_user_active): api_user_active, job_id=job_id, job_status='scheduled', - scheduled_for='2016-01-02T00:00:00.061258' + scheduled_for='2016-01-02T05:00:00.061258' )} return mocker.patch('app.job_api_client.get_job', side_effect=_get_job) @@ -3368,20 +3368,20 @@ def mock_get_service_history(mocker): 'service_history': [ { 'name': 'Example service', - 'created_at': '2010-10-10T01:01:01.000000Z', + 'created_at': '2010-10-10T06:01:01.000000Z', 'updated_at': None, 'created_by_id': uuid4(), }, { 'name': 'Before lunch', - 'created_at': '2010-10-10T01:01:01.000000Z', - 'updated_at': '2012-12-12T12:12:12.000000Z', + 'created_at': '2010-10-10T06:01:01.000000Z', + 'updated_at': '2012-12-12T17:12:12.000000Z', 'created_by_id': sample_uuid(), }, { 'name': 'After lunch', - 'created_at': '2010-10-10T01:01:01.000000Z', - 'updated_at': '2012-12-12T13:13:13.000000Z', + 'created_at': '2010-10-10T06:01:01.000000Z', + 'updated_at': '2012-12-12T18:13:13.000000Z', 'created_by_id': sample_uuid(), }, ], @@ -3389,25 +3389,25 @@ def mock_get_service_history(mocker): { 'name': 'Good key', 'updated_at': None, - 'created_at': '2010-10-10T10:10:10.000000Z', + 'created_at': '2010-10-10T15:10:10.000000Z', 'created_by_id': sample_uuid(), }, { 'name': 'Bad key', - 'updated_at': '2012-11-11T12:12:12.000000Z', - 'created_at': '2011-11-11T11:11:11.000000Z', + 'updated_at': '2012-11-11T17:12:12.000000Z', + 'created_at': '2011-11-11T16:11:11.000000Z', 'created_by_id': sample_uuid(), }, { 'name': 'Bad key', 'updated_at': None, - 'created_at': '2011-11-11T11:11:11.000000Z', + 'created_at': '2011-11-11T16:11:11.000000Z', 'created_by_id': sample_uuid(), }, { 'name': 'Key event returned in non-chronological order', 'updated_at': None, - 'created_at': '2010-10-10T09:09:09.000000Z', + 'created_at': '2010-10-10T14:09:09.000000Z', 'created_by_id': sample_uuid(), }, ],