This commit is contained in:
Imdad Ahad
2017-08-01 14:04:17 +01:00
parent d01d875f7e
commit dc7a1051a6

View File

@@ -14,13 +14,11 @@ from tests.app.db import create_notification, create_rate, create_service, creat
def create_sample_monthly_billing_entry( def create_sample_monthly_billing_entry(
notify_db,
notify_db_session,
service_id, service_id,
notification_type,
monthly_totals, monthly_totals,
start_date, start_date,
end_date end_date,
notification_type=SMS_TYPE
): ):
entry = MonthlyBilling( entry = MonthlyBilling(
service_id=service_id, service_id=service_id,
@@ -38,8 +36,8 @@ def create_sample_monthly_billing_entry(
def test_add_monthly_billing(sample_template): def test_add_monthly_billing(sample_template):
jan = datetime(2017, 1, 1) jan = datetime(2017, 1, 1)
feb = datetime(2017, 2, 15) feb = datetime(2017, 2, 15)
create_rate(start_date=jan, value=0.0158, notification_type='sms') create_rate(start_date=jan, value=0.0158, notification_type=SMS_TYPE)
create_rate(start_date=datetime(2017, 3, 31, 23, 00, 00), value=0.123, notification_type='sms') create_rate(start_date=datetime(2017, 3, 31, 23, 00, 00), value=0.123, notification_type=SMS_TYPE)
create_notification(template=sample_template, created_at=jan, billable_units=1, status='delivered') create_notification(template=sample_template, created_at=jan, billable_units=1, status='delivered')
create_notification(template=sample_template, created_at=feb, billable_units=2, status='delivered') create_notification(template=sample_template, created_at=feb, billable_units=2, status='delivered')
@@ -74,8 +72,8 @@ def test_add_monthly_billing(sample_template):
def test_add_monthly_billing_multiple_rates_in_a_month(sample_template): def test_add_monthly_billing_multiple_rates_in_a_month(sample_template):
rate_1 = datetime(2016, 12, 1) rate_1 = datetime(2016, 12, 1)
rate_2 = datetime(2017, 1, 15) rate_2 = datetime(2017, 1, 15)
create_rate(start_date=rate_1, value=0.0158, notification_type='sms') create_rate(start_date=rate_1, value=0.0158, notification_type=SMS_TYPE)
create_rate(start_date=rate_2, value=0.0124, notification_type='sms') create_rate(start_date=rate_2, value=0.0124, notification_type=SMS_TYPE)
create_notification(template=sample_template, created_at=datetime(2017, 1, 1), billable_units=1, status='delivered') create_notification(template=sample_template, created_at=datetime(2017, 1, 1), billable_units=1, status='delivered')
create_notification(template=sample_template, created_at=datetime(2017, 1, 14, 23, 59), billable_units=1, create_notification(template=sample_template, created_at=datetime(2017, 1, 14, 23, 59), billable_units=1,
@@ -110,7 +108,7 @@ def test_add_monthly_billing_multiple_rates_in_a_month(sample_template):
def test_update_monthly_billing_overwrites_old_totals(sample_template): def test_update_monthly_billing_overwrites_old_totals(sample_template):
july = datetime(2017, 7, 1) july = datetime(2017, 7, 1)
create_rate(july, 0.123, 'sms') create_rate(july, 0.123, SMS_TYPE)
create_notification(template=sample_template, created_at=datetime(2017, 7, 2), billable_units=1, status='delivered') create_notification(template=sample_template, created_at=datetime(2017, 7, 2), billable_units=1, status='delivered')
with freeze_time('2017-07-20 02:30:00'): with freeze_time('2017-07-20 02:30:00'):
create_or_update_monthly_billing_sms(sample_template.service_id, july) create_or_update_monthly_billing_sms(sample_template.service_id, july)
@@ -167,23 +165,17 @@ def test_get_monthly_billing_entry_filters_by_service(notify_db, notify_db_sessi
now = datetime.utcnow() now = datetime.utcnow()
create_sample_monthly_billing_entry( create_sample_monthly_billing_entry(
notify_db, service_id=service_1.id,
notify_db_session, monthly_totals=[],
service_1.id, start_date=now,
'sms', end_date=now + timedelta(days=30)
[],
now,
now + timedelta(days=30)
) )
create_sample_monthly_billing_entry( create_sample_monthly_billing_entry(
notify_db, service_id=service_2.id,
notify_db_session, monthly_totals=[],
service_2.id, start_date=now,
'sms', end_date=now + timedelta(days=30)
[],
now,
now + timedelta(days=30)
) )
entry = get_monthly_billing_entry(service_2.id, now, SMS_TYPE) entry = get_monthly_billing_entry(service_2.id, now, SMS_TYPE)