コード例 #1
0
def test_fetch_stats_counts_correctly(notify_db_session):
    service = create_service()
    sms_template = create_template(service=service)
    email_template = create_template(service=service, template_type='email')
    # two created email, one failed email, and one created sms
    create_notification(template=email_template, status='created')
    create_notification(template=email_template, status='created')
    create_notification(template=email_template, status='technical-failure')
    create_notification(template=sms_template, status='created')

    stats = dao_fetch_stats_for_service(sms_template.service_id, 7)
    stats = sorted(stats, key=lambda x: (x.notification_type, x.status))
    assert len(stats) == 3

    assert stats[0].notification_type == 'email'
    assert stats[0].status == 'created'
    assert stats[0].count == 2

    assert stats[1].notification_type == 'email'
    assert stats[1].status == 'technical-failure'
    assert stats[1].count == 1

    assert stats[2].notification_type == 'sms'
    assert stats[2].status == 'created'
    assert stats[2].count == 1
コード例 #2
0
ファイル: rest.py プロジェクト: pwright08/notifications-api
def get_service_statistics(service_id, today_only, limit_days=7):
    # today_only flag is used by the send page to work out if the service will exceed their daily usage by sending a job
    if today_only:
        stats = dao_fetch_todays_stats_for_service(service_id)
    else:
        stats = dao_fetch_stats_for_service(service_id, limit_days=limit_days)

    return statistics.format_statistics(stats)
コード例 #3
0
def test_fetch_stats_ignores_historical_notification_data(sample_template):
    create_notification_history(template=sample_template)

    assert Notification.query.count() == 0
    assert NotificationHistory.query.count() == 1

    stats = dao_fetch_stats_for_service(sample_template.service_id, 7)
    assert len(stats) == 0
コード例 #4
0
def test_fetch_stats_ignores_historical_notification_data(sample_notification):
    service_id = sample_notification.service.id

    db.session.delete(sample_notification)

    assert Notification.query.count() == 0
    assert NotificationHistory.query.count() == 1

    stats = dao_fetch_stats_for_service(service_id)
    assert len(stats) == 0
コード例 #5
0
def test_fetch_stats_should_not_gather_notifications_older_than_7_days(
        sample_template, created_at, limit_days, rows_returned
):
    # It's monday today. Things made last monday should still show
    with freeze_time(created_at):
        create_notification(sample_template, )

    with freeze_time('Monday 16th July 2018 12:00'):
        stats = dao_fetch_stats_for_service(sample_template.service_id, limit_days)

    assert len(stats) == rows_returned
コード例 #6
0
def test_fetch_stats_filters_on_service(sample_notification):
    service_two = Service(
        name="service_two",
        created_by=sample_notification.service.created_by,
        email_from="hello",
        restricted=False,
        message_limit=1000,
    )
    dao_create_service(service_two, sample_notification.service.created_by)

    stats = dao_fetch_stats_for_service(service_two.id)
    assert len(stats) == 0
コード例 #7
0
def test_fetch_stats_filters_on_service(notify_db_session):
    service_one = create_service()
    create_notification(template=create_template(service=service_one))

    service_two = Service(name="service_two",
                          created_by=service_one.created_by,
                          email_from="hello",
                          restricted=False,
                          message_limit=1000)
    dao_create_service(service_two, service_one.created_by)

    stats = dao_fetch_stats_for_service(service_two.id, 7)
    assert len(stats) == 0
コード例 #8
0
def test_fetch_stats_counts_should_ignore_team_key(notify_db_session):
    service = create_service()
    template = create_template(service=service)
    live_api_key = create_api_key(service=service, key_type=KEY_TYPE_NORMAL)
    team_api_key = create_api_key(service=service, key_type=KEY_TYPE_TEAM)
    test_api_key = create_api_key(service=service, key_type=KEY_TYPE_TEST)

    # two created email, one failed email, and one created sms
    create_notification(template=template, api_key=live_api_key, key_type=live_api_key.key_type)
    create_notification(template=template, api_key=test_api_key, key_type=test_api_key.key_type)
    create_notification(template=template, api_key=team_api_key, key_type=team_api_key.key_type)
    create_notification(template=template)

    stats = dao_fetch_stats_for_service(template.service_id, 7)
    assert len(stats) == 1
    assert stats[0].notification_type == 'sms'
    assert stats[0].status == 'created'
    assert stats[0].count == 3
コード例 #9
0
def test_fetch_stats_counts_should_ignore_team_key(
    notify_db, notify_db_session, sample_template, sample_api_key, sample_test_api_key, sample_team_api_key
):
    # two created email, one failed email, and one created sms
    create_notification(notify_db, notify_db_session, api_key_id=sample_api_key.id, key_type=sample_api_key.key_type)
    create_notification(
        notify_db, notify_db_session, api_key_id=sample_test_api_key.id, key_type=sample_test_api_key.key_type
    )
    create_notification(
        notify_db, notify_db_session, api_key_id=sample_team_api_key.id, key_type=sample_team_api_key.key_type
    )
    create_notification(notify_db, notify_db_session)

    stats = dao_fetch_stats_for_service(sample_template.service_id)
    assert len(stats) == 1
    assert stats[0].notification_type == "sms"
    assert stats[0].status == "created"
    assert stats[0].count == 3
コード例 #10
0
def test_fetch_stats_counts_correctly(notify_db, notify_db_session, sample_template, sample_email_template):
    # two created email, one failed email, and one created sms
    create_notification(notify_db, notify_db_session, template=sample_email_template, status="created")
    create_notification(notify_db, notify_db_session, template=sample_email_template, status="created")
    create_notification(notify_db, notify_db_session, template=sample_email_template, status="technical-failure")
    create_notification(notify_db, notify_db_session, template=sample_template, status="created")

    stats = dao_fetch_stats_for_service(sample_template.service_id)
    stats = sorted(stats, key=lambda x: (x.notification_type, x.status))
    assert len(stats) == 3

    assert stats[0].notification_type == "email"
    assert stats[0].status == "created"
    assert stats[0].count == 2

    assert stats[1].notification_type == "email"
    assert stats[1].status == "technical-failure"
    assert stats[1].count == 1

    assert stats[2].notification_type == "sms"
    assert stats[2].status == "created"
    assert stats[2].count == 1