コード例 #1
0
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,
        just_sent='yes',
    )

    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')
コード例 #2
0
def test_should_show_address_and_hint_for_letters(
    client_request,
    service_one,
    mock_get_service_statistics,
    mock_get_service_data_retention,
    mock_get_no_api_keys,
    mocker,
    is_precompiled_letter,
    expected_address,
    expected_hint
):
    notifications = create_notifications(
        template_type='letter',
        subject=expected_hint,
        is_precompiled_letter=is_precompiled_letter,
        client_reference=expected_hint,
        to=expected_address
    )
    mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)

    page = client_request.get(
        'main.view_notifications',
        service_id=SERVICE_ONE_ID,
        message_type='letter',
    )

    assert page.select_one('a.file-list-filename').text == 'Full Name'
    assert page.find('p', {'class': 'file-list-hint'}).text.strip() == expected_hint
コード例 #3
0
def test_redacts_templates_that_should_be_redacted(
    client_request,
    mocker,
    mock_get_service_statistics,
    mock_get_service_data_retention,
    mock_get_no_api_keys,
    notification_type,
    expected_row_contents,
):
    notifications = create_notifications(
        status='technical-failure',
        content='hello & welcome ((name))',
        subject='((name)), hello & welcome',
        personalisation={'name': 'Jo'},
        redact_personalisation=True,
        template_type=notification_type,
    )
    mocker.patch('app.notification_api_client.get_notifications_for_service',
                 return_value=notifications)

    page = client_request.get(
        'main.view_notifications',
        service_id=SERVICE_ONE_ID,
        message_type=notification_type,
    )

    assert normalize_spaces(
        page.select('tbody tr th')[0].text) == (expected_row_contents)
コード例 #4
0
def test_letters_with_status_virus_scan_failed_shows_a_failure_description(
    mocker,
    client_request,
    service_one,
    mock_get_service_statistics,
    mock_get_service_data_retention,
    mock_get_api_keys,
):
    notifications = create_notifications(template_type='letter',
                                         status='virus-scan-failed',
                                         is_precompiled_letter=True,
                                         client_reference='client reference')
    mocker.patch('app.notification_api_client.get_notifications_for_service',
                 return_value=notifications)

    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
コード例 #5
0
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'
        ],
    )
コード例 #6
0
def test_should_not_have_link_to_view_letter_for_precompiled_letters_in_virus_states(
        client_request, fake_uuid, mock_has_permissions, mocker, status):
    notifications = create_notifications(status=status)
    mocker.patch('app.notification_api_client.get_notifications_for_service',
                 return_value=notifications)

    page = client_request.get(
        'main.api_integration',
        service_id=fake_uuid,
    )

    assert not page.select_one('details a')
コード例 #7
0
def test_letter_notifications_should_have_link_to_view_letter(
    client_request,
    mock_has_permissions,
    mocker,
    template_type,
    link_text,
):
    notifications = create_notifications(template_type=template_type)
    mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)
    page = client_request.get(
        'main.api_integration',
        service_id=SERVICE_ONE_ID,
    )

    assert page.select_one('details a').text.strip() == link_text
コード例 #8
0
def test_sending_status_hint_displays_correctly_on_notifications_page(
        client_request, service_one, mock_get_service_statistics,
        mock_get_service_data_retention, mock_get_no_api_keys, message_type,
        status, expected_hint_status, single_line, mocker):
    notifications = create_notifications(template_type=message_type,
                                         status=status)
    mocker.patch('app.notification_api_client.get_notifications_for_service',
                 return_value=notifications)

    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
コード例 #9
0
def test_letter_notifications_should_show_client_reference(
        client_request, fake_uuid, mock_has_permissions, mocker,
        client_reference, shows_ref):
    notifications = create_notifications(client_reference=client_reference)
    mocker.patch('app.notification_api_client.get_notifications_for_service',
                 return_value=notifications)

    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
コード例 #10
0
def test_should_show_letter_job_with_first_class_if_notifications_are_first_class(
    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', postage='first')
    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.select('.keyline-block')[1].text) == '5 January Estimated delivery date'
コード例 #11
0
def test_html_contains_links_for_failed_notifications(
    client_request,
    mock_get_service_statistics,
    mock_get_service_data_retention,
    mock_get_no_api_keys,
    mocker,
):
    notifications = create_notifications(status='technical-failure')
    mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)

    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'
コード例 #12
0
def test_should_not_show_preview_link_for_precompiled_letters_in_virus_states(
    mocker,
    client_request,
    service_one,
    mock_get_service_statistics,
    mock_get_service_data_retention,
    mock_get_no_api_keys,
    letter_status,
):
    notifications = create_notifications(template_type='letter', status=letter_status,
                                         is_precompiled_letter=True, client_reference='ref')
    mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)

    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'})
コード例 #13
0
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,
        just_sent='yes',
    )

    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.')
コード例 #14
0
def test_view_conversation(client_request, mocker,
                           mock_get_inbound_sms_by_id_with_no_messages,
                           mock_get_notification, fake_uuid, outbound_redacted,
                           expected_outbound_content, mock_get_inbound_sms):
    notifications = create_notifications(
        content='Hello ((name))',
        personalisation={'name': 'Jo'},
        redact_personalisation=outbound_redacted,
    )
    mock = mocker.patch(
        'app.notification_api_client.get_notifications_for_service',
        return_value=notifications)

    page = client_request.get(
        'main.conversation',
        service_id=SERVICE_ONE_ID,
        notification_id=fake_uuid,
        _test_page_title=False,
    )

    assert normalize_spaces(page.select_one('title').text) == (
        'Received text message – service one – Catalyst Notify')
    assert normalize_spaces(page.select_one('h1').text) == ('07123 456789')

    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

    mock_get_inbound_sms.assert_called_once_with(SERVICE_ONE_ID,
                                                 user_number='07123 456789')
    mock.assert_called_once_with(SERVICE_ONE_ID,
                                 to='07123 456789',
                                 template_type='sms')