コード例 #1
0
def deactivated_service(client, notify_db, notify_db_session, sample_service):
    create_template(notify_db, notify_db_session, template_name='a')
    create_template(notify_db, notify_db_session, template_name='b')
    create_api_key(notify_db, notify_db_session)
    create_api_key(notify_db, notify_db_session)

    auth_header = create_authorization_header()
    response = client.post('/service/{}/deactivate'.format(sample_service.id), headers=[auth_header])
    assert response.status_code == 204
    assert response.data == b''
    return sample_service
コード例 #2
0
def archived_service(client, notify_db, notify_db_session, sample_service):
    create_template(notify_db, notify_db_session, template_name='a')
    create_template(notify_db, notify_db_session, template_name='b')
    create_api_key(notify_db, notify_db_session)
    create_api_key(notify_db, notify_db_session)

    auth_header = create_authorization_header()
    response = client.post('/service/{}/archive'.format(sample_service.id), headers=[auth_header])
    assert response.status_code == 204
    assert response.data == b''
    return sample_service
コード例 #3
0
def test_persist_letter_notification_finds_correct_postage(
    mocker,
    notify_db,
    notify_db_session,
    postage_argument,
    template_postage,
    expected_postage
):
    service = create_service(service_permissions=[LETTER_TYPE])
    api_key = create_api_key(notify_db, notify_db_session, service=service)
    template = create_template(service, template_type=LETTER_TYPE, postage=template_postage)
    mocker.patch('app.dao.templates_dao.dao_get_template_by_id', return_value=template)
    persist_notification(
        template_id=template.id,
        template_version=template.version,
        template_postage=template.postage,
        recipient="Jane Doe, 10 Downing Street, London",
        service=service,
        personalisation=None,
        notification_type=LETTER_TYPE,
        api_key_id=api_key.id,
        key_type=api_key.key_type,
        postage=postage_argument
    )
    persisted_notification = Notification.query.all()[0]

    assert persisted_notification.postage == expected_postage
コード例 #4
0
def test_persist_notification_does_not_increment_cache_if_test_key(
        notify_db, notify_db_session, sample_template, sample_job, mocker
):
    api_key = create_api_key(notify_db=notify_db, notify_db_session=notify_db_session, service=sample_template.service,
                             key_type='test')
    mocker.patch('app.notifications.process_notifications.redis_store.get', return_value="cache")
    mocker.patch('app.notifications.process_notifications.redis_store.get_all_from_hash', return_value="cache")
    daily_limit_cache = mocker.patch('app.notifications.process_notifications.redis_store.incr')
    template_usage_cache = mocker.patch('app.notifications.process_notifications.redis_store.increment_hash_value')

    assert Notification.query.count() == 0
    assert NotificationHistory.query.count() == 0
    persist_notification(
        template_id=sample_template.id,
        template_version=sample_template.version,
        recipient='+16502532222',
        service=sample_template.service,
        personalisation={},
        notification_type='sms',
        api_key_id=api_key.id,
        key_type=api_key.key_type,
        job_id=sample_job.id,
        job_row_number=100,
        reference="ref",
    )

    assert Notification.query.count() == 1

    assert not daily_limit_cache.called
    assert not template_usage_cache.called
コード例 #5
0
def deactivated_service_with_deleted_stuff(client, notify_db, notify_db_session, sample_service):
    with freeze_time('2001-01-01'):
        template = create_template(notify_db, notify_db_session, template_name='a')
        api_key = create_api_key(notify_db, notify_db_session)

        expire_api_key(sample_service.id, api_key.id)

        template.archived = True
        dao_update_template(template)

    with freeze_time('2002-02-02'):
        auth_header = create_authorization_header()
        response = client.post('/service/{}/deactivate'.format(sample_service.id), headers=[auth_header])

    assert response.status_code == 204
    assert response.data == b''
    return sample_service
コード例 #6
0
def archived_service_with_deleted_stuff(client, notify_db, notify_db_session, sample_service):
    with freeze_time('2001-01-01'):
        template = create_template(notify_db, notify_db_session, template_name='a')
        api_key = create_api_key(notify_db, notify_db_session)

        expire_api_key(sample_service.id, api_key.id)

        template.archived = True
        dao_update_template(template)

    with freeze_time('2002-02-02'):
        auth_header = create_authorization_header()
        response = client.post('/service/{}/archive'.format(sample_service.id), headers=[auth_header])

    assert response.status_code == 204
    assert response.data == b''
    return sample_service