mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 14:09:20 -04:00
Letter job can't be cancelled if already printed
Non-cancellable letter statuses mean that it's too late to cancel a job
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
import json
|
||||
|
||||
import pytest
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
from flask import url_for
|
||||
from freezegun import freeze_time
|
||||
|
||||
from app.main.views.jobs import get_time_left
|
||||
from tests import sample_uuid
|
||||
from tests import job_json, notification_json, sample_uuid
|
||||
from tests.conftest import (
|
||||
SERVICE_ONE_ID,
|
||||
active_caseworking_user,
|
||||
@@ -321,7 +320,7 @@ def test_should_show_letter_job(
|
||||
)
|
||||
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'
|
||||
'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) == (
|
||||
@@ -508,6 +507,50 @@ def test_should_cancel_letter_job(
|
||||
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',
|
||||
side_effect=[notifications_json]
|
||||
)
|
||||
|
||||
page = client_request.get(
|
||||
'main.view_job',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
job_id=str(job_id)
|
||||
)
|
||||
|
||||
assert "Cancel sending those letters" not in page
|
||||
assert page.find('p', {'id': 'printing-info'}).text.strip() == "Printed {} at 5:30pm".format(expected_fragment)
|
||||
|
||||
|
||||
def test_dont_cancel_letter_job_when_to_early_to_cancel():
|
||||
pass
|
||||
|
||||
|
||||
def test_page_when_user_clicks_cancel_link_letter_job_and_to_early_to_cancel():
|
||||
pass
|
||||
|
||||
|
||||
@freeze_time("2016-01-01 00:00:00.000001")
|
||||
def test_should_show_updates_for_one_job_as_json(
|
||||
logged_in_client,
|
||||
|
||||
@@ -9,7 +9,6 @@ from freezegun import freeze_time
|
||||
from notifications_python_client.errors import APIError
|
||||
from PyPDF2.utils import PdfReadError
|
||||
|
||||
from app.main.views.notifications import get_letter_printing_statement
|
||||
from tests.conftest import (
|
||||
SERVICE_ONE_ID,
|
||||
active_caseworking_user,
|
||||
@@ -757,42 +756,6 @@ def test_should_show_image_of_precompiled_letter_notification(
|
||||
assert mock_pdf_page_count.called_once()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('created_at, current_datetime', [
|
||||
('2017-07-07T12:00:00+00:00', '2017-07-07 16:29:00'), # created today, summer
|
||||
('2017-12-12T12:00:00+00:00', '2017-12-12 17:29:00'), # created today, winter
|
||||
('2017-12-12T21:30:00+00:00', '2017-12-13 17:29:00'), # created after 5:30 yesterday
|
||||
('2017-03-25T17:30:00+00:00', '2017-03-26 16:29:00'), # over clock change period on 2017-03-26
|
||||
])
|
||||
def test_get_letter_printing_statement_when_letter_prints_today(created_at, current_datetime):
|
||||
with freeze_time(current_datetime):
|
||||
statement = get_letter_printing_statement('created', created_at)
|
||||
|
||||
assert statement == 'Printing starts today at 5:30pm'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('created_at, current_datetime', [
|
||||
('2017-07-07T16:31:00+00:00', '2017-07-07 22:59:00'), # created today, summer
|
||||
('2017-12-12T17:31:00+00:00', '2017-12-12 23:59:00'), # created today, winter
|
||||
])
|
||||
def test_get_letter_printing_statement_when_letter_prints_tomorrow(created_at, current_datetime):
|
||||
with freeze_time(current_datetime):
|
||||
statement = get_letter_printing_statement('created', created_at)
|
||||
|
||||
assert statement == 'Printing starts tomorrow at 5:30pm'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('created_at, print_day', [
|
||||
('2017-07-06T16:30:00+00:00', '7 July'),
|
||||
('2017-12-01T00:00:00+00:00', '1 December'),
|
||||
('2017-03-26T12:00:00+00:00', '26 March'),
|
||||
])
|
||||
@freeze_time('2017-07-07 12:00:00')
|
||||
def test_get_letter_printing_statement_for_letter_that_has_been_sent(created_at, print_day):
|
||||
statement = get_letter_printing_statement('delivered', created_at)
|
||||
|
||||
assert statement == 'Printed on {}'.format(print_day)
|
||||
|
||||
|
||||
@freeze_time('2016-01-01 15:00')
|
||||
def test_show_cancel_letter_confirmation(
|
||||
client_request,
|
||||
|
||||
@@ -13,6 +13,7 @@ from app.utils import (
|
||||
generate_next_dict,
|
||||
generate_notifications_csv,
|
||||
generate_previous_dict,
|
||||
get_letter_printing_statement,
|
||||
get_logo_cdn_domain,
|
||||
printing_today_or_tomorrow,
|
||||
)
|
||||
@@ -367,3 +368,39 @@ def test_printing_today_or_tomorrow_returns_today(utc_datetime):
|
||||
def test_printing_today_or_tomorrow_returns_tomorrow(datetime):
|
||||
with freeze_time(datetime):
|
||||
assert printing_today_or_tomorrow() == 'tomorrow'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('created_at, current_datetime', [
|
||||
('2017-07-07T12:00:00+00:00', '2017-07-07 16:29:00'), # created today, summer
|
||||
('2017-12-12T12:00:00+00:00', '2017-12-12 17:29:00'), # created today, winter
|
||||
('2017-12-12T21:30:00+00:00', '2017-12-13 17:29:00'), # created after 5:30 yesterday
|
||||
('2017-03-25T17:31:00+00:00', '2017-03-26 16:29:00'), # over clock change period on 2017-03-26
|
||||
])
|
||||
def test_get_letter_printing_statement_when_letter_prints_today(created_at, current_datetime):
|
||||
with freeze_time(current_datetime):
|
||||
statement = get_letter_printing_statement('created', created_at)
|
||||
|
||||
assert statement == 'Printing starts today at 5:30pm'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('created_at, current_datetime', [
|
||||
('2017-07-07T16:31:00+00:00', '2017-07-07 22:59:00'), # created today, summer
|
||||
('2017-12-12T17:31:00+00:00', '2017-12-12 23:59:00'), # created today, winter
|
||||
])
|
||||
def test_get_letter_printing_statement_when_letter_prints_tomorrow(created_at, current_datetime):
|
||||
with freeze_time(current_datetime):
|
||||
statement = get_letter_printing_statement('created', created_at)
|
||||
|
||||
assert statement == 'Printing starts tomorrow at 5:30pm'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('created_at, print_day', [
|
||||
('2017-07-06T16:29:00+00:00', 'yesterday'),
|
||||
('2017-12-01T00:00:00+00:00', 'on 1 December'),
|
||||
('2017-03-26T12:00:00+00:00', 'on 26 March'),
|
||||
])
|
||||
@freeze_time('2017-07-07 12:00:00')
|
||||
def test_get_letter_printing_statement_for_letter_that_has_been_sent(created_at, print_day):
|
||||
statement = get_letter_printing_statement('delivered', created_at)
|
||||
|
||||
assert statement == 'Printed {} at 5:30pm'.format(print_day)
|
||||
|
||||
Reference in New Issue
Block a user