mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-05 14:10:47 -04:00
Update tests with new rates
This commit is contained in:
@@ -9,71 +9,71 @@ from tests.app.db import create_notification
|
||||
|
||||
|
||||
def test_get_rates_for_year(notify_db, notify_db_session):
|
||||
set_up_rate(notify_db, datetime(2016, 4, 1), 1.50)
|
||||
set_up_rate(notify_db, datetime(2016, 9, 1), 1.60)
|
||||
set_up_rate(notify_db, datetime(2017, 6, 1), 1.75)
|
||||
set_up_rate(notify_db, datetime(2016, 4, 1), 0.015)
|
||||
set_up_rate(notify_db, datetime(2016, 9, 1), 0.016)
|
||||
set_up_rate(notify_db, datetime(2017, 6, 1), 0.0175)
|
||||
rates = get_rates_for_year(datetime(2016, 3, 31), datetime(2017, 3, 31), 'sms')
|
||||
assert len(rates) == 2
|
||||
assert datetime.strftime(rates[0].valid_from, '%Y-%m-%d %H:%M:%S') == "2016-04-01 00:00:00"
|
||||
assert rates[0].rate == 1.50
|
||||
assert rates[0].rate == 0.015
|
||||
assert datetime.strftime(rates[1].valid_from, '%Y-%m-%d %H:%M:%S') == "2016-09-01 00:00:00"
|
||||
assert rates[1].rate == 1.6
|
||||
assert rates[1].rate == 0.016
|
||||
|
||||
|
||||
def test_get_rates_for_year_returns_correct_rates(notify_db, notify_db_session):
|
||||
set_up_rate(notify_db, datetime(2016, 4, 1), 1.50)
|
||||
set_up_rate(notify_db, datetime(2016, 9, 1), 1.60)
|
||||
set_up_rate(notify_db, datetime(2017, 6, 1), 1.75)
|
||||
set_up_rate(notify_db, datetime(2016, 4, 1), 0.015)
|
||||
set_up_rate(notify_db, datetime(2016, 9, 1), 0.016)
|
||||
set_up_rate(notify_db, datetime(2017, 6, 1), 0.0175)
|
||||
start_date, end_date = get_financial_year(2017)
|
||||
rates_2017 = get_rates_for_year(start_date, end_date, 'sms')
|
||||
assert len(rates_2017) == 2
|
||||
assert datetime.strftime(rates_2017[0].valid_from, '%Y-%m-%d %H:%M:%S') == "2016-09-01 00:00:00"
|
||||
assert rates_2017[0].rate == 1.60
|
||||
assert rates_2017[0].rate == 0.016
|
||||
assert datetime.strftime(rates_2017[1].valid_from, '%Y-%m-%d %H:%M:%S') == "2017-06-01 00:00:00"
|
||||
assert rates_2017[1].rate == 1.75
|
||||
assert rates_2017[1].rate == 0.0175
|
||||
|
||||
|
||||
def test_get_rates_for_year_in_the_future(notify_db, notify_db_session):
|
||||
set_up_rate(notify_db, datetime(2016, 4, 1), 1.50)
|
||||
set_up_rate(notify_db, datetime(2017, 6, 1), 1.75)
|
||||
set_up_rate(notify_db, datetime(2016, 4, 1), 0.015)
|
||||
set_up_rate(notify_db, datetime(2017, 6, 1), 0.0175)
|
||||
start_date, end_date = get_financial_year(2018)
|
||||
rates = get_rates_for_year(start_date, end_date, 'sms')
|
||||
assert datetime.strftime(rates[0].valid_from, '%Y-%m-%d %H:%M:%S') == "2017-06-01 00:00:00"
|
||||
assert rates[0].rate == 1.75
|
||||
assert rates[0].rate == 0.0175
|
||||
|
||||
|
||||
def test_get_rates_for_year_returns_empty_list_if_year_is_before_earliest_rate(notify_db, notify_db_session):
|
||||
set_up_rate(notify_db, datetime(2016, 4, 1), 1.50)
|
||||
set_up_rate(notify_db, datetime(2017, 6, 1), 1.75)
|
||||
set_up_rate(notify_db, datetime(2016, 4, 1), 0.015)
|
||||
set_up_rate(notify_db, datetime(2017, 6, 1), 0.0175)
|
||||
start_date, end_date = get_financial_year(2015)
|
||||
rates = get_rates_for_year(start_date, end_date, 'sms')
|
||||
assert rates == []
|
||||
|
||||
|
||||
def test_get_rates_for_year_early_rate(notify_db, notify_db_session):
|
||||
set_up_rate(notify_db, datetime(2015, 6, 1), 1.40)
|
||||
set_up_rate(notify_db, datetime(2016, 6, 1), 1.50)
|
||||
set_up_rate(notify_db, datetime(2016, 9, 1), 1.60)
|
||||
set_up_rate(notify_db, datetime(2017, 6, 1), 1.75)
|
||||
set_up_rate(notify_db, datetime(2015, 6, 1), 0.014)
|
||||
set_up_rate(notify_db, datetime(2016, 6, 1), 0.015)
|
||||
set_up_rate(notify_db, datetime(2016, 9, 1), 0.016)
|
||||
set_up_rate(notify_db, datetime(2017, 6, 1), 0.0175)
|
||||
start_date, end_date = get_financial_year(2016)
|
||||
rates = get_rates_for_year(start_date, end_date, 'sms')
|
||||
assert len(rates) == 3
|
||||
|
||||
|
||||
def test_get_rates_for_year_edge_case(notify_db, notify_db_session):
|
||||
set_up_rate(notify_db, datetime(2016, 3, 31, 23, 00), 1.50)
|
||||
set_up_rate(notify_db, datetime(2017, 3, 31, 23, 00), 1.75)
|
||||
set_up_rate(notify_db, datetime(2016, 3, 31, 23, 00), 0.015)
|
||||
set_up_rate(notify_db, datetime(2017, 3, 31, 23, 00), 0.0175)
|
||||
start_date, end_date = get_financial_year(2016)
|
||||
rates = get_rates_for_year(start_date, end_date, 'sms')
|
||||
assert len(rates) == 1
|
||||
assert datetime.strftime(rates[0].valid_from, '%Y-%m-%d %H:%M:%S') == "2016-03-31 23:00:00"
|
||||
assert rates[0].rate == 1.50
|
||||
assert rates[0].rate == 0.015
|
||||
|
||||
|
||||
def test_get_yearly_billing_data(notify_db, notify_db_session, sample_template, sample_email_template):
|
||||
set_up_rate(notify_db, datetime(2016, 4, 1), 1.40)
|
||||
set_up_rate(notify_db, datetime(2016, 6, 1), 1.58)
|
||||
set_up_rate(notify_db, datetime(2017, 6, 1), 1.65)
|
||||
set_up_rate(notify_db, datetime(2016, 4, 1), 0.014)
|
||||
set_up_rate(notify_db, datetime(2016, 6, 1), 0.0158)
|
||||
set_up_rate(notify_db, datetime(2017, 6, 1), 0.0165)
|
||||
# previous year
|
||||
create_notification(template=sample_template, created_at=datetime(2016, 3, 31), sent_at=datetime(2016, 3, 31),
|
||||
status='sending', billable_units=1)
|
||||
@@ -97,14 +97,14 @@ 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) == 4
|
||||
assert results[0] == (3, 3, 1, 'sms', False, 1.4)
|
||||
assert results[1] == (9, 9, 1, 'sms', False, 1.58)
|
||||
assert results[2] == (6, 3, 2, 'sms', True, 1.58)
|
||||
assert results[0] == (3, 3, 1, 'sms', False, 0.014)
|
||||
assert results[1] == (9, 9, 1, 'sms', False, 0.0158)
|
||||
assert results[2] == (6, 3, 2, 'sms', True, 0.0158)
|
||||
assert results[3] == (2, 2, 1, 'email', False, 0)
|
||||
|
||||
|
||||
def test_get_future_yearly_billing_data(notify_db, notify_db_session, sample_template, sample_email_template):
|
||||
set_up_rate(notify_db, datetime(2017, 4, 1), 1.58)
|
||||
set_up_rate(notify_db, datetime(2017, 4, 1), 0.0158)
|
||||
|
||||
create_notification(template=sample_template, created_at=datetime(2017, 3, 30), sent_at=datetime(2017, 3, 30),
|
||||
status='sending', billable_units=1)
|
||||
@@ -115,11 +115,11 @@ def test_get_future_yearly_billing_data(notify_db, notify_db_session, sample_tem
|
||||
|
||||
results = get_yearly_billing_data(sample_template.service_id, 2018)
|
||||
assert len(results) == 2
|
||||
assert results[0] == (0, 0, 1, 'sms', False, 1.58)
|
||||
assert results[0] == (0, 0, 1, 'sms', False, 0.0158)
|
||||
|
||||
|
||||
def test_get_yearly_billing_data_with_one_rate(notify_db, notify_db_session, sample_template):
|
||||
set_up_rate(notify_db, datetime(2016, 4, 1), 1.40)
|
||||
set_up_rate(notify_db, datetime(2016, 4, 1), 0.014)
|
||||
# previous year
|
||||
create_notification(template=sample_template, created_at=datetime(2016, 3, 31), sent_at=datetime(2016, 3, 31),
|
||||
status='sending', billable_units=1)
|
||||
@@ -141,12 +141,12 @@ 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, 15, 1, 'sms', False, 1.4)
|
||||
assert results[0] == (15, 15, 1, 'sms', False, 0.014)
|
||||
assert results[1] == (0, 0, 1, 'email', False, 0)
|
||||
|
||||
|
||||
def test_get_yearly_billing_data_with_no_sms_notifications(notify_db, notify_db_session, sample_email_template):
|
||||
set_up_rate(notify_db, datetime(2016, 4, 1), 1.40)
|
||||
set_up_rate(notify_db, datetime(2016, 4, 1), 0.014)
|
||||
create_notification(template=sample_email_template, created_at=datetime(2016, 7, 31), sent_at=datetime(2016, 3, 31),
|
||||
status='sending', billable_units=0)
|
||||
create_notification(template=sample_email_template, created_at=datetime(2016, 10, 2), sent_at=datetime(2016, 4, 2),
|
||||
@@ -154,12 +154,12 @@ 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, 0, 1, 'sms', False, 1.4)
|
||||
assert results[0] == (0, 0, 1, 'sms', False, 0.014)
|
||||
assert results[1] == (2, 2, 1, 'email', False, 0)
|
||||
|
||||
|
||||
def test_get_monthly_billing_data(notify_db, notify_db_session, sample_template, sample_email_template):
|
||||
set_up_rate(notify_db, datetime(2016, 4, 1), 1.40)
|
||||
set_up_rate(notify_db, datetime(2016, 4, 1), 0.014)
|
||||
# previous year
|
||||
create_notification(template=sample_template, created_at=datetime(2016, 3, 31), sent_at=datetime(2016, 3, 31),
|
||||
status='sending', billable_units=1)
|
||||
@@ -187,17 +187,17 @@ def test_get_monthly_billing_data(notify_db, notify_db_session, sample_template,
|
||||
results = get_monthly_billing_data(sample_template.service_id, 2016)
|
||||
assert len(results) == 4
|
||||
# (billable_units, rate_multiplier, international, type, rate)
|
||||
assert results[0] == ('April', 1, 1, False, 'sms', 1.4)
|
||||
assert results[1] == ('May', 2, 1, False, 'sms', 1.4)
|
||||
assert results[2] == ('July', 7, 1, False, 'sms', 1.4)
|
||||
assert results[3] == ('July', 6, 2, False, 'sms', 1.4)
|
||||
assert results[0] == ('April', 1, 1, False, 'sms', 0.014)
|
||||
assert results[1] == ('May', 2, 1, False, 'sms', 0.014)
|
||||
assert results[2] == ('July', 7, 1, False, 'sms', 0.014)
|
||||
assert results[3] == ('July', 6, 2, False, 'sms', 0.014)
|
||||
|
||||
|
||||
def test_get_monthly_billing_data_with_multiple_rates(notify_db, notify_db_session, sample_template,
|
||||
sample_email_template):
|
||||
set_up_rate(notify_db, datetime(2016, 4, 1), 1.40)
|
||||
set_up_rate(notify_db, datetime(2016, 6, 5), 1.75)
|
||||
set_up_rate(notify_db, datetime(2017, 7, 5), 1.80)
|
||||
set_up_rate(notify_db, datetime(2016, 4, 1), 0.014)
|
||||
set_up_rate(notify_db, datetime(2016, 6, 5), 0.0175)
|
||||
set_up_rate(notify_db, datetime(2017, 7, 5), 0.018)
|
||||
# previous year
|
||||
create_notification(template=sample_template, created_at=datetime(2016, 3, 31), sent_at=datetime(2016, 3, 31),
|
||||
status='sending', billable_units=1)
|
||||
@@ -221,15 +221,15 @@ def test_get_monthly_billing_data_with_multiple_rates(notify_db, notify_db_sessi
|
||||
sent_at=datetime(2017, 3, 31), status='sending', billable_units=6)
|
||||
results = get_monthly_billing_data(sample_template.service_id, 2016)
|
||||
assert len(results) == 4
|
||||
assert results[0] == ('April', 1, 1, False, 'sms', 1.4)
|
||||
assert results[1] == ('May', 2, 1, False, 'sms', 1.4)
|
||||
assert results[2] == ('June', 3, 1, False, 'sms', 1.4)
|
||||
assert results[3] == ('June', 4, 1, False, 'sms', 1.75)
|
||||
assert results[0] == ('April', 1, 1, False, 'sms', 0.014)
|
||||
assert results[1] == ('May', 2, 1, False, 'sms', 0.014)
|
||||
assert results[2] == ('June', 3, 1, False, 'sms', 0.014)
|
||||
assert results[3] == ('June', 4, 1, False, 'sms', 0.0175)
|
||||
|
||||
|
||||
def test_get_monthly_billing_data_with_no_notifications_for_year(notify_db, notify_db_session, sample_template,
|
||||
sample_email_template):
|
||||
set_up_rate(notify_db, datetime(2016, 4, 1), 1.40)
|
||||
set_up_rate(notify_db, datetime(2016, 4, 1), 0.014)
|
||||
results = get_monthly_billing_data(sample_template.service_id, 2016)
|
||||
assert len(results) == 0
|
||||
|
||||
|
||||
@@ -1513,7 +1513,7 @@ def test_get_template_stats_by_month_returns_error_for_incorrect_year(
|
||||
|
||||
|
||||
def test_get_yearly_billing_usage(client, notify_db, notify_db_session):
|
||||
rate = Rate(id=uuid.uuid4(), valid_from=datetime(2016, 3, 31, 23, 00), rate=1.58, notification_type='sms')
|
||||
rate = Rate(id=uuid.uuid4(), valid_from=datetime(2016, 3, 31, 23, 00), rate=0.0158, notification_type='sms')
|
||||
notify_db.session.add(rate)
|
||||
notification = create_sample_notification(notify_db, notify_db_session, created_at=datetime(2016, 6, 5),
|
||||
sent_at=datetime(2016, 6, 5),
|
||||
@@ -1529,7 +1529,7 @@ def test_get_yearly_billing_usage(client, notify_db, notify_db_session):
|
||||
'rate_multiplier': 1,
|
||||
'notification_type': 'sms',
|
||||
'international': False,
|
||||
'rate': 1.58},
|
||||
'rate': 0.0158},
|
||||
{'credits': 0,
|
||||
'billing_units': 0,
|
||||
'rate_multiplier': 1,
|
||||
@@ -1550,7 +1550,7 @@ def test_get_yearly_billing_usage_returns_400_if_missing_year(client, sample_ser
|
||||
|
||||
|
||||
def test_get_monthly_billing_usage(client, notify_db, notify_db_session, sample_service):
|
||||
rate = Rate(id=uuid.uuid4(), valid_from=datetime(2016, 3, 31, 23, 00), rate=1.58, notification_type='sms')
|
||||
rate = Rate(id=uuid.uuid4(), valid_from=datetime(2016, 3, 31, 23, 00), rate=0.0158, notification_type='sms')
|
||||
notify_db.session.add(rate)
|
||||
notification = create_sample_notification(notify_db, notify_db_session, created_at=datetime(2016, 6, 5),
|
||||
sent_at=datetime(2016, 6, 5),
|
||||
@@ -1578,19 +1578,19 @@ def test_get_monthly_billing_usage(client, notify_db, notify_db_session, sample_
|
||||
'international': False,
|
||||
'rate_multiplier': 1,
|
||||
'notification_type': 'sms',
|
||||
'rate': 1.58,
|
||||
'rate': 0.0158,
|
||||
'billing_units': 1},
|
||||
{'month': 'June',
|
||||
'international': False,
|
||||
'rate_multiplier': 2,
|
||||
'notification_type': 'sms',
|
||||
'rate': 1.58,
|
||||
'rate': 0.0158,
|
||||
'billing_units': 1},
|
||||
{'month': 'July',
|
||||
'international': False,
|
||||
'rate_multiplier': 1,
|
||||
'notification_type': 'sms',
|
||||
'rate': 1.58,
|
||||
'rate': 0.0158,
|
||||
'billing_units': 1}]
|
||||
|
||||
|
||||
@@ -1606,7 +1606,7 @@ def test_get_monthly_billing_usage_returns_400_if_missing_year(client, sample_se
|
||||
|
||||
|
||||
def test_get_monthly_billing_usage_returns_empty_list_if_no_notifications(client, notify_db, sample_service):
|
||||
rate = Rate(id=uuid.uuid4(), valid_from=datetime(2016, 3, 31, 23, 00), rate=1.58, notification_type='sms')
|
||||
rate = Rate(id=uuid.uuid4(), valid_from=datetime(2016, 3, 31, 23, 00), rate=0.0158, notification_type='sms')
|
||||
notify_db.session.add(rate)
|
||||
response = client.get(
|
||||
'/service/{}/monthly-usage?year=2016'.format(sample_service.id),
|
||||
|
||||
Reference in New Issue
Block a user