Rearrange fixture for readability

This commit is contained in:
Pea Tyczynska
2021-03-10 18:05:35 +00:00
parent 04525dc8c1
commit 0dbe4b27c8
3 changed files with 81 additions and 73 deletions

View File

@@ -600,111 +600,118 @@ def test_fetch_sms_billing_for_all_services_with_remainder(notify_db_session):
def test_fetch_sms_billing_for_all_services_without_an_organisation_appears(notify_db_session):
setup = set_up_usage_data(datetime(2019, 5, 1))
fixtures = set_up_usage_data(datetime(2019, 5, 1))
results = fetch_sms_billing_for_all_services(datetime(2019, 5, 1), datetime(2019, 5, 31))
assert len(results) == 2
assert len(results) == 3
# organisation_name, organisation_id, service_name, service_id, free_sms_fragment_limit,
# sms_rate, sms_remainder, sms_billable_units, chargeable_billable_units, sms_cost
assert results[0] == (
setup["org_1"].name,
setup["org_1"].id,
setup["service_1_sms_and_letter"].name,
setup["service_1_sms_and_letter"].id,
fixtures["org_1"].name,
fixtures["org_1"].id,
fixtures["service_1_sms_and_letter"].name,
fixtures["service_1_sms_and_letter"].id,
10, Decimal('0.11'), 8, 3, 0, Decimal('0'))
assert results[1] == (
None,
None,
setup["service_with_sms_without_org"].name,
setup["service_with_sms_without_org"].id,
fixtures["service_with_sms_without_org"].name,
fixtures["service_with_sms_without_org"].id,
10, Decimal('0.11'), 0, 3, 3, Decimal('0.33')
)
assert results[2] == (
None,
None,
fixtures["service_with_sms_within_allowance"].name,
fixtures["service_with_sms_within_allowance"].id,
10, Decimal('0.11'), 10, 2, 0, Decimal('0.00')
)
def test_fetch_letter_costs_for_all_services(notify_db_session):
setup = set_up_usage_data(datetime(2019, 6, 1))
fixtures = set_up_usage_data(datetime(2019, 6, 1))
results = fetch_letter_costs_for_all_services(datetime(2019, 6, 1), datetime(2019, 9, 30))
assert len(results) == 3
assert results[0] == (
setup["org_1"].name, setup["org_1"].id,
setup["service_1_sms_and_letter"].name, setup["service_1_sms_and_letter"].id,
fixtures["org_1"].name, fixtures["org_1"].id,
fixtures["service_1_sms_and_letter"].name, fixtures["service_1_sms_and_letter"].id,
Decimal('3.40')
)
assert results[1] == (
setup["org_for_service_with_letters"].name, setup["org_for_service_with_letters"].id,
setup["service_with_letters"].name, setup["service_with_letters"].id,
fixtures["org_for_service_with_letters"].name, fixtures["org_for_service_with_letters"].id,
fixtures["service_with_letters"].name, fixtures["service_with_letters"].id,
Decimal('14.00')
)
assert results[2] == (
None, None,
setup["service_with_letters_without_org"].name, setup["service_with_letters_without_org"].id,
fixtures["service_with_letters_without_org"].name, fixtures["service_with_letters_without_org"].id,
Decimal('24.45')
)
def test_fetch_letter_line_items_for_all_service(notify_db_session):
setup = set_up_usage_data(datetime(2019, 6, 1))
fixtures = set_up_usage_data(datetime(2019, 6, 1))
results = fetch_letter_line_items_for_all_services(datetime(2019, 6, 1), datetime(2019, 9, 30))
assert len(results) == 7
assert results[0] == (
setup["org_1"].name, setup["org_1"].id,
setup["service_1_sms_and_letter"].name, setup["service_1_sms_and_letter"].id,
fixtures["org_1"].name, fixtures["org_1"].id,
fixtures["service_1_sms_and_letter"].name, fixtures["service_1_sms_and_letter"].id,
Decimal('0.45'), 'second', 6
)
assert results[1] == (
setup["org_1"].name, setup["org_1"].id,
setup["service_1_sms_and_letter"].name, setup["service_1_sms_and_letter"].id,
fixtures["org_1"].name, fixtures["org_1"].id,
fixtures["service_1_sms_and_letter"].name, fixtures["service_1_sms_and_letter"].id,
Decimal("0.35"), 'first', 2
)
assert results[2] == (
setup["org_for_service_with_letters"].name, setup["org_for_service_with_letters"].id,
setup["service_with_letters"].name, setup["service_with_letters"].id,
fixtures["org_for_service_with_letters"].name, fixtures["org_for_service_with_letters"].id,
fixtures["service_with_letters"].name, fixtures["service_with_letters"].id,
Decimal("0.65"), 'second', 20
)
assert results[3] == (
setup["org_for_service_with_letters"].name, setup["org_for_service_with_letters"].id,
setup["service_with_letters"].name, setup["service_with_letters"].id,
fixtures["org_for_service_with_letters"].name, fixtures["org_for_service_with_letters"].id,
fixtures["service_with_letters"].name, fixtures["service_with_letters"].id,
Decimal("0.50"), 'first', 2
)
assert results[4] == (
None, None,
setup["service_with_letters_without_org"].name, setup["service_with_letters_without_org"].id,
fixtures["service_with_letters_without_org"].name, fixtures["service_with_letters_without_org"].id,
Decimal("0.35"), 'second', 2
)
assert results[5] == (
None, None,
setup["service_with_letters_without_org"].name, setup["service_with_letters_without_org"].id,
fixtures["service_with_letters_without_org"].name, fixtures["service_with_letters_without_org"].id,
Decimal("0.50"), 'first', 1
)
assert results[6] == (
None, None,
setup["service_with_letters_without_org"].name, setup["service_with_letters_without_org"].id,
fixtures["service_with_letters_without_org"].name, fixtures["service_with_letters_without_org"].id,
Decimal("1.55"), 'international', 15
)
@freeze_time('2019-06-01 13:30')
def test_fetch_usage_year_for_organisation(notify_db_session):
setup = 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')
dao_add_service_to_organisation(
service=service_with_emails_for_org,
organisation_id=setup["org_1"].id
organisation_id=fixtures["org_1"].id
)
template = create_template(service=service_with_emails_for_org, template_type='email')
create_ft_billing(bst_date=datetime(2019, 5, 1),
template=template,
notifications_sent=1100)
results = fetch_usage_year_for_organisation(setup["org_1"].id, 2019)
results = fetch_usage_year_for_organisation(fixtures["org_1"].id, 2019)
assert len(results) == 2
first_row = results[str(setup["service_1_sms_and_letter"].id)]
assert first_row['service_id'] == setup["service_1_sms_and_letter"].id
assert first_row['service_name'] == setup["service_1_sms_and_letter"].name
first_row = results[str(fixtures["service_1_sms_and_letter"].id)]
assert first_row['service_id'] == fixtures["service_1_sms_and_letter"].id
assert first_row['service_name'] == fixtures["service_1_sms_and_letter"].name
assert first_row['free_sms_limit'] == 10
assert first_row['sms_remainder'] == 10
assert first_row['chargeable_billable_sms'] == 0

View File

@@ -974,6 +974,17 @@ def set_up_usage_data(start_date):
organisation_id=org_1.id
)
create_ft_billing(bst_date=one_week_earlier, template=sms_template_1, billable_unit=2, rate=0.11)
create_ft_billing(bst_date=start_date, template=sms_template_1, billable_unit=2, rate=0.11)
create_ft_billing(bst_date=two_days_later, template=sms_template_1, billable_unit=1, rate=0.11)
create_ft_billing(bst_date=one_week_later, template=letter_template_1,
notifications_sent=2, billable_unit=1, rate=.35, postage='first')
create_ft_billing(bst_date=one_month_later, template=letter_template_1,
notifications_sent=4, billable_unit=2, rate=.45, postage='second')
create_ft_billing(bst_date=one_week_later, template=letter_template_1,
notifications_sent=2, billable_unit=2, rate=.45, postage='second')
# service with emails only:
service_with_emails = create_service(service_name='b - emails')
email_template = create_template(service=service_with_emails, template_type='email')
@@ -982,6 +993,8 @@ def set_up_usage_data(start_date):
)
dao_add_service_to_organisation(service=service_with_emails, organisation_id=org_2.id)
create_ft_billing(bst_date=start_date, template=email_template, notifications_sent=10)
# service with letters:
service_with_letters = create_service(service_name='c - letters only')
letter_template_3 = create_template(service=service_with_letters, template_type='letter')
@@ -994,10 +1007,26 @@ def set_up_usage_data(start_date):
)
dao_add_service_to_organisation(service=service_with_letters, organisation_id=org_for_service_with_letters.id)
create_ft_billing(bst_date=start_date, template=letter_template_3,
notifications_sent=2, billable_unit=3, rate=.50, postage='first')
create_ft_billing(bst_date=one_week_later, template=letter_template_3,
notifications_sent=8, billable_unit=5, rate=.65, postage='second')
create_ft_billing(bst_date=one_month_later, template=letter_template_3,
notifications_sent=12, billable_unit=5, rate=.65, postage='second')
# service with letters, without an organisation:
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')
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')
create_ft_billing(bst_date=two_days_later, template=letter_template_4,
notifications_sent=8, billable_unit=4, rate=1.55, postage='europe')
create_ft_billing(bst_date=two_days_later, template=letter_template_4,
notifications_sent=2, billable_unit=1, rate=.35, postage='second')
create_ft_billing(bst_date=two_days_later, template=letter_template_4,
notifications_sent=1, billable_unit=1, rate=.50, postage='first')
# service with chargeable SMS, without an organisation
service_with_sms_without_org = create_service(
service_name='b - chargeable sms',
@@ -1010,6 +1039,9 @@ def set_up_usage_data(start_date):
create_annual_billing(
service_id=service_with_sms_without_org.id, free_sms_fragment_limit=10, financial_year_start=year
)
create_ft_billing(bst_date=one_week_earlier, template=sms_template, rate=0.11, billable_unit=12)
create_ft_billing(bst_date=two_days_later, template=sms_template, rate=0.11)
create_ft_billing(bst_date=one_week_later, template=sms_template, billable_unit=2, rate=0.11)
# service with SMS within free allowance
service_with_sms_within_allowance = create_service(
@@ -1021,39 +1053,7 @@ def set_up_usage_data(start_date):
)
create_ft_billing(bst_date=one_week_later, template=sms_template_2, billable_unit=2, rate=0.11)
# all other ft billing isntances:
create_ft_billing(bst_date=one_week_earlier, template=sms_template_1, billable_unit=2, rate=0.11)
create_ft_billing(bst_date=start_date, template=sms_template_1, billable_unit=2, rate=0.11)
create_ft_billing(bst_date=two_days_later, template=sms_template_1, billable_unit=1, rate=0.11)
create_ft_billing(bst_date=one_week_later, template=letter_template_1,
notifications_sent=2, billable_unit=1, rate=.35, postage='first')
create_ft_billing(bst_date=one_month_later, template=letter_template_1,
notifications_sent=4, billable_unit=2, rate=.45, postage='second')
create_ft_billing(bst_date=one_week_later, template=letter_template_1,
notifications_sent=2, billable_unit=2, rate=.45, postage='second')
create_ft_billing(bst_date=one_week_earlier, template=sms_template, rate=0.11, billable_unit=12)
create_ft_billing(bst_date=two_days_later, template=sms_template, rate=0.11)
create_ft_billing(bst_date=one_week_later, template=sms_template, billable_unit=2, rate=0.11)
create_ft_billing(bst_date=start_date, template=letter_template_3,
notifications_sent=2, billable_unit=3, rate=.50, postage='first')
create_ft_billing(bst_date=one_week_later, template=letter_template_3,
notifications_sent=8, billable_unit=5, rate=.65, postage='second')
create_ft_billing(bst_date=one_month_later, template=letter_template_3,
notifications_sent=12, billable_unit=5, rate=.65, postage='second')
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')
create_ft_billing(bst_date=two_days_later, template=letter_template_4,
notifications_sent=8, billable_unit=4, rate=1.55, postage='europe')
create_ft_billing(bst_date=two_days_later, template=letter_template_4,
notifications_sent=2, billable_unit=1, rate=.35, postage='second')
create_ft_billing(bst_date=two_days_later, template=letter_template_4,
notifications_sent=1, billable_unit=1, rate=.50, postage='first')
create_ft_billing(bst_date=start_date, template=email_template, notifications_sent=10)
# dictionary with services and orgs to return
return {
"org_1": org_1,
"service_1_sms_and_letter": service_1_sms_and_letter,
@@ -1062,7 +1062,8 @@ def set_up_usage_data(start_date):
"org_for_service_with_letters": org_for_service_with_letters,
"service_with_letters": service_with_letters,
"service_with_letters_without_org": service_with_letters_without_org,
"service_with_sms_without_org": service_with_sms_without_org
"service_with_sms_without_org": service_with_sms_without_org,
"service_with_sms_within_allowance": service_with_sms_within_allowance,
}

View File

@@ -127,7 +127,7 @@ def test_validate_date_is_within_a_financial_year_when_input_is_not_a_date(start
def test_get_data_for_billing_report(notify_db_session, admin_request):
setup = set_up_usage_data(datetime(2019, 5, 1))
fixtures = set_up_usage_data(datetime(2019, 5, 1))
response = admin_request.get(
"platform_stats.get_data_for_billing_report",
start_date='2019-05-01',
@@ -137,8 +137,8 @@ def test_get_data_for_billing_report(notify_db_session, admin_request):
# we set up 6 services, but only 4 returned. service_with_emails was skipped as it had no bills to pay,
# and likewise the service with SMS within allowance was skipped. too.
assert len(response) == 4
assert response[0]["organisation_id"] == str(setup["org_1"].id)
assert response[0]["service_id"] == str(setup["service_1_sms_and_letter"].id)
assert response[0]["organisation_id"] == str(fixtures["org_1"].id)
assert response[0]["service_id"] == str(fixtures["service_1_sms_and_letter"].id)
assert response[0]["sms_cost"] == 0
assert response[0]["sms_fragments"] == 0
assert response[0]["letter_cost"] == 3.40
@@ -148,8 +148,8 @@ def test_get_data_for_billing_report(notify_db_session, admin_request):
assert response[0]["contact_email_addresses"] == "service@billing.contact email@addresses.gov.uk"
assert response[0]["billing_reference"] == "service billing reference"
assert response[1]["organisation_id"] == str(setup["org_for_service_with_letters"].id)
assert response[1]["service_id"] == str(setup["service_with_letters"].id)
assert response[1]["organisation_id"] == str(fixtures["org_for_service_with_letters"].id)
assert response[1]["service_id"] == str(fixtures["service_with_letters"].id)
assert response[1]["sms_cost"] == 0
assert response[1]["sms_fragments"] == 0
assert response[1]["letter_cost"] == 14
@@ -160,7 +160,7 @@ def test_get_data_for_billing_report(notify_db_session, admin_request):
assert response[1]["billing_reference"] == "org3 billing reference"
assert response[2]["organisation_id"] == ""
assert response[2]["service_id"] == str(setup["service_with_sms_without_org"].id)
assert response[2]["service_id"] == str(fixtures["service_with_sms_without_org"].id)
assert response[2]["sms_cost"] == 0.33
assert response[2]["sms_fragments"] == 3
assert response[2]["letter_cost"] == 0
@@ -171,7 +171,7 @@ def test_get_data_for_billing_report(notify_db_session, admin_request):
assert response[2]["billing_reference"] == "sms billing reference"
assert response[3]["organisation_id"] == ""
assert response[3]["service_id"] == str(setup["service_with_letters_without_org"].id)
assert response[3]["service_id"] == str(fixtures["service_with_letters_without_org"].id)
assert response[3]["sms_cost"] == 0
assert response[3]["sms_fragments"] == 0
assert response[3]["letter_cost"] == 24.45