Exemplo n.º 1
0
def test_get_api_notifications_changes_letter_statuses(mocker, letter_status,
                                                       expected_status):
    service_id = str(uuid.uuid4())
    sms_notification = single_notification_json(service_id,
                                                notification_type='sms',
                                                status='created')
    email_notification = single_notification_json(service_id,
                                                  notification_type='email',
                                                  status='created')
    letter_notification = single_notification_json(service_id,
                                                   notification_type='letter',
                                                   status=letter_status)
    notis = notification_json(service_id=service_id, rows=0)
    notis['notifications'] = [
        sms_notification, email_notification, letter_notification
    ]

    mocker.patch(
        'app.notify_client.notification_api_client.NotificationApiClient.get',
        return_value=notis)

    ret = NotificationApiClient().get_api_notifications_for_service(service_id)

    assert ret['notifications'][0]['notification_type'] == 'sms'
    assert ret['notifications'][1]['notification_type'] == 'email'
    assert ret['notifications'][2]['notification_type'] == 'letter'
    assert ret['notifications'][0]['status'] == 'created'
    assert ret['notifications'][1]['status'] == 'created'
    assert ret['notifications'][2]['status'] == expected_status
Exemplo n.º 2
0
def test_get_api_notifications_changes_letter_statuses(mocker, letter_status,
                                                       expected_status):
    service_id = str(uuid.uuid4())
    sms_notification = single_notification_json(service_id,
                                                notification_type="sms",
                                                status="created",
                                                api_key="api key id")
    email_notification = single_notification_json(service_id,
                                                  notification_type="email",
                                                  status="created",
                                                  api_key="api key id")
    letter_notification = single_notification_json(service_id,
                                                   notification_type="letter",
                                                   status=letter_status,
                                                   api_key="api key id")
    notis = notification_json(service_id=service_id, rows=0)
    notis["notifications"] = [
        sms_notification, email_notification, letter_notification
    ]

    mocker.patch(
        "app.notify_client.notification_api_client.NotificationApiClient.get",
        return_value=notis,
    )

    ret = NotificationApiClient().get_api_notifications_for_service(service_id)

    assert ret["notifications"][0]["notification_type"] == "sms"
    assert ret["notifications"][1]["notification_type"] == "email"
    assert ret["notifications"][2]["notification_type"] == "letter"
    assert ret["notifications"][0]["status"] == "created"
    assert ret["notifications"][1]["status"] == "created"
    assert ret["notifications"][2]["status"] == expected_status
Exemplo n.º 3
0
def test_should_show_delete_template_page_with_time_block_for_empty_notification(
    client_request,
    mock_get_service_template,
    mocker,
    fake_uuid
):
    with freeze_time('2012-01-08 12:00:00'):
        template = template_json('1234', '1234', "Test template", "sms", "Something very interesting")
        single_notification_json('1234', template=template)
        mocker.patch('app.template_statistics_client.get_template_statistics_for_template',
                     return_value=None)

    with freeze_time('2012-01-01 11:00:00'):
        page = client_request.get(
            '.delete_service_template',
            service_id=SERVICE_ONE_ID,
            template_id=fake_uuid,
            _test_page_title=False,
        )
    assert page.h1.text == 'Are you sure you want to delete Two week reminder?'
    assert normalize_spaces(page.select('.banner-dangerous p')[0].text) == (
        'It was last used more than seven days ago'
    )
    assert normalize_spaces(page.select('.sms-message-wrapper')[0].text) == (
        'service one: Template <em>content</em> with & entity'
    )
    mock_get_service_template.assert_called_with(SERVICE_ONE_ID, fake_uuid)
def test_should_show_delete_template_page_with_time_block(app_,
                                                          api_user_active,
                                                          mock_login,
                                                          mock_get_service,
                                                          mock_get_service_template,
                                                          mock_get_user,
                                                          mock_get_user_by_email,
                                                          mock_has_permissions,
                                                          fake_uuid,
                                                          mocker):
    with app_.test_request_context():
        with app_.test_client() as client:
            with freeze_time('2012-01-01 12:00:00'):
                template = template_json('1234', '1234', "Test template", "sms", "Something very interesting")
                notification = single_notification_json('1234', template=template)

                mocker.patch('app.template_statistics_client.get_template_statistics_for_template',
                             return_value=notification)

            with freeze_time('2012-01-01 12:10:00'):
                client.login(api_user_active)
                service_id = fake_uuid
                template_id = fake_uuid
                response = client.get(url_for(
                    '.delete_service_template',
                    service_id=service_id,
                    template_id=template_id))
    content = response.get_data(as_text=True)
    assert response.status_code == 200
    assert 'Test template was last used 10 minutes ago. Are you sure you want to delete it?' in content
    assert 'Are you sure' in content
    assert 'Two week reminder' in content
    assert 'Your vehicle tax is about to expire' in content
    mock_get_service_template.assert_called_with(service_id, template_id)
Exemplo n.º 5
0
def test_get_api_notifications_ignores_non_api_notifications(mocker):
    service_id = str(uuid.uuid4())
    notis = notification_json(service_id=service_id, rows=0)
    admin_notification = single_notification_json(service_id,
                                                  notification_type="email",
                                                  status="created",
                                                  api_key=None)
    api_notification = single_notification_json(service_id,
                                                notification_type="email",
                                                status="created",
                                                api_key="api key id")
    notis["notifications"] = [admin_notification, api_notification]
    mocker.patch(
        "app.notify_client.notification_api_client.NotificationApiClient.get",
        return_value=notis,
    )

    ret = NotificationApiClient().get_api_notifications_for_service(service_id)

    assert len(ret["notifications"]) == 1
    assert ret["notifications"][0]["api_key"] == "api key id"