mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 15:57:23 -04:00
more test fixes & letter trimming
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user