mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-24 00:06:16 -04:00
Fix bug on organisation-usage page.
The dict is initialised for all live services, but if the organisation has trial mode services they cause a key error.
This commit is contained in:
@@ -554,7 +554,8 @@ def fetch_letter_costs_for_organisation(organisation_id, start_date, end_date):
|
|||||||
FactBilling.bst_date >= start_date,
|
FactBilling.bst_date >= start_date,
|
||||||
FactBilling.bst_date <= end_date,
|
FactBilling.bst_date <= end_date,
|
||||||
FactBilling.notification_type == LETTER_TYPE,
|
FactBilling.notification_type == LETTER_TYPE,
|
||||||
Service.organisation_id == organisation_id
|
Service.organisation_id == organisation_id,
|
||||||
|
Service.restricted.is_(False)
|
||||||
).group_by(
|
).group_by(
|
||||||
Service.id,
|
Service.id,
|
||||||
Service.name,
|
Service.name,
|
||||||
@@ -579,7 +580,8 @@ def fetch_email_usage_for_organisation(organisation_id, start_date, end_date):
|
|||||||
FactBilling.bst_date >= start_date,
|
FactBilling.bst_date >= start_date,
|
||||||
FactBilling.bst_date <= end_date,
|
FactBilling.bst_date <= end_date,
|
||||||
FactBilling.notification_type == EMAIL_TYPE,
|
FactBilling.notification_type == EMAIL_TYPE,
|
||||||
Service.organisation_id == organisation_id
|
Service.organisation_id == organisation_id,
|
||||||
|
Service.restricted.is_(False)
|
||||||
).group_by(
|
).group_by(
|
||||||
Service.id,
|
Service.id,
|
||||||
Service.name,
|
Service.name,
|
||||||
@@ -621,7 +623,8 @@ def fetch_sms_billing_for_organisation(organisation_id, start_date, end_date):
|
|||||||
FactBilling.bst_date >= start_date,
|
FactBilling.bst_date >= start_date,
|
||||||
FactBilling.bst_date <= end_date,
|
FactBilling.bst_date <= end_date,
|
||||||
FactBilling.notification_type == SMS_TYPE,
|
FactBilling.notification_type == SMS_TYPE,
|
||||||
Service.organisation_id == organisation_id
|
Service.organisation_id == organisation_id,
|
||||||
|
Service.restricted.is_(False)
|
||||||
).group_by(
|
).group_by(
|
||||||
Service.id,
|
Service.id,
|
||||||
Service.name,
|
Service.name,
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ def persist_notification(
|
|||||||
billable_units=None,
|
billable_units=None,
|
||||||
postage=None,
|
postage=None,
|
||||||
template_postage=None,
|
template_postage=None,
|
||||||
document_download_count=None,
|
document_download_count=None
|
||||||
):
|
):
|
||||||
notification_created_at = created_at or datetime.utcnow()
|
notification_created_at = created_at or datetime.utcnow()
|
||||||
if not notification_id:
|
if not notification_id:
|
||||||
|
|||||||
@@ -684,13 +684,28 @@ def test_fetch_usage_year_for_organisation_populates_ft_billing_for_today(notify
|
|||||||
assert FactBilling.query.count() == 1
|
assert FactBilling.query.count() == 1
|
||||||
|
|
||||||
|
|
||||||
|
@freeze_time('2020-02-27 13:30')
|
||||||
def test_fetch_usage_year_for_organisation_only_returns_data_for_live_services(notify_db_session):
|
def test_fetch_usage_year_for_organisation_only_returns_data_for_live_services(notify_db_session):
|
||||||
org = create_organisation(name='Organisation without live services')
|
org = create_organisation(name='Organisation without live services')
|
||||||
service = create_service(restricted=True)
|
live_service = create_service(restricted=False)
|
||||||
template = create_template(service=service)
|
sms_template = create_template(service=live_service)
|
||||||
dao_add_service_to_organisation(service=service, organisation_id=org.id)
|
trial_service = create_service(restricted=True, service_name='trial_service')
|
||||||
create_ft_billing(bst_date=datetime.utcnow().date(), template=template, billable_unit=19, notifications_sent=19)
|
email_template = create_template(service=trial_service, template_type='email')
|
||||||
|
trial_sms_template = create_template(service=trial_service, template_type='sms')
|
||||||
|
trial_letter_template = create_template(service=trial_service, template_type='letter')
|
||||||
|
dao_add_service_to_organisation(service=live_service, organisation_id=org.id)
|
||||||
|
dao_add_service_to_organisation(service=trial_service, organisation_id=org.id)
|
||||||
|
create_ft_billing(bst_date=datetime.utcnow().date(), template=sms_template, rate=0.0158,
|
||||||
|
billable_unit=19, notifications_sent=19)
|
||||||
|
create_ft_billing(bst_date=datetime.utcnow().date(), template=email_template, billable_unit=0,
|
||||||
|
notifications_sent=100)
|
||||||
|
create_ft_billing(bst_date=datetime.utcnow().date(), template=trial_sms_template, billable_unit=200, rate=0.0158,
|
||||||
|
notifications_sent=100)
|
||||||
|
create_ft_billing(bst_date=datetime.utcnow().date(), template=trial_letter_template, billable_unit=40, rate=0.30,
|
||||||
|
notifications_sent=20)
|
||||||
|
|
||||||
results = fetch_usage_year_for_organisation(organisation_id=org.id, year=datetime.utcnow().year)
|
results = fetch_usage_year_for_organisation(organisation_id=org.id, year=2019)
|
||||||
|
|
||||||
assert len(results) == 0
|
assert len(results) == 1
|
||||||
|
assert results[str(live_service.id)]['sms_billable_units'] == 19
|
||||||
|
assert results[str(live_service.id)]['emails_sent'] == 0
|
||||||
|
|||||||
Reference in New Issue
Block a user