make create_ft_billing ensure data is correct

that is, the template must belong to the named service, and the
template's template_type must match a provided notification_type
This commit is contained in:
Leo Hemsted
2019-12-03 16:05:48 +00:00
parent d457db4164
commit ed5a52fe0d
2 changed files with 16 additions and 14 deletions

View File

@@ -214,12 +214,12 @@ 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_1, provider='firetext', billable_unit=4)
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',
rate_multiplier=2, billable_unit=1)
create_ft_billing('2018-06-03', 'sms', sms_template_2, service_1, provider='firetext', billable_unit=4)
create_ft_billing('2018-06-15', 'sms', sms_template_1, service_2, provider='firetext', 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)
result = dao_get_provider_stats()

View File

@@ -686,14 +686,16 @@ def create_ft_billing(bst_date,
notifications_sent=1,
postage='none',
):
if template:
service = template.service
notification_type = template.template_type
assert template is not None
if service is not None:
assert service == template.service
if notification_type is not None:
assert notification_type == template.template_type
data = FactBilling(bst_date=bst_date,
service_id=service.id,
service_id=template.service_id,
template_id=template.id,
notification_type=notification_type,
notification_type=template.template_type,
provider=provider,
rate_multiplier=rate_multiplier,
international=international,
@@ -909,12 +911,12 @@ def set_up_usage_data(start_date):
dao_add_service_to_organisation(service=service, organisation_id=org.id)
service_3 = create_service(service_name='c - letters only')
template_3 = create_template(service=service_3)
letter_template_3 = create_template(service=service_3, template_type='letter')
org_3 = create_organisation(name="Org for {}".format(service_3.name))
dao_add_service_to_organisation(service=service_3, organisation_id=org_3.id)
service_4 = create_service(service_name='d - service without org')
template_4 = create_template(service=service_4, template_type='letter')
letter_template_4 = create_template(service=service_4, template_type='letter')
service_sms_only = create_service(service_name='b - chargeable sms')
sms_template = create_template(service=service_sms_only, template_type='sms')
@@ -944,17 +946,17 @@ def set_up_usage_data(start_date):
template=sms_template, billable_unit=2, rate=0.11)
create_ft_billing(bst_date=start_date, service=service_3, notification_type='letter',
template=template_3,
template=letter_template_3,
notifications_sent=2, billable_unit=3, rate=.50, postage='first')
create_ft_billing(bst_date=one_week_later, service=service_3, notification_type='letter',
template=template_3,
template=letter_template_3,
notifications_sent=8, billable_unit=5, rate=.65, postage='second')
create_ft_billing(bst_date=one_month_later, service=service_3, notification_type='letter',
template=template_3,
template=letter_template_3,
notifications_sent=12, billable_unit=5, rate=.65, postage='second')
create_ft_billing(bst_date=two_days_later, service=service_4, notification_type='letter',
template=template_4,
template=letter_template_4,
notifications_sent=15, billable_unit=4, rate=.55, postage='second')
return org, org_3, service, service_3, service_4, service_sms_only