Update ft_billing DAO functions to use postage

* Updated the 'fetch_billing_data_for_day' DAO function to take postage into
account
* Updated the 'update_fact_billing' DAO function to insert postage for
new rows. When updating rows which are identical apart from the postage, the
original row will be kept. (This behaviour will change once postage is
added to the primary key - at this point, upserting will add a new row.)
* Also changed some fixtures / test set up functions to take postage
into account
This commit is contained in:
Katie Smith
2018-09-26 11:28:59 +01:00
parent 0b5da2b8ad
commit 6727f0e0f5
6 changed files with 95 additions and 14 deletions

View File

@@ -50,12 +50,14 @@ def set_up_yearly_data():
service=service,
template=letter_template,
notification_type='letter',
rate=0.33)
rate=0.33,
postage='second')
create_ft_billing(bst_date='{}-{}-{}'.format(year, mon, d),
service=service,
template=letter_template,
notification_type='letter',
rate=0.30)
rate=0.30,
postage='second')
return service
@@ -190,6 +192,34 @@ def test_fetch_billing_data_for_day_is_grouped_by_notification_type(notify_db_se
assert len(notification_types) == 3
def test_fetch_billing_data_for_day_groups_by_postage(notify_db_session):
service = create_service()
letter_template = create_template(service=service, template_type='letter')
email_template = create_template(service=service, template_type='email')
create_notification(template=letter_template, status='delivered', postage='first')
create_notification(template=letter_template, status='delivered', postage='first')
create_notification(template=letter_template, status='delivered', postage='second')
create_notification(template=email_template, status='delivered')
today = convert_utc_to_bst(datetime.utcnow())
results = fetch_billing_data_for_day(today)
assert len(results) == 3
def test_fetch_billing_data_for_day_sets_postage_for_emails_and_sms_to_none(notify_db_session):
service = create_service()
sms_template = create_template(service=service, template_type='sms')
email_template = create_template(service=service, template_type='email')
create_notification(template=sms_template, status='delivered')
create_notification(template=email_template, status='delivered')
today = convert_utc_to_bst(datetime.utcnow())
results = fetch_billing_data_for_day(today)
assert len(results) == 2
assert results[0].postage == 'none'
assert results[1].postage == 'none'
def test_fetch_billing_data_for_day_returns_empty_list(notify_db_session):
today = convert_utc_to_bst(datetime.utcnow())
results = fetch_billing_data_for_day(today)