mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-02 17:48:36 -04:00
remove notification_type and service from create_ft_billing
they can both be inferred from the template, and specifying them just leads to unnecessary risk of errors
This commit is contained in:
@@ -51,20 +51,10 @@ def set_up_yearly_data():
|
||||
for n in range((end_date - start_date).days):
|
||||
dt = start_date + timedelta(days=n)
|
||||
|
||||
create_ft_billing(bst_date=dt,
|
||||
template=sms_template,
|
||||
rate=0.162)
|
||||
create_ft_billing(bst_date=dt,
|
||||
template=email_template,
|
||||
rate=0)
|
||||
create_ft_billing(bst_date=dt,
|
||||
template=letter_template,
|
||||
rate=0.33,
|
||||
postage='second')
|
||||
create_ft_billing(bst_date=dt,
|
||||
template=letter_template,
|
||||
rate=0.30,
|
||||
postage='second')
|
||||
create_ft_billing(bst_date=dt, template=sms_template, rate=0.162)
|
||||
create_ft_billing(bst_date=dt, template=email_template, rate=0)
|
||||
create_ft_billing(bst_date=dt, template=letter_template, rate=0.33, postage='second')
|
||||
create_ft_billing(bst_date=dt, template=letter_template, rate=0.30, postage='second')
|
||||
return service
|
||||
|
||||
|
||||
@@ -382,16 +372,12 @@ def test_fetch_monthly_billing_for_year(notify_db_session):
|
||||
template = create_template(service=service, template_type="sms")
|
||||
for i in range(1, 31):
|
||||
create_ft_billing(bst_date='2018-06-{}'.format(i),
|
||||
service=service,
|
||||
template=template,
|
||||
notification_type='sms',
|
||||
rate_multiplier=2,
|
||||
rate=0.162)
|
||||
for i in range(1, 32):
|
||||
create_ft_billing(bst_date='2018-07-{}'.format(i),
|
||||
service=service,
|
||||
template=template,
|
||||
notification_type='sms',
|
||||
rate=0.158)
|
||||
|
||||
results = fetch_monthly_billing_for_year(service_id=service.id, year=2018)
|
||||
@@ -417,11 +403,7 @@ def test_fetch_monthly_billing_for_year_adds_data_for_today(notify_db_session):
|
||||
service = create_service()
|
||||
template = create_template(service=service, template_type="email")
|
||||
for i in range(1, 32):
|
||||
create_ft_billing(bst_date='2018-07-{}'.format(i),
|
||||
service=service,
|
||||
template=template,
|
||||
notification_type='email',
|
||||
rate=0.162)
|
||||
create_ft_billing(bst_date='2018-07-{}'.format(i), template=template)
|
||||
create_notification(template=template, status='delivered')
|
||||
|
||||
assert db.session.query(FactBilling.bst_date).count() == 31
|
||||
@@ -497,11 +479,11 @@ def test_delete_billing_data(notify_db_session):
|
||||
other_service_template = create_template(service_2, 'sms')
|
||||
|
||||
existing_rows_to_delete = [ # noqa
|
||||
create_ft_billing('2018-01-01', 'sms', sms_template, service_1, billable_unit=1),
|
||||
create_ft_billing('2018-01-01', 'email', email_template, service_1, billable_unit=2)
|
||||
create_ft_billing('2018-01-01', sms_template, billable_unit=1),
|
||||
create_ft_billing('2018-01-01', email_template, billable_unit=2)
|
||||
]
|
||||
other_day = create_ft_billing('2018-01-02', 'sms', sms_template, service_1, billable_unit=3)
|
||||
other_service = create_ft_billing('2018-01-01', 'sms', other_service_template, service_2, billable_unit=4)
|
||||
other_day = create_ft_billing('2018-01-02', sms_template, billable_unit=3)
|
||||
other_service = create_ft_billing('2018-01-01', other_service_template, billable_unit=4)
|
||||
|
||||
delete_billing_data_for_service_for_day('2018-01-01', service_1.id)
|
||||
|
||||
@@ -517,22 +499,18 @@ def test_fetch_sms_free_allowance_remainder_with_two_services(notify_db_session)
|
||||
org = create_organisation(name="Org for {}".format(service.name))
|
||||
dao_add_service_to_organisation(service=service, organisation_id=org.id)
|
||||
create_annual_billing(service_id=service.id, free_sms_fragment_limit=10, financial_year_start=2016)
|
||||
create_ft_billing(service=service, template=template,
|
||||
bst_date=datetime(2016, 4, 20), notification_type='sms', billable_unit=2, rate=0.11)
|
||||
create_ft_billing(service=service, template=template, bst_date=datetime(2016, 5, 20), notification_type='sms',
|
||||
billable_unit=3, rate=0.11)
|
||||
create_ft_billing(template=template, bst_date=datetime(2016, 4, 20), billable_unit=2, rate=0.11)
|
||||
create_ft_billing(template=template, bst_date=datetime(2016, 5, 20), billable_unit=3, rate=0.11)
|
||||
|
||||
service_2 = create_service(service_name='used free allowance')
|
||||
template_2 = create_template(service=service_2)
|
||||
org_2 = create_organisation(name="Org for {}".format(service_2.name))
|
||||
dao_add_service_to_organisation(service=service_2, organisation_id=org_2.id)
|
||||
create_annual_billing(service_id=service_2.id, free_sms_fragment_limit=20, financial_year_start=2016)
|
||||
create_ft_billing(service=service_2, template=template_2, bst_date=datetime(2016, 4, 20), notification_type='sms',
|
||||
billable_unit=12, rate=0.11)
|
||||
create_ft_billing(service=service_2, template=template_2, bst_date=datetime(2016, 4, 22), notification_type='sms',
|
||||
billable_unit=10, rate=0.11)
|
||||
create_ft_billing(service=service_2, template=template_2, bst_date=datetime(2016, 5, 20), notification_type='sms',
|
||||
billable_unit=3, rate=0.11)
|
||||
create_ft_billing(template=template_2, bst_date=datetime(2016, 4, 20), billable_unit=12, rate=0.11)
|
||||
create_ft_billing(template=template_2, bst_date=datetime(2016, 4, 22), billable_unit=10, rate=0.11)
|
||||
create_ft_billing(template=template_2, bst_date=datetime(2016, 5, 20), billable_unit=3, rate=0.11)
|
||||
|
||||
results = fetch_sms_free_allowance_remainder(datetime(2016, 5, 1)).all()
|
||||
assert len(results) == 2
|
||||
service_result = [row for row in results if row[0] == service.id]
|
||||
@@ -548,8 +526,7 @@ def test_fetch_sms_billing_for_all_services_for_first_quarter(notify_db_session)
|
||||
org = create_organisation(name="Org for {}".format(service.name))
|
||||
dao_add_service_to_organisation(service=service, organisation_id=org.id)
|
||||
create_annual_billing(service_id=service.id, free_sms_fragment_limit=25000, financial_year_start=2019)
|
||||
create_ft_billing(service=service, template=template,
|
||||
bst_date=datetime(2019, 4, 20), notification_type='sms', billable_unit=44, rate=0.11)
|
||||
create_ft_billing(template=template, bst_date=datetime(2019, 4, 20), billable_unit=44, rate=0.11)
|
||||
results = fetch_sms_billing_for_all_services(datetime(2019, 4, 1), datetime(2019, 5, 30))
|
||||
assert len(results) == 1
|
||||
assert results[0] == (org.name, org.id, service.name, service.id, 25000, Decimal('0.11'), 25000, 44, 0,
|
||||
@@ -562,39 +539,33 @@ def test_fetch_sms_billing_for_all_services_with_remainder(notify_db_session):
|
||||
org = create_organisation(name="Org for {}".format(service.name))
|
||||
dao_add_service_to_organisation(service=service, organisation_id=org.id)
|
||||
create_annual_billing(service_id=service.id, free_sms_fragment_limit=10, financial_year_start=2019)
|
||||
create_ft_billing(service=service, template=template,
|
||||
bst_date=datetime(2019, 4, 20), notification_type='sms', billable_unit=2, rate=0.11)
|
||||
create_ft_billing(service=service, template=template, bst_date=datetime(2019, 5, 20), notification_type='sms',
|
||||
billable_unit=2, rate=0.11)
|
||||
create_ft_billing(service=service, template=template, bst_date=datetime(2019, 5, 22), notification_type='sms',
|
||||
billable_unit=1, rate=0.11)
|
||||
create_ft_billing(template=template, bst_date=datetime(2019, 4, 20), billable_unit=2, rate=0.11)
|
||||
create_ft_billing(template=template, bst_date=datetime(2019, 5, 20), billable_unit=2, rate=0.11)
|
||||
create_ft_billing(template=template, bst_date=datetime(2019, 5, 22), billable_unit=1, rate=0.11)
|
||||
|
||||
service_2 = create_service(service_name='b - used free allowance')
|
||||
template_2 = create_template(service=service_2)
|
||||
org_2 = create_organisation(name="Org for {}".format(service_2.name))
|
||||
dao_add_service_to_organisation(service=service_2, organisation_id=org_2.id)
|
||||
create_annual_billing(service_id=service_2.id, free_sms_fragment_limit=10, financial_year_start=2019)
|
||||
create_ft_billing(service=service_2, template=template_2, bst_date=datetime(2019, 4, 20), notification_type='sms',
|
||||
billable_unit=12, rate=0.11)
|
||||
create_ft_billing(service=service_2, template=template_2, bst_date=datetime(2019, 5, 20), notification_type='sms',
|
||||
billable_unit=3, rate=0.11)
|
||||
create_ft_billing(template=template_2, bst_date=datetime(2019, 4, 20), billable_unit=12, rate=0.11)
|
||||
create_ft_billing(template=template_2, bst_date=datetime(2019, 5, 20), billable_unit=3, rate=0.11)
|
||||
|
||||
service_3 = create_service(service_name='c - partial allowance')
|
||||
template_3 = create_template(service=service_3)
|
||||
org_3 = create_organisation(name="Org for {}".format(service_3.name))
|
||||
dao_add_service_to_organisation(service=service_3, organisation_id=org_3.id)
|
||||
create_annual_billing(service_id=service_3.id, free_sms_fragment_limit=10, financial_year_start=2019)
|
||||
create_ft_billing(service=service_3, template=template_3, bst_date=datetime(2019, 4, 20), notification_type='sms',
|
||||
billable_unit=5, rate=0.11)
|
||||
create_ft_billing(service=service_3, template=template_3, bst_date=datetime(2019, 5, 20), notification_type='sms',
|
||||
billable_unit=7, rate=0.11)
|
||||
create_ft_billing(template=template_3, bst_date=datetime(2019, 4, 20), billable_unit=5, rate=0.11)
|
||||
create_ft_billing(template=template_3, bst_date=datetime(2019, 5, 20), billable_unit=7, rate=0.11)
|
||||
|
||||
service_4 = create_service(service_name='d - email only')
|
||||
email_template = create_template(service=service_4, template_type='email')
|
||||
org_4 = create_organisation(name="Org for {}".format(service_4.name))
|
||||
dao_add_service_to_organisation(service=service_4, organisation_id=org_4.id)
|
||||
create_annual_billing(service_id=service_4.id, free_sms_fragment_limit=10, financial_year_start=2019)
|
||||
create_ft_billing(service=service_4, template=email_template, bst_date=datetime(2019, 5, 22), notifications_sent=5,
|
||||
notification_type='email', billable_unit=0, rate=0)
|
||||
create_ft_billing(template=email_template, bst_date=datetime(2019, 5, 22), notifications_sent=5,
|
||||
billable_unit=0, rate=0)
|
||||
|
||||
results = fetch_sms_billing_for_all_services(datetime(2019, 5, 1), datetime(2019, 5, 31))
|
||||
assert len(results) == 3
|
||||
|
||||
@@ -214,13 +214,13 @@ def test_dao_get_provider_stats(notify_db_session):
|
||||
sms_template_1 = create_template(service_1, 'sms')
|
||||
sms_template_2 = create_template(service_2, 'sms')
|
||||
|
||||
create_ft_billing('2017-06-05', 'sms', sms_template_2, service_2, provider='firetext', billable_unit=4)
|
||||
create_ft_billing('2018-05-31', 'sms', sms_template_1, service_1, provider='mmg', billable_unit=1)
|
||||
create_ft_billing('2018-06-01', 'sms', sms_template_1, service_1, provider='mmg',
|
||||
create_ft_billing('2017-06-05', sms_template_2, provider='firetext', billable_unit=4)
|
||||
create_ft_billing('2018-05-31', sms_template_1, provider='mmg', billable_unit=1)
|
||||
create_ft_billing('2018-06-01', sms_template_1, provider='mmg',
|
||||
rate_multiplier=2, billable_unit=1)
|
||||
create_ft_billing('2018-06-03', 'sms', sms_template_2, service_2, provider='firetext', billable_unit=4)
|
||||
create_ft_billing('2018-06-15', 'sms', sms_template_1, service_1, provider='firetext', billable_unit=1)
|
||||
create_ft_billing('2018-06-28', 'sms', sms_template_2, service_2, provider='mmg', billable_unit=2)
|
||||
create_ft_billing('2018-06-03', sms_template_2, provider='firetext', billable_unit=4)
|
||||
create_ft_billing('2018-06-15', sms_template_1, provider='firetext', billable_unit=1)
|
||||
create_ft_billing('2018-06-28', sms_template_2, provider='mmg', billable_unit=2)
|
||||
|
||||
result = dao_get_provider_stats()
|
||||
|
||||
|
||||
@@ -444,28 +444,28 @@ def test_get_all_user_services_should_return_empty_list_if_no_services_for_user(
|
||||
def test_dao_fetch_live_services_data(sample_user):
|
||||
org = create_organisation(organisation_type='nhs_central')
|
||||
service = create_service(go_live_user=sample_user, go_live_at='2014-04-20T10:00:00')
|
||||
template = create_template(service=service)
|
||||
sms_template = create_template(service=service)
|
||||
service_2 = create_service(service_name='second', go_live_at='2017-04-20T10:00:00', go_live_user=sample_user)
|
||||
service_3 = create_service(service_name='third', go_live_at='2016-04-20T10:00:00')
|
||||
# below services should be filtered out:
|
||||
create_service(service_name='restricted', restricted=True)
|
||||
create_service(service_name='not_active', active=False)
|
||||
create_service(service_name='not_live', count_as_live=False)
|
||||
template2 = create_template(service=service, template_type='email')
|
||||
email_template = create_template(service=service, template_type='email')
|
||||
template_letter_1 = create_template(service=service, template_type='letter')
|
||||
template_letter_2 = create_template(service=service_2, template_type='letter')
|
||||
dao_add_service_to_organisation(service=service, organisation_id=org.id)
|
||||
# two sms billing records for 1st service within current financial year:
|
||||
create_ft_billing(bst_date='2019-04-20', notification_type='sms', template=template, service=service)
|
||||
create_ft_billing(bst_date='2019-04-21', notification_type='sms', template=template, service=service)
|
||||
create_ft_billing(bst_date='2019-04-20', template=sms_template)
|
||||
create_ft_billing(bst_date='2019-04-21', template=sms_template)
|
||||
# one sms billing record for 1st service from previous financial year, should not appear in the result:
|
||||
create_ft_billing(bst_date='2018-04-20', notification_type='sms', template=template, service=service)
|
||||
create_ft_billing(bst_date='2018-04-20', template=sms_template)
|
||||
# one email billing record for 1st service within current financial year:
|
||||
create_ft_billing(bst_date='2019-04-20', notification_type='email', template=template2, service=service)
|
||||
create_ft_billing(bst_date='2019-04-20', template=email_template)
|
||||
# one letter billing record for 1st service within current financial year:
|
||||
create_ft_billing(bst_date='2019-04-15', notification_type='letter', template=template_letter_1, service=service)
|
||||
create_ft_billing(bst_date='2019-04-15', template=template_letter_1)
|
||||
# one letter billing record for 2nd service within current financial year:
|
||||
create_ft_billing(bst_date='2019-04-16', notification_type='letter', template=template_letter_2, service=service_2)
|
||||
create_ft_billing(bst_date='2019-04-16', template=template_letter_2)
|
||||
|
||||
# 1st service: billing from 2018 and 2019
|
||||
create_annual_billing(service.id, 500, 2018)
|
||||
|
||||
Reference in New Issue
Block a user