mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-20 14:29:25 -04:00
Merge branch 'populate-monthly-letter-usages' of github.com:alphagov/notifications-api into populate-monthly-letter-usages
This commit is contained in:
@@ -52,6 +52,11 @@ def get_billing_data_for_month(service_id, start_date, end_date, notification_ty
|
|||||||
elif notification_type == LETTER_TYPE:
|
elif notification_type == LETTER_TYPE:
|
||||||
results.extend(billing_letter_data_per_month_query(service_id, start_date, end_date))
|
results.extend(billing_letter_data_per_month_query(service_id, start_date, end_date))
|
||||||
|
|
||||||
|
if notification_type == LETTER_TYPE:
|
||||||
|
results.extend(billing_letter_data_per_month_query(
|
||||||
|
service_id=service_id, start_date=start_date, end_date=end_date)
|
||||||
|
)
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -286,12 +286,11 @@ def get_service_provider_aggregate_statistics(service_id):
|
|||||||
# tables. This is so product owner can pass stories as done
|
# tables. This is so product owner can pass stories as done
|
||||||
@service_blueprint.route('/<uuid:service_id>/history', methods=['GET'])
|
@service_blueprint.route('/<uuid:service_id>/history', methods=['GET'])
|
||||||
def get_service_history(service_id):
|
def get_service_history(service_id):
|
||||||
from app.models import (Service, ApiKey, TemplateHistory, Event)
|
from app.models import (Service, ApiKey, TemplateHistory)
|
||||||
from app.schemas import (
|
from app.schemas import (
|
||||||
service_history_schema,
|
service_history_schema,
|
||||||
api_key_history_schema,
|
api_key_history_schema,
|
||||||
template_history_schema,
|
template_history_schema
|
||||||
event_schema
|
|
||||||
)
|
)
|
||||||
|
|
||||||
service_history = Service.get_history_model().query.filter_by(id=service_id).all()
|
service_history = Service.get_history_model().query.filter_by(id=service_id).all()
|
||||||
@@ -302,14 +301,11 @@ def get_service_history(service_id):
|
|||||||
template_history = TemplateHistory.query.filter_by(service_id=service_id).all()
|
template_history = TemplateHistory.query.filter_by(service_id=service_id).all()
|
||||||
template_data, errors = template_history_schema.dump(template_history, many=True)
|
template_data, errors = template_history_schema.dump(template_history, many=True)
|
||||||
|
|
||||||
events = Event.query.all()
|
|
||||||
events_data = event_schema.dump(events, many=True).data
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'service_history': service_data,
|
'service_history': service_data,
|
||||||
'api_key_history': api_keys_data,
|
'api_key_history': api_keys_data,
|
||||||
'template_history': template_data,
|
'template_history': template_data,
|
||||||
'events': events_data}
|
'events': []}
|
||||||
|
|
||||||
return jsonify(data=data)
|
return jsonify(data=data)
|
||||||
|
|
||||||
|
|||||||
@@ -706,6 +706,7 @@ def test_populate_monthly_billing_updates_correct_month_in_bst(sample_template):
|
|||||||
assert monthly_billing[2].notification_type == 'letter'
|
assert monthly_billing[2].notification_type == 'letter'
|
||||||
assert monthly_billing[2].monthly_totals == []
|
assert monthly_billing[2].monthly_totals == []
|
||||||
|
|
||||||
|
|
||||||
def test_run_letter_jobs(client, mocker, sample_letter_template):
|
def test_run_letter_jobs(client, mocker, sample_letter_template):
|
||||||
jobs = [create_job(template=sample_letter_template, job_status=JOB_STATUS_READY_TO_SEND),
|
jobs = [create_job(template=sample_letter_template, job_status=JOB_STATUS_READY_TO_SEND),
|
||||||
create_job(template=sample_letter_template, job_status=JOB_STATUS_READY_TO_SEND)]
|
create_job(template=sample_letter_template, job_status=JOB_STATUS_READY_TO_SEND)]
|
||||||
|
|||||||
@@ -11,13 +11,14 @@ from app.dao.monthly_billing_dao import (
|
|||||||
get_billing_data_for_financial_year
|
get_billing_data_for_financial_year
|
||||||
)
|
)
|
||||||
from app.models import MonthlyBilling, SMS_TYPE, EMAIL_TYPE
|
from app.models import MonthlyBilling, SMS_TYPE, EMAIL_TYPE
|
||||||
|
from tests.app.conftest import sample_letter_template
|
||||||
from tests.app.db import (
|
from tests.app.db import (
|
||||||
create_notification,
|
create_notification,
|
||||||
create_rate,
|
create_rate,
|
||||||
create_service,
|
create_service,
|
||||||
create_template,
|
create_template,
|
||||||
create_monthly_billing_entry
|
create_monthly_billing_entry,
|
||||||
)
|
create_letter_rate)
|
||||||
|
|
||||||
FEB_2016_MONTH_START = datetime(2016, 2, 1)
|
FEB_2016_MONTH_START = datetime(2016, 2, 1)
|
||||||
FEB_2016_MONTH_END = datetime(2016, 2, 29, 23, 59, 59, 99999)
|
FEB_2016_MONTH_END = datetime(2016, 2, 29, 23, 59, 59, 99999)
|
||||||
@@ -253,8 +254,9 @@ def test_add_monthly_billing_for_multiple_months_populate_correctly(
|
|||||||
|
|
||||||
|
|
||||||
def test_add_monthly_billing_with_multiple_rates_populate_correctly(
|
def test_add_monthly_billing_with_multiple_rates_populate_correctly(
|
||||||
sample_template
|
sample_template, sample_email_template
|
||||||
):
|
):
|
||||||
|
letter_template = sample_letter_template(sample_template.service)
|
||||||
create_rate(start_date=JAN_2017_MONTH_START, value=0.0158, notification_type=SMS_TYPE)
|
create_rate(start_date=JAN_2017_MONTH_START, value=0.0158, notification_type=SMS_TYPE)
|
||||||
create_rate(start_date=JAN_2017_MONTH_START + timedelta(days=5), value=0.123, notification_type=SMS_TYPE)
|
create_rate(start_date=JAN_2017_MONTH_START + timedelta(days=5), value=0.123, notification_type=SMS_TYPE)
|
||||||
create_notification(template=sample_template, created_at=JAN_2017_MONTH_START, billable_units=1, status='delivered')
|
create_notification(template=sample_template, created_at=JAN_2017_MONTH_START, billable_units=1, status='delivered')
|
||||||
@@ -263,6 +265,11 @@ def test_add_monthly_billing_with_multiple_rates_populate_correctly(
|
|||||||
billable_units=2, status='delivered'
|
billable_units=2, status='delivered'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
create_notification(template=sample_email_template, created_at=JAN_2017_MONTH_START, status='delivered')
|
||||||
|
create_notification(template=letter_template, created_at=JAN_2017_MONTH_START, status='delivered',
|
||||||
|
billable_units=1)
|
||||||
|
create_letter_rate(start_date=JAN_2017_MONTH_START, crown=False)
|
||||||
|
|
||||||
create_or_update_monthly_billing(service_id=sample_template.service_id, billing_month=JAN_2017_MONTH_START)
|
create_or_update_monthly_billing(service_id=sample_template.service_id, billing_month=JAN_2017_MONTH_START)
|
||||||
|
|
||||||
monthly_billing = MonthlyBilling.query.order_by(MonthlyBilling.notification_type).all()
|
monthly_billing = MonthlyBilling.query.order_by(MonthlyBilling.notification_type).all()
|
||||||
@@ -271,7 +278,13 @@ def test_add_monthly_billing_with_multiple_rates_populate_correctly(
|
|||||||
_assert_monthly_billing(
|
_assert_monthly_billing(
|
||||||
monthly_billing[0], sample_template.service.id, 'email', JAN_2017_MONTH_START, JAN_2017_MONTH_END
|
monthly_billing[0], sample_template.service.id, 'email', JAN_2017_MONTH_START, JAN_2017_MONTH_END
|
||||||
)
|
)
|
||||||
assert monthly_billing[0].monthly_totals == []
|
_assert_monthly_billing_totals(monthly_billing[0].monthly_totals[0], {
|
||||||
|
"billing_units": 1,
|
||||||
|
"rate_multiplier": 1,
|
||||||
|
"international": False,
|
||||||
|
"rate": 0.0,
|
||||||
|
"total_cost": 0.0
|
||||||
|
})
|
||||||
|
|
||||||
_assert_monthly_billing(
|
_assert_monthly_billing(
|
||||||
monthly_billing[1], sample_template.service.id, 'sms', JAN_2017_MONTH_START, JAN_2017_MONTH_END
|
monthly_billing[1], sample_template.service.id, 'sms', JAN_2017_MONTH_START, JAN_2017_MONTH_END
|
||||||
@@ -294,7 +307,13 @@ def test_add_monthly_billing_with_multiple_rates_populate_correctly(
|
|||||||
_assert_monthly_billing(
|
_assert_monthly_billing(
|
||||||
monthly_billing[2], sample_template.service.id, 'letter', JAN_2017_MONTH_START, JAN_2017_MONTH_END
|
monthly_billing[2], sample_template.service.id, 'letter', JAN_2017_MONTH_START, JAN_2017_MONTH_END
|
||||||
)
|
)
|
||||||
assert monthly_billing[0].monthly_totals == []
|
_assert_monthly_billing_totals(monthly_billing[2].monthly_totals[0], {
|
||||||
|
"billing_units": 1,
|
||||||
|
"rate_multiplier": 1,
|
||||||
|
"international": False,
|
||||||
|
"rate": 0.31,
|
||||||
|
"total_cost": 0.31
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def test_update_monthly_billing_overwrites_old_totals(sample_template):
|
def test_update_monthly_billing_overwrites_old_totals(sample_template):
|
||||||
|
|||||||
@@ -232,5 +232,5 @@ def test_billing_letter_data_per_month_query(
|
|||||||
end_date=datetime(2017, 2, 28))
|
end_date=datetime(2017, 2, 28))
|
||||||
|
|
||||||
assert len(results) == 1
|
assert len(results) == 1
|
||||||
print(results[0].rate)
|
|
||||||
assert results[0].rate == 0.31
|
assert results[0].rate == 0.31
|
||||||
|
assert results[0].billing_units == 3
|
||||||
|
|||||||
Reference in New Issue
Block a user