mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-16 20:48:37 -04:00
Update montly billing with letters
This commit is contained in:
@@ -645,13 +645,12 @@ def test_populate_monthly_billing_populates_correctly(sample_template):
|
||||
|
||||
monthly_billing = MonthlyBilling.query.order_by(MonthlyBilling.notification_type).all()
|
||||
|
||||
assert len(monthly_billing) == 2
|
||||
assert len(monthly_billing) == 3
|
||||
|
||||
assert monthly_billing[0].service_id == sample_template.service_id
|
||||
assert monthly_billing[0].start_date == jul_month_start
|
||||
assert monthly_billing[0].end_date == jul_month_end
|
||||
assert monthly_billing[0].notification_type == 'email'
|
||||
assert monthly_billing[0].notification_type == 'email'
|
||||
assert monthly_billing[0].monthly_totals == []
|
||||
|
||||
assert monthly_billing[1].service_id == sample_template.service_id
|
||||
@@ -668,6 +667,12 @@ def test_populate_monthly_billing_populates_correctly(sample_template):
|
||||
}
|
||||
)
|
||||
|
||||
assert monthly_billing[2].service_id == sample_template.service_id
|
||||
assert monthly_billing[2].start_date == jul_month_start
|
||||
assert monthly_billing[2].end_date == jul_month_end
|
||||
assert monthly_billing[2].notification_type == 'letter'
|
||||
assert monthly_billing[2].monthly_totals == []
|
||||
|
||||
|
||||
@freeze_time("2016-04-01 23:00:00")
|
||||
def test_populate_monthly_billing_updates_correct_month_in_bst(sample_template):
|
||||
@@ -680,7 +685,7 @@ def test_populate_monthly_billing_updates_correct_month_in_bst(sample_template):
|
||||
|
||||
monthly_billing = MonthlyBilling.query.order_by(MonthlyBilling.notification_type).all()
|
||||
|
||||
assert len(monthly_billing) == 2
|
||||
assert len(monthly_billing) == 3
|
||||
|
||||
assert monthly_billing[0].service_id == sample_template.service_id
|
||||
assert monthly_billing[0].start_date == apr_month_start
|
||||
@@ -695,6 +700,11 @@ def test_populate_monthly_billing_updates_correct_month_in_bst(sample_template):
|
||||
assert monthly_billing[1].monthly_totals[0]['billing_units'] == 1
|
||||
assert monthly_billing[1].monthly_totals[0]['total_cost'] == 0.0123
|
||||
|
||||
assert monthly_billing[2].service_id == sample_template.service_id
|
||||
assert monthly_billing[2].start_date == apr_month_start
|
||||
assert monthly_billing[2].end_date == apr_month_end
|
||||
assert monthly_billing[2].notification_type == 'letter'
|
||||
assert monthly_billing[2].monthly_totals == []
|
||||
|
||||
def test_run_letter_jobs(client, mocker, sample_letter_template):
|
||||
jobs = [create_job(template=sample_letter_template, job_status=JOB_STATUS_READY_TO_SEND),
|
||||
|
||||
@@ -164,7 +164,7 @@ def test_add_monthly_billing_for_single_month_populates_correctly(
|
||||
|
||||
monthly_billing = MonthlyBilling.query.order_by(MonthlyBilling.notification_type).all()
|
||||
|
||||
assert len(monthly_billing) == 2
|
||||
assert len(monthly_billing) == 3
|
||||
_assert_monthly_billing(
|
||||
monthly_billing[0], sample_template.service.id, 'email', JAN_2017_MONTH_START, JAN_2017_MONTH_END
|
||||
)
|
||||
@@ -181,6 +181,11 @@ def test_add_monthly_billing_for_single_month_populates_correctly(
|
||||
"total_cost": 1 * 2 * 0.0158
|
||||
})
|
||||
|
||||
_assert_monthly_billing(
|
||||
monthly_billing[2], sample_template.service.id, 'letter', JAN_2017_MONTH_START, JAN_2017_MONTH_END
|
||||
)
|
||||
assert monthly_billing[2].monthly_totals == []
|
||||
|
||||
|
||||
def test_add_monthly_billing_for_multiple_months_populate_correctly(
|
||||
sample_template, sample_email_template
|
||||
@@ -203,7 +208,7 @@ def test_add_monthly_billing_for_multiple_months_populate_correctly(
|
||||
MonthlyBilling.start_date
|
||||
).all()
|
||||
|
||||
assert len(monthly_billing) == 4
|
||||
assert len(monthly_billing) == 6
|
||||
_assert_monthly_billing(
|
||||
monthly_billing[0], sample_template.service.id, 'email', FEB_2016_MONTH_START, FEB_2016_MONTH_END
|
||||
)
|
||||
@@ -236,6 +241,16 @@ def test_add_monthly_billing_for_multiple_months_populate_correctly(
|
||||
"total_cost": 0.72
|
||||
})
|
||||
|
||||
_assert_monthly_billing(
|
||||
monthly_billing[4], sample_template.service.id, 'letter', FEB_2016_MONTH_START, FEB_2016_MONTH_END
|
||||
)
|
||||
assert monthly_billing[4].monthly_totals == []
|
||||
|
||||
_assert_monthly_billing(
|
||||
monthly_billing[5], sample_template.service.id, 'letter', MAR_2016_MONTH_START, MAR_2016_MONTH_END
|
||||
)
|
||||
assert monthly_billing[5].monthly_totals == []
|
||||
|
||||
|
||||
def test_add_monthly_billing_with_multiple_rates_populate_correctly(
|
||||
sample_template
|
||||
@@ -252,7 +267,7 @@ def test_add_monthly_billing_with_multiple_rates_populate_correctly(
|
||||
|
||||
monthly_billing = MonthlyBilling.query.order_by(MonthlyBilling.notification_type).all()
|
||||
|
||||
assert len(monthly_billing) == 2
|
||||
assert len(monthly_billing) == 3
|
||||
_assert_monthly_billing(
|
||||
monthly_billing[0], sample_template.service.id, 'email', JAN_2017_MONTH_START, JAN_2017_MONTH_END
|
||||
)
|
||||
@@ -276,6 +291,11 @@ def test_add_monthly_billing_with_multiple_rates_populate_correctly(
|
||||
"total_cost": 0.246
|
||||
})
|
||||
|
||||
_assert_monthly_billing(
|
||||
monthly_billing[2], sample_template.service.id, 'letter', JAN_2017_MONTH_START, JAN_2017_MONTH_END
|
||||
)
|
||||
assert monthly_billing[0].monthly_totals == []
|
||||
|
||||
|
||||
def test_update_monthly_billing_overwrites_old_totals(sample_template):
|
||||
create_rate(APR_2016_MONTH_START, 0.123, SMS_TYPE)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import uuid
|
||||
from _decimal import Decimal
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from freezegun import freeze_time
|
||||
@@ -218,7 +217,7 @@ def test_get_monthly_billing_data_where_start_date_before_rate_returns_empty(
|
||||
def test_billing_letter_data_per_month_query(
|
||||
notify_db_session
|
||||
):
|
||||
rate = create_letter_rate()
|
||||
create_letter_rate()
|
||||
service = create_service()
|
||||
template = create_template(service=service, template_type='letter')
|
||||
create_notification(template=template, billable_units=1, created_at=datetime(2017, 2, 1, 13, 21),
|
||||
@@ -233,4 +232,5 @@ def test_billing_letter_data_per_month_query(
|
||||
end_date=datetime(2017, 2, 28))
|
||||
|
||||
assert len(results) == 1
|
||||
assert results[0].rate == Decimal('0.31')
|
||||
print(results[0].rate)
|
||||
assert results[0].rate == 0.31
|
||||
|
||||
@@ -70,7 +70,7 @@ def create_service(
|
||||
email_from=None,
|
||||
prefix_sms=True,
|
||||
message_limit=1000,
|
||||
crown=True
|
||||
organisation_type='central'
|
||||
):
|
||||
service = Service(
|
||||
name=service_name,
|
||||
@@ -79,7 +79,7 @@ def create_service(
|
||||
email_from=email_from if email_from else service_name.lower().replace(' ', '.'),
|
||||
created_by=user or create_user(email='{}@digital.cabinet-office.gov.uk'.format(uuid.uuid4())),
|
||||
prefix_sms=prefix_sms,
|
||||
crown=crown
|
||||
organisation_type=organisation_type
|
||||
)
|
||||
|
||||
dao_create_service(service, service.created_by, service_id, service_permissions=service_permissions)
|
||||
@@ -459,7 +459,7 @@ def create_annual_billing(
|
||||
|
||||
|
||||
def create_letter_rate(
|
||||
start_date=datetime(2017, 1,1, 00,00,00),
|
||||
start_date=datetime(2017, 1, 1, 00, 00, 00),
|
||||
end_date=None,
|
||||
sheet_count=1,
|
||||
rate=0.31,
|
||||
|
||||
Reference in New Issue
Block a user