mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-29 22:58:21 -04:00
@@ -166,6 +166,7 @@ def test_create_nightly_billing_for_day_different_templates(
|
||||
multiplier = [0, 1]
|
||||
billable_units = [0, 1]
|
||||
rate = [0, Decimal(1.33)]
|
||||
|
||||
for i, record in enumerate(records):
|
||||
assert record.bst_date == datetime.date(yesterday)
|
||||
assert record.rate == rate[i]
|
||||
|
||||
@@ -70,6 +70,34 @@ def test_fetch_billing_data_for_today_includes_data_with_the_right_key_type(noti
|
||||
assert results[0].notifications_sent == 2
|
||||
|
||||
|
||||
@pytest.mark.parametrize("notification_type", ["email", "sms", "letter"])
|
||||
def test_fetch_billing_data_for_day_only_calls_query_for_permission_type(notify_db_session, notification_type):
|
||||
service = create_service(service_permissions=[notification_type])
|
||||
email_template = create_template(service=service, template_type="email")
|
||||
sms_template = create_template(service=service, template_type="sms")
|
||||
letter_template = create_template(service=service, template_type="letter")
|
||||
create_notification(template=email_template, status='delivered')
|
||||
create_notification(template=sms_template, status='delivered')
|
||||
create_notification(template=letter_template, status='delivered')
|
||||
today = convert_utc_to_bst(datetime.utcnow())
|
||||
results = fetch_billing_data_for_day(process_day=today.date(), check_permissions=True)
|
||||
assert len(results) == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize("notification_type", ["email", "sms", "letter"])
|
||||
def test_fetch_billing_data_for_day_only_calls_query_for_all_channels(notify_db_session, notification_type):
|
||||
service = create_service(service_permissions=[notification_type])
|
||||
email_template = create_template(service=service, template_type="email")
|
||||
sms_template = create_template(service=service, template_type="sms")
|
||||
letter_template = create_template(service=service, template_type="letter")
|
||||
create_notification(template=email_template, status='delivered')
|
||||
create_notification(template=sms_template, status='delivered')
|
||||
create_notification(template=letter_template, status='delivered')
|
||||
today = convert_utc_to_bst(datetime.utcnow())
|
||||
results = fetch_billing_data_for_day(process_day=today.date(), check_permissions=False)
|
||||
assert len(results) == 3
|
||||
|
||||
|
||||
@freeze_time('2018-04-02 01:20:00')
|
||||
def test_fetch_billing_data_for_today_includes_data_with_the_right_date(notify_db_session):
|
||||
process_day = datetime(2018, 4, 1, 13, 30, 0)
|
||||
@@ -170,7 +198,7 @@ def test_fetch_billing_data_for_day_is_grouped_by_notification_type(notify_db_se
|
||||
today = convert_utc_to_bst(datetime.utcnow())
|
||||
results = fetch_billing_data_for_day(today.date())
|
||||
assert len(results) == 3
|
||||
notification_types = [x[2] for x in results if x[2] in ['email', 'sms', 'letter']]
|
||||
notification_types = [x.notification_type for x in results]
|
||||
assert len(notification_types) == 3
|
||||
|
||||
|
||||
@@ -280,12 +308,13 @@ def test_fetch_billing_data_for_day_bills_correctly_for_status(notify_db_session
|
||||
today = convert_utc_to_bst(datetime.utcnow())
|
||||
results = fetch_billing_data_for_day(process_day=today.date(), service_id=service.id)
|
||||
|
||||
sms_results = [x for x in results if x[2] == 'sms']
|
||||
email_results = [x for x in results if x[2] == 'email']
|
||||
letter_results = [x for x in results if x[2] == 'letter']
|
||||
assert 8 == sms_results[0][7]
|
||||
assert 8 == email_results[0][7]
|
||||
assert 3 == letter_results[0][7]
|
||||
sms_results = [x for x in results if x.notification_type == 'sms']
|
||||
email_results = [x for x in results if x.notification_type == 'email']
|
||||
letter_results = [x for x in results if x.notification_type == 'letter']
|
||||
# we expect as many rows as we check for notification types
|
||||
assert 6 == sms_results[0].notifications_sent
|
||||
assert 4 == email_results[0].notifications_sent
|
||||
assert 3 == letter_results[0].notifications_sent
|
||||
|
||||
|
||||
def test_get_rates_for_billing(notify_db_session):
|
||||
|
||||
Reference in New Issue
Block a user