def test_should_expected_hint_for_letters( client_request, service_one, active_user_with_permissions, mock_get_service_statistics, mock_get_service_data_retention, mocker, fake_uuid, is_precompiled_letter, expected_hint, ): mock_get_notifications( mocker, active_user_with_permissions, is_precompiled_letter=is_precompiled_letter, ) page = client_request.get( "main.view_notifications", service_id=SERVICE_ONE_ID, message_type="letter", ) assert page.find("p", { "class": "file-list-hint" }).text.strip() == expected_hint
def test_letters_with_status_virus_scan_failed_shows_a_failure_description( mocker, active_user_with_permissions, logged_in_client, service_one, mock_get_service_statistics, ): mock_get_notifications(mocker, active_user_with_permissions, is_precompiled_letter=True, noti_status='virus-scan-failed') response = logged_in_client.get( url_for( 'main.view_notifications', service_id=service_one['id'], message_type='letter', status='', )) assert response.status_code == 200 page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') error_description = page.find('div', attrs={ 'class': 'table-field-status-error' }).text.strip() assert 'Virus detected\n' in error_description
def test_sending_status_hint_displays_correctly_on_notifications_page( client_request, service_one, active_user_with_permissions, mock_get_service_statistics, mock_get_service_data_retention, message_type, status, expected_hint_status, single_line, mocker, ): mock_get_notifications(mocker, True, diff_template_type=message_type, noti_status=status) page = client_request.get( "main.view_notifications", service_id=service_one["id"], message_type=message_type, ) assert normalize_spaces(page.select(".table-field-right-aligned") [0].text) == expected_hint_status assert bool(page.select(".align-with-message-body")) is single_line
def test_letters_with_status_virus_scan_failed_shows_a_failure_description( mocker, active_user_with_permissions, client_request, service_one, mock_get_service_statistics, mock_get_service_data_retention, ): mock_get_notifications( mocker, active_user_with_permissions, is_precompiled_letter=True, noti_status="virus-scan-failed", ) page = client_request.get( "main.view_notifications", service_id=service_one["id"], message_type="letter", status="", ) error_description = page.find("div", attrs={ "class": "table-field-status-error" }).text.strip() assert "Virus detected\n" in error_description
def test_should_not_have_link_to_view_letter_for_precompiled_letters_in_virus_states( client_request, api_user_active, fake_uuid, mock_has_permissions, mocker, status): mock_get_notifications(mocker, api_user_active, noti_status=status) page = client_request.get( 'main.api_integration', service_id=fake_uuid, ) assert not page.select_one('details a')
def test_letter_notifications_should_have_link_to_view_letter( client_request, api_user_active, fake_uuid, mock_has_permissions, mocker, template_type, has_links): mock_get_notifications(mocker, api_user_active, diff_template_type=template_type) page = client_request.get( 'main.api_integration', service_id=fake_uuid, ) assert (page.select_one('details a') is not None) == has_links
def test_letter_notifications_should_have_link_to_view_letter( client_request, api_user_active, mock_has_permissions, mocker, template_type, link_text, ): mock_get_notifications(mocker, api_user_active, diff_template_type=template_type) page = client_request.get( 'main.api_integration', service_id=SERVICE_ONE_ID, ) assert page.select_one('details a').text.strip() == link_text
def test_sending_status_hint_does_not_include_status_for_letters( client_request, service_one, active_user_with_permissions, mock_get_detailed_service, message_type, hint_status_visible, mocker): mock_get_notifications(mocker, True, diff_template_type=message_type) page = client_request.get('main.view_notifications', service_id=service_one['id'], message_type=message_type) if message_type == 'letter': assert normalize_spaces( page.select(".align-with-message-body") [0].text) == "27 September at 5:30pm" else: assert normalize_spaces( page.select(".align-with-message-body") [0].text) == "Delivered 27 September at 5:31pm"
def test_should_expected_hint_for_letters(logged_in_client, service_one, active_user_with_permissions, mock_get_service_statistics, mocker, fake_uuid, is_precompiled_letter, expected_hint): mock_get_notifications(mocker, active_user_with_permissions, is_precompiled_letter=is_precompiled_letter) response = logged_in_client.get( url_for('main.view_notifications', service_id=SERVICE_ONE_ID, message_type='letter')) page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') assert page.find('p', { 'class': 'file-list-hint' }).text.strip() == expected_hint
def test_letter_notifications_should_show_client_reference( client_request, api_user_active, fake_uuid, mock_has_permissions, mocker, client_reference, shows_ref): mock_get_notifications(mocker, api_user_active, client_reference=client_reference) page = client_request.get( 'main.api_integration', service_id=fake_uuid, ) dt_arr = [p.text for p in page.select('dt')] if shows_ref: assert 'client_reference:' in dt_arr assert page.select_one('dd:nth-of-type(2)').text == 'foo' else: assert 'client_reference:' not in dt_arr
def test_html_contains_links_for_failed_notifications( client_request, active_user_with_permissions, mock_get_service_statistics, mock_get_service_data_retention, mocker, ): mock_get_notifications(mocker, active_user_with_permissions, diff_template_type="sms", noti_status='technical-failure') response = client_request.get('main.view_notifications', service_id=SERVICE_ONE_ID, message_type='sms', status='sending%2Cdelivered%2Cfailed') notifications = response.tbody.find_all('tr') for tr in notifications: link_text = tr.find('div', class_='table-field-status-error').find('a').text assert normalize_spaces(link_text) == 'Technical failure'
def test_should_not_show_preview_link_for_precompiled_letters_in_virus_states( mocker, active_user_with_permissions, client_request, service_one, mock_get_service_statistics, mock_get_service_data_retention, letter_status, ): mock_get_notifications(mocker, active_user_with_permissions, is_precompiled_letter=True, noti_status=letter_status) page = client_request.get( 'main.view_notifications', service_id=service_one['id'], message_type='letter', status='', ) assert not page.find('a', attrs={'class': 'file-list-filename'})
def test_should_show_letter_job( client_request, mock_get_service_letter_template, mock_get_job, mock_get_service_data_retention, fake_uuid, active_user_with_permissions, mocker, ): get_notifications = mock_get_notifications(mocker, active_user_with_permissions, diff_template_type='letter') 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('[download=download]') == [] 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' ], )
def test_redacts_templates_that_should_be_redacted( client_request, mocker, active_user_with_permissions, mock_get_service_statistics, ): mock_get_notifications( mocker, active_user_with_permissions, template_content="hello ((name))", personalisation={'name': 'Jo'}, redact_personalisation=True, ) page = client_request.get( 'main.view_notifications', service_id=SERVICE_ONE_ID, message_type='sms', ) assert normalize_spaces( page.select('tbody tr th')[0].text) == ('07123456789 hello hidden')
def test_should_show_letter_job_with_first_class_if_notifications_are_first_class( client_request, mock_get_service_letter_template, mock_get_job, mock_get_service_data_retention, fake_uuid, active_user_with_permissions, mocker, ): mock_get_notifications(mocker, active_user_with_permissions, diff_template_type='letter', postage='first') page = client_request.get( 'main.view_job', service_id=SERVICE_ONE_ID, job_id=fake_uuid, ) assert normalize_spaces(page.select('.keyline-block') [1].text) == '5 January Estimated delivery date'
def test_should_not_show_preview_link_for_precompiled_letters_in_virus_states( mocker, active_user_with_permissions, logged_in_client, service_one, mock_get_service_statistics, letter_status, ): mock_get_notifications(mocker, active_user_with_permissions, is_precompiled_letter=True, noti_status=letter_status) response = logged_in_client.get( url_for( 'main.view_notifications', service_id=service_one['id'], message_type='letter', status='', )) page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') assert not page.find('a', attrs={'class': 'file-list-filename'})
def test_redacts_templates_that_should_be_redacted( client_request, mocker, active_user_with_permissions, mock_get_service_statistics, mock_get_service_data_retention, ): mock_get_notifications( mocker, active_user_with_permissions, template_content="hello ((name))", personalisation={"name": "Jo"}, redact_personalisation=True, ) page = client_request.get( "main.view_notifications", service_id=SERVICE_ONE_ID, message_type="sms", ) assert normalize_spaces( page.select("tbody tr th")[0].text) == ("6502532222 hello [hidden]")
def test_should_not_show_preview_link_for_precompiled_letters_in_virus_states( mocker, active_user_with_permissions, client_request, service_one, mock_get_service_statistics, mock_get_service_data_retention, letter_status, ): mock_get_notifications( mocker, active_user_with_permissions, is_precompiled_letter=True, noti_status=letter_status, ) page = client_request.get( "main.view_notifications", service_id=service_one["id"], message_type="letter", status="", ) assert not page.find("a", attrs={"class": "file-list-filename"})
def test_letters_with_status_virus_scan_failed_shows_a_failure_description( mocker, active_user_with_permissions, client_request, service_one, mock_get_service_statistics, mock_get_service_data_retention, ): mock_get_notifications( mocker, active_user_with_permissions, is_precompiled_letter=True, noti_status='virus-scan-failed' ) page = client_request.get( 'main.view_notifications', service_id=service_one['id'], message_type='letter', status='', ) error_description = page.find('div', attrs={'class': 'table-field-status-error'}).text.strip() assert 'Virus detected\n' in error_description
def test_view_conversation(client_request, mocker, api_user_active, mock_get_notification, fake_uuid, outbound_redacted, expected_outbound_content, mock_get_inbound_sms): mock_get_notifications( mocker, api_user_active, template_content='Hello ((name))', personalisation={'name': 'Jo'}, redact_personalisation=outbound_redacted, ) page = client_request.get( 'main.conversation', service_id=SERVICE_ONE_ID, notification_id=fake_uuid, ) messages = page.select('.sms-message-wrapper') statuses = page.select('.sms-message-status') assert len(messages) == 13 assert len(statuses) == 13 for index, expected in enumerate([ ( 'message-8', 'yesterday at 2:59pm', ), ( 'message-7', 'yesterday at 2:59pm', ), ( 'message-6', 'yesterday at 4:59pm', ), ( 'message-5', 'yesterday at 6:59pm', ), ( 'message-4', 'yesterday at 8:59pm', ), ( 'message-3', 'yesterday at 10:59pm', ), ( 'message-2', 'yesterday at 10:59pm', ), ( 'message-1', 'yesterday at 11:00pm', ), ( expected_outbound_content, 'yesterday at midnight', ), ( expected_outbound_content, 'yesterday at midnight', ), ( expected_outbound_content, 'yesterday at midnight', ), ( expected_outbound_content, 'yesterday at midnight', ), ( expected_outbound_content, 'yesterday at midnight', ), ]): assert ( normalize_spaces(messages[index].text), normalize_spaces(statuses[index].text), ) == expected
def test_view_conversation( client_request, mocker, api_user_active, mock_get_inbound_sms_by_id_with_no_messages, mock_get_notification, fake_uuid, outbound_redacted, expected_outbound_content, mock_get_inbound_sms ): mock = mock_get_notifications( mocker, api_user_active, template_content='Hello ((name))', personalisation={'name': 'Jo'}, redact_personalisation=outbound_redacted, ) page = client_request.get( 'main.conversation', service_id=SERVICE_ONE_ID, notification_id=fake_uuid, ) messages = page.select('.sms-message-wrapper') statuses = page.select('.sms-message-status') assert len(messages) == 13 assert len(statuses) == 13 for index, expected in enumerate([ ( 'message-8', '2011-12-31T14:59:53', ), ( 'message-7', '2011-12-31T14:59:54', ), ( 'message-6', '2011-12-31T16:59:55', ), ( 'message-5', '2011-12-31T18:59:56', ), ( 'message-4', '2011-12-31T20:59:57', ), ( 'message-3', '2011-12-31T22:59:58', ), ( 'message-2', '2011-12-31T22:59:59', ), ( 'message-1', '2011-12-31T23:00:00', ), ( expected_outbound_content, '2012-01-01T00:00:00+00:00', ), ( expected_outbound_content, '2012-01-01T00:00:00+00:00', ), ( expected_outbound_content, '2012-01-01T00:00:00+00:00', ), ( expected_outbound_content, '2012-01-01T00:00:00+00:00', ), ( expected_outbound_content, '2012-01-01T00:00:00+00:00', ), ]): assert ( normalize_spaces(messages[index].text), normalize_spaces(statuses[index].text), ) == expected mock_get_inbound_sms.assert_called_once_with(SERVICE_ONE_ID, user_number='+1 650-253-2222') mock.assert_called_once_with(SERVICE_ONE_ID, to='+1 650-253-2222', template_type='sms')