Beispiel #1
0
def get_service_provider_aggregate_statistics(service_id):
    year = request.args.get('year')
    if year is not None:
        try:
            year = int(year)
        except ValueError:
            raise InvalidRequest('Year must be a number', status_code=400)
    return jsonify(data=get_fragment_count(service_id, year=year))
def test_get_fragment_count_separates_sms_and_email(notify_db, sample_template,
                                                    sample_email_template):
    noti_hist(notify_db, sample_template)
    noti_hist(notify_db, sample_template)
    noti_hist(notify_db, sample_email_template)
    assert get_fragment_count(sample_template.service_id) == {
        'sms_count': 2,
        'email_count': 1
    }
def test_get_fragment_count_with_no_data(sample_template):
    assert get_fragment_count(sample_template.service_id)["sms_count"] == 0
    assert get_fragment_count(sample_template.service_id)["email_count"] == 0
def test_get_fragment_count_ignores_test_api_keys(notify_db, sample_template, key_type, sms_count):
    noti_hist(notify_db, sample_template, key_type=key_type)
    assert get_fragment_count(sample_template.service_id)["sms_count"] == sms_count
def test_get_fragment_count_sums_billable_units_for_sms(notify_db, sample_template):
    noti_hist(notify_db, sample_template, billable_units=1)
    noti_hist(notify_db, sample_template, billable_units=2)
    assert get_fragment_count(sample_template.service_id)["sms_count"] == 3
def test_get_fragment_count_filters_on_service_id(notify_db, sample_template, service_factory):
    service_2 = service_factory.get("service 2", email_from="service.2")
    noti_hist(notify_db, sample_template)
    assert get_fragment_count(service_2.id)["sms_count"] == 0
def test_get_fragment_count_filters_on_status(notify_db, sample_template):
    for status in NOTIFICATION_STATUS_TYPES:
        noti_hist(notify_db, sample_template, status=status)
    # sending, delivered, failed, technical-failure, temporary-failure, permanent-failure
    assert get_fragment_count(sample_template.service_id)["sms_count"] == 6
def test_get_fragment_count_separates_sms_and_email(notify_db, sample_template, sample_email_template):
    noti_hist(notify_db, sample_template)
    noti_hist(notify_db, sample_template)
    noti_hist(notify_db, sample_email_template)
    assert get_fragment_count(sample_template.service_id) == {"sms_count": 2, "email_count": 1}
def test_get_fragment_count_ignores_test_api_keys(notify_db, sample_template,
                                                  key_type, sms_count):
    noti_hist(notify_db, sample_template, key_type=key_type)
    assert get_fragment_count(
        sample_template.service_id)['sms_count'] == sms_count
def test_get_fragment_count_sums_billable_units_for_sms(
        notify_db, sample_template):
    noti_hist(notify_db, sample_template, billable_units=1)
    noti_hist(notify_db, sample_template, billable_units=2)
    assert get_fragment_count(sample_template.service_id)['sms_count'] == 3
def test_get_fragment_count_filters_on_year(notify_db, sample_template,
                                            creation_time, expected_count):
    with freeze_time(creation_time):
        noti_hist(notify_db, sample_template)
    assert get_fragment_count(sample_template.service_id,
                              year=2000)['sms_count'] == expected_count
def test_get_fragment_count_filters_on_service_id(notify_db, sample_template,
                                                  service_factory):
    service_2 = service_factory.get('service 2', email_from='service.2')
    noti_hist(notify_db, sample_template)
    assert get_fragment_count(service_2.id)['sms_count'] == 0
def test_get_fragment_count_filters_on_status(notify_db, sample_template):
    for status in NOTIFICATION_STATUS_TYPES:
        noti_hist(notify_db, sample_template, status=status)
    # sending, sent, delivered, failed, technical-failure, temporary-failure, permanent-failure
    assert get_fragment_count(sample_template.service_id)['sms_count'] == 7
def test_get_fragment_count_with_no_data(sample_template):
    assert get_fragment_count(sample_template.service_id)['sms_count'] == 0
    assert get_fragment_count(sample_template.service_id)['email_count'] == 0