mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-10 10:03:38 -04:00
Add more realistic test
Add statsd Fix imports
This commit is contained in:
@@ -542,6 +542,7 @@ def create_billing_record(data, rate, process_day):
|
|||||||
return billing_record
|
return billing_record
|
||||||
|
|
||||||
|
|
||||||
|
@statsd(namespace="dao")
|
||||||
def fetch_letter_costs_for_organisation(organisation_id, start_date, end_date):
|
def fetch_letter_costs_for_organisation(organisation_id, start_date, end_date):
|
||||||
query = db.session.query(
|
query = db.session.query(
|
||||||
Service.name.label("service_name"),
|
Service.name.label("service_name"),
|
||||||
@@ -552,7 +553,6 @@ def fetch_letter_costs_for_organisation(organisation_id, start_date, end_date):
|
|||||||
).join(
|
).join(
|
||||||
FactBilling, FactBilling.service_id == Service.id,
|
FactBilling, FactBilling.service_id == Service.id,
|
||||||
).filter(
|
).filter(
|
||||||
FactBilling.service_id == Service.id,
|
|
||||||
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,
|
||||||
@@ -567,6 +567,7 @@ def fetch_letter_costs_for_organisation(organisation_id, start_date, end_date):
|
|||||||
return query.all()
|
return query.all()
|
||||||
|
|
||||||
|
|
||||||
|
@statsd(namespace="dao")
|
||||||
def fetch_email_usage_for_organisation(organisation_id, start_date, end_date):
|
def fetch_email_usage_for_organisation(organisation_id, start_date, end_date):
|
||||||
query = db.session.query(
|
query = db.session.query(
|
||||||
Service.name.label("service_name"),
|
Service.name.label("service_name"),
|
||||||
@@ -636,6 +637,7 @@ def fetch_sms_billing_for_organisation(organisation_id, start_date, end_date):
|
|||||||
return query.all()
|
return query.all()
|
||||||
|
|
||||||
|
|
||||||
|
@statsd(namespace="dao")
|
||||||
def fetch_usage_year_for_organisation(organisation_id, year):
|
def fetch_usage_year_for_organisation(organisation_id, year):
|
||||||
year_start_datetime, year_end_datetime = get_financial_year(year)
|
year_start_datetime, year_end_datetime = get_financial_year(year)
|
||||||
|
|
||||||
@@ -662,8 +664,8 @@ def fetch_usage_year_for_organisation(organisation_id, year):
|
|||||||
'sms_remainder': 0,
|
'sms_remainder': 0,
|
||||||
'sms_billable_units': 0,
|
'sms_billable_units': 0,
|
||||||
'chargeable_billable_sms': 0,
|
'chargeable_billable_sms': 0,
|
||||||
'sms_cost': 0,
|
'sms_cost': 0.0,
|
||||||
'letter_cost': 0,
|
'letter_cost': 0.0,
|
||||||
'emails_sent': 0
|
'emails_sent': 0
|
||||||
}
|
}
|
||||||
sms_usages = fetch_sms_billing_for_organisation(organisation_id, year_start_date, year_end_date)
|
sms_usages = fetch_sms_billing_for_organisation(organisation_id, year_start_date, year_end_date)
|
||||||
@@ -676,9 +678,9 @@ def fetch_usage_year_for_organisation(organisation_id, year):
|
|||||||
'free_sms_limit': usage.free_sms_fragment_limit,
|
'free_sms_limit': usage.free_sms_fragment_limit,
|
||||||
'sms_remainder': usage.sms_remainder,
|
'sms_remainder': usage.sms_remainder,
|
||||||
'sms_billable_units': usage.sms_billable_units,
|
'sms_billable_units': usage.sms_billable_units,
|
||||||
'chargeable_billable_sms': float(usage.chargeable_billable_sms),
|
'chargeable_billable_sms': usage.chargeable_billable_sms,
|
||||||
'sms_cost': float(usage.sms_cost),
|
'sms_cost': float(usage.sms_cost),
|
||||||
'letter_cost': 0,
|
'letter_cost': 0.0,
|
||||||
'emails_sent': 0
|
'emails_sent': 0
|
||||||
}
|
}
|
||||||
for letter_usage in letter_usages:
|
for letter_usage in letter_usages:
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ from app.dao.fact_billing_dao import (
|
|||||||
get_rates_for_billing,
|
get_rates_for_billing,
|
||||||
fetch_sms_free_allowance_remainder,
|
fetch_sms_free_allowance_remainder,
|
||||||
fetch_sms_billing_for_all_services,
|
fetch_sms_billing_for_all_services,
|
||||||
fetch_letter_costs_for_all_services, fetch_letter_line_items_for_all_services, fetch_usage_year_for_organisation
|
fetch_letter_costs_for_all_services,
|
||||||
|
fetch_letter_line_items_for_all_services,
|
||||||
|
fetch_usage_year_for_organisation
|
||||||
)
|
)
|
||||||
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 (
|
from app.models import (
|
||||||
@@ -583,8 +585,6 @@ def test_fetch_sms_billing_for_all_services_with_remainder(notify_db_session):
|
|||||||
|
|
||||||
results = fetch_sms_billing_for_all_services(datetime(2019, 5, 1), datetime(2019, 5, 31))
|
results = fetch_sms_billing_for_all_services(datetime(2019, 5, 1), datetime(2019, 5, 31))
|
||||||
assert len(results) == 3
|
assert len(results) == 3
|
||||||
# (organisation_name, organisation_id, service_name, free_sms_fragment_limit, sms_rate,
|
|
||||||
# sms_remainder, sms_billable_units, chargeable_billable_sms, sms_cost)
|
|
||||||
assert results[0] == (org.name, org.id, service.name, service.id, 10, Decimal('0.11'), 8, 3, 0, Decimal('0'))
|
assert results[0] == (org.name, org.id, service.name, service.id, 10, Decimal('0.11'), 8, 3, 0, Decimal('0'))
|
||||||
assert results[1] == (org_2.name, org_2.id, service_2.name, service_2.id, 10, Decimal('0.11'), 0, 3, 3,
|
assert results[1] == (org_2.name, org_2.id, service_2.name, service_2.id, 10, Decimal('0.11'), 0, 3, 3,
|
||||||
Decimal('0.33'))
|
Decimal('0.33'))
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ from tests.app.db import (
|
|||||||
create_service,
|
create_service,
|
||||||
create_user,
|
create_user,
|
||||||
create_template,
|
create_template,
|
||||||
create_ft_billing
|
create_ft_billing,
|
||||||
|
create_annual_billing
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -750,7 +751,9 @@ def test_get_organisation_services_usage(admin_request, notify_db_session):
|
|||||||
service = create_service()
|
service = create_service()
|
||||||
template = create_template(service=service)
|
template = create_template(service=service)
|
||||||
dao_add_service_to_organisation(service=service, organisation_id=org.id)
|
dao_add_service_to_organisation(service=service, organisation_id=org.id)
|
||||||
create_ft_billing(bst_date=datetime.utcnow().date(), template=template, billable_unit=19, notifications_sent=19)
|
create_annual_billing(service_id=service.id, free_sms_fragment_limit=10, financial_year_start=2019)
|
||||||
|
create_ft_billing(bst_date=datetime.utcnow().date(), template=template, billable_unit=19, rate=0.060,
|
||||||
|
notifications_sent=19)
|
||||||
response = admin_request.get(
|
response = admin_request.get(
|
||||||
'organisation.get_organisation_services_usage',
|
'organisation.get_organisation_services_usage',
|
||||||
organisation_id=org.id,
|
organisation_id=org.id,
|
||||||
@@ -758,8 +761,16 @@ def test_get_organisation_services_usage(admin_request, notify_db_session):
|
|||||||
)
|
)
|
||||||
assert len(response) == 1
|
assert len(response) == 1
|
||||||
assert len(response['services']) == 1
|
assert len(response['services']) == 1
|
||||||
print(response)
|
service_usage = response['services'][0]
|
||||||
assert response['services'][0]['service_id'] == str(service.id)
|
assert service_usage['service_id'] == str(service.id)
|
||||||
|
assert service_usage['service_name'] == service.name
|
||||||
|
assert service_usage['chargeable_billable_sms'] == 9.0
|
||||||
|
assert service_usage['emails_sent'] == 0
|
||||||
|
assert service_usage['free_sms_limit'] == 10
|
||||||
|
assert service_usage['letter_cost'] == 0
|
||||||
|
assert service_usage['sms_billable_units'] == 19
|
||||||
|
assert service_usage['sms_remainder'] == 10
|
||||||
|
assert service_usage['sms_cost'] == 0.54
|
||||||
|
|
||||||
|
|
||||||
def test_get_organisation_services_usage_returns_400_if_year_is_invalid(admin_request):
|
def test_get_organisation_services_usage_returns_400_if_year_is_invalid(admin_request):
|
||||||
|
|||||||
Reference in New Issue
Block a user