Merge pull request #1867 from alphagov/use-ft-billing-for-usage

Update ft_billing table to use integer data types
This commit is contained in:
Rebecca Law
2018-05-14 13:04:52 +01:00
committed by GitHub
9 changed files with 247 additions and 57 deletions

View File

@@ -7,7 +7,8 @@ from freezegun import freeze_time
from app import db
from app.dao.fact_billing_dao import (
fetch_monthly_billing_for_year, fetch_billing_data_for_day, get_rates_for_billing,
get_rate
get_rate,
fetch_billing_totals_for_year,
)
from app.models import FactBilling
from app.utils import convert_utc_to_bst
@@ -21,6 +22,34 @@ from tests.app.db import (
)
def set_up_yearly_data():
service = create_service()
sms_template = create_template(service=service, template_type="sms")
email_template = create_template(service=service, template_type="email")
letter_template = create_template(service=service, template_type="letter")
for year in (2016, 2017):
for month in range(1, 13):
mon = str(month).zfill(2)
for day in range(1, monthrange(year, month)[1] + 1):
d = str(day).zfill(2)
create_ft_billing(bst_date='{}-{}-{}'.format(year, mon, d),
service=service,
template=sms_template,
notification_type='sms',
rate=0.162)
create_ft_billing(bst_date='{}-{}-{}'.format(year, mon, d),
service=service,
template=email_template,
notification_type='email',
rate=0)
create_ft_billing(bst_date='{}-{}-{}'.format(year, mon, d),
service=service,
template=letter_template,
notification_type='letter',
rate=0.33)
return service
def test_fetch_billing_data_for_today_includes_data_with_the_right_status(notify_db_session):
service = create_service()
template = create_template(service=service, template_type="email")
@@ -256,31 +285,7 @@ def test_fetch_monthly_billing_for_year_adds_data_for_today(notify_db_session):
def test_fetch_monthly_billing_for_year_return_financial_year(notify_db_session):
service = create_service()
sms_template = create_template(service=service, template_type="sms")
email_template = create_template(service=service, template_type="email")
letter_template = create_template(service=service, template_type="letter")
for year in (2016, 2017):
for month in range(1, 13):
mon = str(month).zfill(2)
for day in range(1, monthrange(year, month)[1] + 1):
d = str(day).zfill(2)
create_ft_billing(bst_date='{}-{}-{}'.format(year, mon, d),
service=service,
template=sms_template,
notification_type='sms',
rate=0.162)
create_ft_billing(bst_date='{}-{}-{}'.format(year, mon, d),
service=service,
template=email_template,
notification_type='email',
rate=0)
create_ft_billing(bst_date='{}-{}-{}'.format(year, mon, d),
service=service,
template=letter_template,
notification_type='letter',
rate=0.33)
service = set_up_yearly_data()
results = fetch_monthly_billing_for_year(service.id, 2016)
# returns 3 rows, per month, returns financial year april to end of march
@@ -304,3 +309,27 @@ def test_fetch_monthly_billing_for_year_return_financial_year(notify_db_session)
assert results[2].rate == Decimal('0.162')
assert str(results[3].month) == "2016-05-01"
assert str(results[35].month) == "2017-03-01"
def test_fetch_billing_totals_for_year(notify_db_session):
service = set_up_yearly_data()
results = fetch_billing_totals_for_year(service_id=service.id, year=2016)
assert len(results) == 3
assert results[0].notification_type == 'email'
assert results[0].service_id == service.id
assert results[0].notifications_sent == 365
assert results[0].billable_units == 365
assert results[0].rate == Decimal('0')
assert results[1].notification_type == 'letter'
assert results[1].service_id == service.id
assert results[1].notifications_sent == 365
assert results[1].billable_units == 365
assert results[1].rate == Decimal('0.33')
assert results[2].notification_type == 'sms'
assert results[2].service_id == service.id
assert results[2].notifications_sent == 365
assert results[2].billable_units == 365
assert results[2].rate == Decimal('0.162')