Exemple #1
0
def test_get_monthly_billing_by_notification_type_filters_by_type(
        notify_db, notify_db_session):
    service = create_service(service_name="Service One")

    create_monthly_billing_entry(service=service,
                                 monthly_totals=[{
                                     "billing_units": 138,
                                     "rate": 0.0158,
                                     "rate_multiplier": 1,
                                     "total_cost": 2.1804,
                                     "international": None
                                 }],
                                 start_date=APR_2016_MONTH_START,
                                 end_date=APR_2016_MONTH_END,
                                 notification_type=SMS_TYPE)

    create_monthly_billing_entry(service=service,
                                 monthly_totals=[],
                                 start_date=APR_2016_MONTH_START,
                                 end_date=APR_2016_MONTH_END,
                                 notification_type=EMAIL_TYPE)

    monthly_billing_data = get_monthly_billing_by_notification_type(
        service.id, APR_2016, EMAIL_TYPE)

    _assert_monthly_billing(monthly_billing_data, service.id, 'email',
                            APR_2016_MONTH_START, APR_2016_MONTH_END)
    assert monthly_billing_data.monthly_totals == []
Exemple #2
0
def test_get_yearly_billing_data_for_year_includes_current_day_totals(
        sample_template):
    create_rate(start_date=FEB_2016_MONTH_START,
                value=0.0158,
                notification_type=SMS_TYPE)

    create_monthly_billing_entry(service=sample_template.service,
                                 start_date=JUL_2016_MONTH_START,
                                 end_date=JUL_2016_MONTH_END,
                                 notification_type=SMS_TYPE)

    billing_data = get_billing_data_for_financial_year(
        service_id=sample_template.service.id,
        year=2016,
        notification_types=[SMS_TYPE])

    assert len(billing_data) == 1
    assert billing_data[0].notification_type == SMS_TYPE
    assert billing_data[0].monthly_totals == []

    create_notification(template=sample_template,
                        created_at=datetime.utcnow(),
                        sent_at=datetime.utcnow(),
                        status='sending',
                        billable_units=3)

    billing_data = get_billing_data_for_financial_year(
        service_id=sample_template.service.id,
        year=2016,
        notification_types=[SMS_TYPE])

    assert billing_data[0].monthly_totals[0]['billing_units'] == 3
Exemple #3
0
def test_get_monthly_billing_by_notification_type_returns_correct_totals(
        notify_db, notify_db_session):
    service = create_service(service_name="Service One")

    create_monthly_billing_entry(service=service,
                                 monthly_totals=[{
                                     "billing_units": 12,
                                     "rate": 0.0158,
                                     "rate_multiplier": 5,
                                     "total_cost": 2.1804,
                                     "international": False
                                 }],
                                 start_date=APR_2016_MONTH_START,
                                 end_date=APR_2016_MONTH_END,
                                 notification_type=SMS_TYPE)

    monthly_billing_data = get_monthly_billing_by_notification_type(
        service.id, APR_2016, SMS_TYPE)

    _assert_monthly_billing(monthly_billing_data, service.id, 'sms',
                            APR_2016_MONTH_START, APR_2016_MONTH_END)
    _assert_monthly_billing_totals(
        monthly_billing_data.monthly_totals[0], {
            "billing_units": 12,
            "rate_multiplier": 5,
            "international": False,
            "rate": 0.0158,
            "total_cost": 2.1804
        })
Exemple #4
0
def test_transform_billing_calculates_with_different_rate_multipliers(
        sample_service):
    create_monthly_billing_entry(service=sample_service,
                                 monthly_totals=[{
                                     'billing_units': 1321,
                                     'international': False,
                                     'month': 'May',
                                     'notification_type': SMS_TYPE,
                                     'rate': 0.12,
                                     'rate_multiplier': 1
                                 }, {
                                     'billing_units': 1,
                                     'international': False,
                                     'month': 'May',
                                     'notification_type': SMS_TYPE,
                                     'rate': 0.12,
                                     'rate_multiplier': 3
                                 }],
                                 start_date=APR_2016_MONTH_START,
                                 end_date=APR_2016_MONTH_END,
                                 notification_type=SMS_TYPE)

    transformed_billing_data = _transform_billing_for_month_sms(
        get_monthly_billing_by_notification_type(sample_service.id,
                                                 APR_2016_MONTH_START,
                                                 SMS_TYPE))

    _assert_dict_equals(
        transformed_billing_data, {
            'notification_type': SMS_TYPE,
            'billing_units': 1324,
            'month': 'April',
            'rate': 0.12,
        })
Exemple #5
0
def test_transform_billing_for_month_formats_monthly_totals_correctly(
        sample_service):
    create_monthly_billing_entry(service=sample_service,
                                 monthly_totals=[{
                                     "billing_units": 12,
                                     "rate": 0.0158,
                                     "rate_multiplier": 5,
                                     "total_cost": 2.1804,
                                     "international": False
                                 }],
                                 start_date=APR_2016_MONTH_START,
                                 end_date=APR_2016_MONTH_END,
                                 notification_type=SMS_TYPE)

    transformed_billing_data = _transform_billing_for_month_sms(
        get_monthly_billing_by_notification_type(sample_service.id,
                                                 APR_2016_MONTH_START,
                                                 SMS_TYPE))

    _assert_dict_equals(
        transformed_billing_data, {
            'notification_type': SMS_TYPE,
            'billing_units': 60,
            'month': 'April',
            'rate': 0.0158,
        })
Exemple #6
0
def test_transform_billing_for_month_returns_empty_if_no_monthly_totals(
        sample_service):
    create_monthly_billing_entry(service=sample_service,
                                 monthly_totals=[],
                                 start_date=APR_2016_MONTH_START,
                                 end_date=APR_2016_MONTH_END,
                                 notification_type=SMS_TYPE)

    transformed_billing_data = _transform_billing_for_month_sms(
        get_monthly_billing_by_notification_type(sample_service.id,
                                                 APR_2016_MONTH_START,
                                                 SMS_TYPE))

    _assert_dict_equals(
        transformed_billing_data, {
            'notification_type': SMS_TYPE,
            'billing_units': 0,
            'month': 'April',
            'rate': 0,
        })
Exemple #7
0
def test_get_monthly_billing_by_notification_type_normalises_start_date(
        notify_db, notify_db_session):
    service = create_service(service_name="Service One")

    create_monthly_billing_entry(service=service,
                                 monthly_totals=[{
                                     "billing_units": 321,
                                     "rate": 0.0158,
                                     "rate_multiplier": 1,
                                     "total_cost": 2.1804,
                                     "international": None
                                 }],
                                 start_date=APR_2016_MONTH_START,
                                 end_date=APR_2016_MONTH_END,
                                 notification_type=SMS_TYPE)

    monthly_billing_data = get_monthly_billing_by_notification_type(
        service.id, APR_2016 + timedelta(days=5), SMS_TYPE)

    assert monthly_billing_data.start_date == APR_2016_MONTH_START
    assert monthly_billing_data.monthly_totals[0]['billing_units'] == 321
Exemple #8
0
def test_get_monthly_billing_entry_filters_by_service(notify_db,
                                                      notify_db_session):
    service_1 = create_service(service_name="Service One")
    service_2 = create_service(service_name="Service Two")
    now = datetime.utcnow()

    create_monthly_billing_entry(service=service_1,
                                 monthly_totals=[],
                                 start_date=now,
                                 end_date=now + timedelta(days=30),
                                 notification_type=SMS_TYPE)

    create_monthly_billing_entry(service=service_2,
                                 monthly_totals=[],
                                 start_date=now,
                                 end_date=now + timedelta(days=30),
                                 notification_type=SMS_TYPE)

    entry = get_monthly_billing_entry(service_2.id, now, SMS_TYPE)

    assert entry.start_date == now
    assert entry.service_id == service_2.id