mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
Add new fields to the usage queries: rate_multiplier, international, phone_prefix.
This commit is contained in:
@@ -47,14 +47,20 @@ def email_billing_data_query(service_id, start_date, end_date):
|
||||
result = db.session.query(
|
||||
func.count(NotificationHistory.id),
|
||||
NotificationHistory.notification_type,
|
||||
"0"
|
||||
"0",
|
||||
NotificationHistory.rate_multiplier,
|
||||
NotificationHistory.international,
|
||||
NotificationHistory.phone_prefix
|
||||
).filter(
|
||||
*billing_data_filter(EMAIL_TYPE, start_date, end_date, service_id)
|
||||
).group_by(
|
||||
NotificationHistory.notification_type
|
||||
NotificationHistory.notification_type,
|
||||
NotificationHistory.rate_multiplier,
|
||||
NotificationHistory.international,
|
||||
NotificationHistory.phone_prefix
|
||||
).first()
|
||||
if not result:
|
||||
return 0, EMAIL_TYPE, Decimal("0")
|
||||
return 0, EMAIL_TYPE, Decimal("0"), None, False, None
|
||||
else:
|
||||
return result
|
||||
|
||||
@@ -63,14 +69,20 @@ def sms_billing_data_query(rate, service_id, start_date, end_date):
|
||||
result = db.session.query(
|
||||
func.sum(NotificationHistory.billable_units),
|
||||
NotificationHistory.notification_type,
|
||||
rate
|
||||
rate,
|
||||
NotificationHistory.rate_multiplier,
|
||||
NotificationHistory.international,
|
||||
NotificationHistory.phone_prefix
|
||||
).filter(
|
||||
*billing_data_filter(SMS_TYPE, start_date, end_date, service_id)
|
||||
).group_by(
|
||||
NotificationHistory.notification_type
|
||||
NotificationHistory.notification_type,
|
||||
NotificationHistory.rate_multiplier,
|
||||
NotificationHistory.international,
|
||||
NotificationHistory.phone_prefix
|
||||
).first()
|
||||
if not result:
|
||||
return 0, SMS_TYPE, Decimal("0")
|
||||
return 0, SMS_TYPE, Decimal("0"), None, False, None
|
||||
else:
|
||||
return result
|
||||
|
||||
@@ -86,11 +98,17 @@ def sms_billing_data_per_month_query(rate, service_id, start_date, end_date):
|
||||
month,
|
||||
func.sum(NotificationHistory.billable_units),
|
||||
NotificationHistory.notification_type,
|
||||
rate
|
||||
rate,
|
||||
NotificationHistory.rate_multiplier,
|
||||
NotificationHistory.international,
|
||||
NotificationHistory.phone_prefix
|
||||
).filter(
|
||||
*billing_data_filter(SMS_TYPE, start_date, end_date, service_id)
|
||||
).group_by(
|
||||
NotificationHistory.notification_type, month
|
||||
NotificationHistory.notification_type, month,
|
||||
NotificationHistory.rate_multiplier,
|
||||
NotificationHistory.international,
|
||||
NotificationHistory.phone_prefix
|
||||
).order_by(
|
||||
month
|
||||
).all()
|
||||
@@ -102,11 +120,17 @@ def email_billing_data_per_month_query(rate, service_id, start_date, end_date):
|
||||
month,
|
||||
func.count(NotificationHistory.id),
|
||||
NotificationHistory.notification_type,
|
||||
rate
|
||||
rate,
|
||||
NotificationHistory.rate_multiplier,
|
||||
NotificationHistory.international,
|
||||
NotificationHistory.phone_prefix
|
||||
).filter(
|
||||
*billing_data_filter(EMAIL_TYPE, start_date, end_date, service_id)
|
||||
).group_by(
|
||||
NotificationHistory.notification_type, month
|
||||
NotificationHistory.notification_type, month,
|
||||
NotificationHistory.rate_multiplier,
|
||||
NotificationHistory.international,
|
||||
NotificationHistory.phone_prefix
|
||||
).order_by(
|
||||
month
|
||||
).all()
|
||||
@@ -124,4 +148,4 @@ def get_notification_billing_data_per_month(service_id, year):
|
||||
|
||||
result.extend(email_billing_data_per_month_query("0", service_id, start_date, end_date))
|
||||
|
||||
return [(datetime.strftime(x[0], "%B"), x[1:]) for x in result]
|
||||
return [(datetime.strftime(x[0], "%B"), x[1], x[2], x[3], x[4], x[5], x[6]) for x in result]
|
||||
|
||||
@@ -48,9 +48,9 @@ def test_get_yearly_billing_data(notify_db, notify_db_session, sample_template,
|
||||
status='sending', billable_units=6)
|
||||
results = get_yearly_billing_data(sample_template.service_id, 2016)
|
||||
assert len(results) == 3
|
||||
assert results[0] == (3, 'sms', Decimal('1.4'))
|
||||
assert results[1] == (12, 'sms', Decimal('1.58'))
|
||||
assert results[2] == (2, 'email', Decimal("0"))
|
||||
assert results[0] == (3, 'sms', Decimal('1.4'), None, False, None)
|
||||
assert results[1] == (12, 'sms', Decimal('1.58'), None, False, None)
|
||||
assert results[2] == (2, 'email', Decimal("0"), None, False, None)
|
||||
|
||||
|
||||
def test_get_yearly_billing_data_with_one_rate(notify_db, notify_db_session, sample_template):
|
||||
@@ -76,8 +76,8 @@ def test_get_yearly_billing_data_with_one_rate(notify_db, notify_db_session, sam
|
||||
status='sending', billable_units=7)
|
||||
results = get_yearly_billing_data(sample_template.service_id, 2016)
|
||||
assert len(results) == 2
|
||||
assert results[0] == (15, 'sms', Decimal('1.4'))
|
||||
assert results[1] == (0, 'email', Decimal('0'))
|
||||
assert results[0] == (15, 'sms', Decimal('1.4'), None, False, None)
|
||||
assert results[1] == (0, 'email', Decimal('0'), None, False, None)
|
||||
|
||||
|
||||
def test_get_yearly_billing_data_with_no_sms_notifications(notify_db, notify_db_session, sample_email_template):
|
||||
@@ -89,8 +89,8 @@ def test_get_yearly_billing_data_with_no_sms_notifications(notify_db, notify_db_
|
||||
|
||||
results = get_yearly_billing_data(sample_email_template.service_id, 2016)
|
||||
assert len(results) == 2
|
||||
assert results[0] == (0, 'sms', Decimal('0'))
|
||||
assert results[1] == (2, 'email', Decimal('0'))
|
||||
assert results[0] == (0, 'sms', Decimal('0'), None, False, None)
|
||||
assert results[1] == (2, 'email', Decimal('0'), None, False, None)
|
||||
|
||||
|
||||
def test_get_notification_billing_data_per_month(notify_db, notify_db_session, sample_template, sample_email_template):
|
||||
@@ -116,10 +116,10 @@ def test_get_notification_billing_data_per_month(notify_db, notify_db_session, s
|
||||
sent_at=datetime(2017, 3, 31), status='sending', billable_units=6)
|
||||
results = get_notification_billing_data_per_month(sample_template.service_id, 2016)
|
||||
assert len(results) == 4
|
||||
assert results[0] == ('April', (1, 'sms', Decimal('1.4')))
|
||||
assert results[1] == ('May', (2, 'sms', Decimal('1.4')))
|
||||
assert results[2] == ('July', (7, 'sms', Decimal('1.4')))
|
||||
assert results[3] == ('August', (2, 'email', Decimal('0')))
|
||||
assert results[0] == ('April', 1, 'sms', Decimal('1.4'), None, False, None)
|
||||
assert results[1] == ('May', 2, 'sms', Decimal('1.4'), None, False, None)
|
||||
assert results[2] == ('July', 7, 'sms', Decimal('1.4'), None, False, None)
|
||||
assert results[3] == ('August', 2, 'email', Decimal('0'), None, False, None)
|
||||
|
||||
|
||||
def test_get_notification_billing_data_per_month_with_multiple_rates(notify_db, notify_db_session, sample_template,
|
||||
@@ -149,11 +149,11 @@ def test_get_notification_billing_data_per_month_with_multiple_rates(notify_db,
|
||||
sent_at=datetime(2017, 3, 31), status='sending', billable_units=6)
|
||||
results = get_notification_billing_data_per_month(sample_template.service_id, 2016)
|
||||
assert len(results) == 5
|
||||
assert results[0] == ('April', (1, 'sms', Decimal('1.4')))
|
||||
assert results[1] == ('May', (2, 'sms', Decimal('1.4')))
|
||||
assert results[2] == ('June', (3, 'sms', Decimal('1.4')))
|
||||
assert results[3] == ('June', (4, 'sms', Decimal('1.75')))
|
||||
assert results[4] == ('August', (2, 'email', Decimal('0')))
|
||||
assert results[0] == ('April', 1, 'sms', Decimal('1.4'), None, False, None)
|
||||
assert results[1] == ('May', 2, 'sms', Decimal('1.4'), None, False, None)
|
||||
assert results[2] == ('June', 3, 'sms', Decimal('1.4'), None, False, None)
|
||||
assert results[3] == ('June', 4, 'sms', Decimal('1.75'), None, False, None)
|
||||
assert results[4] == ('August', 2, 'email', Decimal('0'), None, False, None)
|
||||
|
||||
|
||||
def set_up_rate(notify_db, start_date, value):
|
||||
|
||||
Reference in New Issue
Block a user