mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-09 16:39:49 -04:00
Ensure org billing tests have AnnualBilling for all services
we add a row in AnnualBilling table whenever a new service is created, and our billing code assumes this is done. Yet when we were writing some of the tests, this was not a thing yet, so now we are updating those tests so they reflect our system well. Co-authored-by: Pea Tyczynska <pea.tyczynska@digital.cabinet-office.gov.uk>
This commit is contained in:
committed by
Pea Tyczynska
parent
112c2ddf72
commit
1c3793c5ac
@@ -21,7 +21,7 @@ from app.dao.fact_billing_dao import (
|
|||||||
fetch_volumes_by_service,
|
fetch_volumes_by_service,
|
||||||
get_rate,
|
get_rate,
|
||||||
get_rates_for_billing,
|
get_rates_for_billing,
|
||||||
query_organisation_sms_usage_for_year
|
query_organisation_sms_usage_for_year,
|
||||||
)
|
)
|
||||||
from app.dao.organisation_dao import dao_add_service_to_organisation
|
from app.dao.organisation_dao import dao_add_service_to_organisation
|
||||||
from app.models import NOTIFICATION_STATUS_TYPES, FactBilling
|
from app.models import NOTIFICATION_STATUS_TYPES, FactBilling
|
||||||
@@ -845,6 +845,7 @@ def test_fetch_letter_line_items_for_all_service(notify_db_session):
|
|||||||
def test_fetch_usage_year_for_organisation(notify_db_session):
|
def test_fetch_usage_year_for_organisation(notify_db_session):
|
||||||
fixtures = set_up_usage_data(datetime(2019, 5, 1))
|
fixtures = set_up_usage_data(datetime(2019, 5, 1))
|
||||||
service_with_emails_for_org = create_service(service_name='Service with emails for org')
|
service_with_emails_for_org = create_service(service_name='Service with emails for org')
|
||||||
|
create_annual_billing(service_with_emails_for_org.id, free_sms_fragment_limit=0, financial_year_start=2019)
|
||||||
dao_add_service_to_organisation(
|
dao_add_service_to_organisation(
|
||||||
service=service_with_emails_for_org,
|
service=service_with_emails_for_org,
|
||||||
organisation_id=fixtures["org_1"].id
|
organisation_id=fixtures["org_1"].id
|
||||||
@@ -1014,6 +1015,8 @@ def test_fetch_usage_year_for_organisation_only_returns_data_for_live_services(n
|
|||||||
notifications_sent=100)
|
notifications_sent=100)
|
||||||
create_ft_billing(bst_date=datetime.utcnow().date(), template=trial_letter_template, billable_unit=40, rate=0.30,
|
create_ft_billing(bst_date=datetime.utcnow().date(), template=trial_letter_template, billable_unit=40, rate=0.30,
|
||||||
notifications_sent=20)
|
notifications_sent=20)
|
||||||
|
create_annual_billing(service_id=live_service.id, free_sms_fragment_limit=0, financial_year_start=2019)
|
||||||
|
create_annual_billing(service_id=trial_service.id, free_sms_fragment_limit=0, financial_year_start=2019)
|
||||||
|
|
||||||
results = fetch_usage_year_for_organisation(organisation_id=org.id, year=2019)
|
results = fetch_usage_year_for_organisation(organisation_id=org.id, year=2019)
|
||||||
|
|
||||||
@@ -1247,7 +1250,8 @@ def test_fetch_volumes_by_service(notify_db_session):
|
|||||||
|
|
||||||
results = fetch_volumes_by_service(start_date=datetime(2022, 2, 1), end_date=datetime(2022, 2, 28))
|
results = fetch_volumes_by_service(start_date=datetime(2022, 2, 1), end_date=datetime(2022, 2, 28))
|
||||||
|
|
||||||
assert len(results) == 4
|
# since we are using a pre-set up fixture, we only care about some of the results
|
||||||
|
assert len(results) == 7
|
||||||
assert results[0].service_name == 'a - with sms and letter'
|
assert results[0].service_name == 'a - with sms and letter'
|
||||||
assert results[0].organisation_name == 'Org for a - with sms and letter'
|
assert results[0].organisation_name == 'Org for a - with sms and letter'
|
||||||
assert results[0].free_allowance == 10
|
assert results[0].free_allowance == 10
|
||||||
@@ -1268,22 +1272,22 @@ def test_fetch_volumes_by_service(notify_db_session):
|
|||||||
assert results[1].letter_sheet_totals == 0
|
assert results[1].letter_sheet_totals == 0
|
||||||
assert float(results[1].letter_cost) == 0
|
assert float(results[1].letter_cost) == 0
|
||||||
|
|
||||||
assert results[2].service_name == 'b - chargeable sms'
|
assert results[4].service_name == 'b - chargeable sms'
|
||||||
assert not results[2].organisation_name
|
assert not results[4].organisation_name
|
||||||
assert results[2].free_allowance == 10
|
assert results[4].free_allowance == 10
|
||||||
assert results[2].sms_notifications == 2
|
assert results[4].sms_notifications == 2
|
||||||
assert results[2].sms_chargeable_units == 3
|
assert results[4].sms_chargeable_units == 3
|
||||||
assert results[2].email_totals == 0
|
assert results[4].email_totals == 0
|
||||||
assert results[2].letter_totals == 0
|
assert results[4].letter_totals == 0
|
||||||
assert results[2].letter_sheet_totals == 0
|
assert results[4].letter_sheet_totals == 0
|
||||||
assert float(results[2].letter_cost) == 0
|
assert float(results[4].letter_cost) == 0
|
||||||
|
|
||||||
assert results[3].service_name == 'e - sms within allowance'
|
assert results[6].service_name == 'e - sms within allowance'
|
||||||
assert not results[3].organisation_name
|
assert not results[6].organisation_name
|
||||||
assert results[3].free_allowance == 10
|
assert results[6].free_allowance == 10
|
||||||
assert results[3].sms_notifications == 1
|
assert results[6].sms_notifications == 1
|
||||||
assert results[3].sms_chargeable_units == 2
|
assert results[6].sms_chargeable_units == 2
|
||||||
assert results[3].email_totals == 0
|
assert results[6].email_totals == 0
|
||||||
assert results[3].letter_totals == 0
|
assert results[6].letter_totals == 0
|
||||||
assert results[3].letter_sheet_totals == 0
|
assert results[6].letter_sheet_totals == 0
|
||||||
assert float(results[3].letter_cost) == 0
|
assert float(results[6].letter_cost) == 0
|
||||||
|
|||||||
@@ -998,6 +998,7 @@ def set_up_usage_data(start_date):
|
|||||||
name='Org for {}'.format(service_with_emails.name),
|
name='Org for {}'.format(service_with_emails.name),
|
||||||
)
|
)
|
||||||
dao_add_service_to_organisation(service=service_with_emails, organisation_id=org_2.id)
|
dao_add_service_to_organisation(service=service_with_emails, organisation_id=org_2.id)
|
||||||
|
create_annual_billing(service_id=service_with_emails.id, free_sms_fragment_limit=0, financial_year_start=year)
|
||||||
|
|
||||||
create_ft_billing(bst_date=start_date, template=email_template, notifications_sent=10)
|
create_ft_billing(bst_date=start_date, template=email_template, notifications_sent=10)
|
||||||
|
|
||||||
@@ -1012,6 +1013,7 @@ def set_up_usage_data(start_date):
|
|||||||
billing_reference="org3 billing reference"
|
billing_reference="org3 billing reference"
|
||||||
)
|
)
|
||||||
dao_add_service_to_organisation(service=service_with_letters, organisation_id=org_for_service_with_letters.id)
|
dao_add_service_to_organisation(service=service_with_letters, organisation_id=org_for_service_with_letters.id)
|
||||||
|
create_annual_billing(service_id=service_with_letters.id, free_sms_fragment_limit=0, financial_year_start=year)
|
||||||
|
|
||||||
create_ft_billing(bst_date=start_date, template=letter_template_3,
|
create_ft_billing(bst_date=start_date, template=letter_template_3,
|
||||||
notifications_sent=2, billable_unit=3, rate=.50, postage='first')
|
notifications_sent=2, billable_unit=3, rate=.50, postage='first')
|
||||||
@@ -1023,6 +1025,11 @@ def set_up_usage_data(start_date):
|
|||||||
# service with letters, without an organisation:
|
# service with letters, without an organisation:
|
||||||
service_with_letters_without_org = create_service(service_name='d - service without org')
|
service_with_letters_without_org = create_service(service_name='d - service without org')
|
||||||
letter_template_4 = create_template(service=service_with_letters_without_org, template_type='letter')
|
letter_template_4 = create_template(service=service_with_letters_without_org, template_type='letter')
|
||||||
|
create_annual_billing(
|
||||||
|
service_id=service_with_letters_without_org.id,
|
||||||
|
free_sms_fragment_limit=0,
|
||||||
|
financial_year_start=year
|
||||||
|
)
|
||||||
|
|
||||||
create_ft_billing(bst_date=two_days_later, template=letter_template_4,
|
create_ft_billing(bst_date=two_days_later, template=letter_template_4,
|
||||||
notifications_sent=7, billable_unit=4, rate=1.55, postage='rest-of-world')
|
notifications_sent=7, billable_unit=4, rate=1.55, postage='rest-of-world')
|
||||||
|
|||||||
@@ -214,7 +214,9 @@ def test_volumes_by_service_report(
|
|||||||
end_date='2022-03-01'
|
end_date='2022-03-01'
|
||||||
)
|
)
|
||||||
|
|
||||||
assert len(response) == 4
|
assert len(response) == 7
|
||||||
|
|
||||||
|
# since we are using a pre-set up fixture, we only care about some of the results
|
||||||
assert response[0] == {'email_totals': 0, 'free_allowance': 10, 'letter_cost': 0.0,
|
assert response[0] == {'email_totals': 0, 'free_allowance': 10, 'letter_cost': 0.0,
|
||||||
'letter_sheet_totals': 0, 'letter_totals': 0,
|
'letter_sheet_totals': 0, 'letter_totals': 0,
|
||||||
'organisation_id': str(fixture['org_1'].id),
|
'organisation_id': str(fixture['org_1'].id),
|
||||||
@@ -228,12 +230,12 @@ def test_volumes_by_service_report(
|
|||||||
'service_id': str(fixture['service_with_out_ft_billing_this_year'].id),
|
'service_id': str(fixture['service_with_out_ft_billing_this_year'].id),
|
||||||
'service_name': fixture['service_with_out_ft_billing_this_year'].name,
|
'service_name': fixture['service_with_out_ft_billing_this_year'].name,
|
||||||
'sms_chargeable_units': 0, 'sms_notifications': 0}
|
'sms_chargeable_units': 0, 'sms_notifications': 0}
|
||||||
assert response[2] == {'email_totals': 0, 'free_allowance': 10, 'letter_cost': 0.0, 'letter_sheet_totals': 0,
|
assert response[4] == {'email_totals': 0, 'free_allowance': 10, 'letter_cost': 0.0, 'letter_sheet_totals': 0,
|
||||||
'letter_totals': 0, 'organisation_id': '', 'organisation_name': '',
|
'letter_totals': 0, 'organisation_id': '', 'organisation_name': '',
|
||||||
'service_id': str(fixture['service_with_sms_without_org'].id),
|
'service_id': str(fixture['service_with_sms_without_org'].id),
|
||||||
'service_name': fixture['service_with_sms_without_org'].name,
|
'service_name': fixture['service_with_sms_without_org'].name,
|
||||||
'sms_chargeable_units': 0, 'sms_notifications': 0}
|
'sms_chargeable_units': 0, 'sms_notifications': 0}
|
||||||
assert response[3] == {'email_totals': 0, 'free_allowance': 10, 'letter_cost': 0.0, 'letter_sheet_totals': 0,
|
assert response[6] == {'email_totals': 0, 'free_allowance': 10, 'letter_cost': 0.0, 'letter_sheet_totals': 0,
|
||||||
'letter_totals': 0, 'organisation_id': '', 'organisation_name': '',
|
'letter_totals': 0, 'organisation_id': '', 'organisation_name': '',
|
||||||
'service_id': str(fixture['service_with_sms_within_allowance'].id),
|
'service_id': str(fixture['service_with_sms_within_allowance'].id),
|
||||||
'service_name': fixture['service_with_sms_within_allowance'].name,
|
'service_name': fixture['service_with_sms_within_allowance'].name,
|
||||||
|
|||||||
Reference in New Issue
Block a user