diff --git a/tests/app/billing/test_rest.py b/tests/app/billing/test_rest.py index 042754eb5..d05237a98 100644 --- a/tests/app/billing/test_rest.py +++ b/tests/app/billing/test_rest.py @@ -273,145 +273,3 @@ def test_get_yearly_billing_usage_summary_from_ft_billing(admin_request, notify_ assert json_response[2]['billing_units'] == 825 assert json_response[2]['rate'] == 0.0162 assert json_response[2]['letter_total'] == 0 - - -def test_get_yearly_usage_by_monthly_from_ft_billing_all_cases(admin_request, notify_db_session): - service = set_up_data_for_all_cases() - - json_response = admin_request.get( - 'billing.get_yearly_usage_by_monthly_from_ft_billing', - service_id=service.id, - year=2018 - ) - - assert len(json_response) == 5 - assert json_response[0]['month'] == 'May' - assert json_response[0]['notification_type'] == 'letter' - assert json_response[0]['rate'] == 0.33 - assert json_response[0]['billing_units'] == 1 - assert json_response[0]['postage'] == 'second' - - assert json_response[1]['month'] == 'May' - assert json_response[1]['notification_type'] == 'letter' - assert json_response[1]['rate'] == 0.36 - assert json_response[1]['billing_units'] == 1 - assert json_response[1]['postage'] == 'second' - - assert json_response[2]['month'] == 'May' - assert json_response[2]['notification_type'] == 'letter' - assert json_response[2]['rate'] == 0.39 - assert json_response[2]['billing_units'] == 1 - assert json_response[2]['postage'] == 'first' - - assert json_response[3]['month'] == 'May' - assert json_response[3]['notification_type'] == 'sms' - assert json_response[3]['rate'] == 0.0150 - assert json_response[3]['billing_units'] == 4 - assert json_response[3]['postage'] == 'none' - - assert json_response[4]['month'] == 'May' - assert json_response[4]['notification_type'] == 'sms' - assert json_response[4]['rate'] == 0.162 - assert json_response[4]['billing_units'] == 5 - assert json_response[4]['postage'] == 'none' - - -def test_get_yearly_billing_usage_summary_from_ft_billing_all_cases(admin_request, notify_db_session): - service = set_up_data_for_all_cases() - - json_response = admin_request.get( - 'billing.get_yearly_billing_usage_summary_from_ft_billing', - service_id=service.id, - year=2018 - ) - - assert len(json_response) == 6 - assert json_response[0]["notification_type"] == 'email' - assert json_response[0]["billing_units"] == 1 - assert json_response[0]["rate"] == 0 - assert json_response[0]["letter_total"] == 0 - - assert json_response[1]["notification_type"] == 'letter' - assert json_response[1]["billing_units"] == 1 - assert json_response[1]["rate"] == 0.33 - assert json_response[1]["letter_total"] == 0.33 - - assert json_response[2]["notification_type"] == 'letter' - assert json_response[2]["billing_units"] == 1 - assert json_response[2]["rate"] == 0.36 - assert json_response[2]["letter_total"] == 0.36 - - assert json_response[3]["notification_type"] == 'letter' - assert json_response[3]["billing_units"] == 1 - assert json_response[3]["rate"] == 0.39 - assert json_response[3]["letter_total"] == 0.39 - - assert json_response[4]["notification_type"] == 'sms' - assert json_response[4]["billing_units"] == 4 - assert json_response[4]["rate"] == 0.0150 - assert json_response[4]["letter_total"] == 0 - - assert json_response[5]["notification_type"] == 'sms' - assert json_response[5]["billing_units"] == 5 - assert json_response[5]["rate"] == 0.162 - assert json_response[5]["letter_total"] == 0 - - -def set_up_data_for_all_cases(): - service = create_service() - sms_template = create_template(service=service, template_type="sms") - email_template = create_template(service=service, template_type="email") - letter_template = create_template(service=service, template_type="letter") - create_ft_billing(bst_date='2018-05-16', - template=sms_template, - rate_multiplier=1, - international=False, - rate=0.162, - billable_unit=1, - notifications_sent=1) - create_ft_billing(bst_date='2018-05-17', - template=sms_template, - rate_multiplier=2, - international=False, - rate=0.162, - billable_unit=2, - notifications_sent=1) - create_ft_billing(bst_date='2018-05-16', - template=sms_template, - rate_multiplier=2, - international=False, - rate=0.0150, - billable_unit=2, - notifications_sent=1) - create_ft_billing(bst_date='2018-05-16', - template=email_template, - rate_multiplier=1, - international=False, - rate=0, - billable_unit=0, - notifications_sent=1) - create_ft_billing(bst_date='2018-05-16', - template=letter_template, - rate_multiplier=1, - international=False, - rate=0.33, - billable_unit=1, - notifications_sent=1, - postage='second') - create_ft_billing(bst_date='2018-05-17', - template=letter_template, - rate_multiplier=1, - international=False, - rate=0.36, - billable_unit=2, - notifications_sent=1, - postage='second') - create_ft_billing(bst_date='2018-05-18', - template=letter_template, - rate_multiplier=1, - international=False, - rate=0.39, - billable_unit=3, - notifications_sent=1, - postage='first') - return service diff --git a/tests/app/dao/test_ft_billing_dao.py b/tests/app/dao/test_ft_billing_dao.py index ae40c377c..32d9460bb 100644 --- a/tests/app/dao/test_ft_billing_dao.py +++ b/tests/app/dao/test_ft_billing_dao.py @@ -58,6 +58,19 @@ def set_up_yearly_data(): return service +def set_up_yearly_data_variable_rates(): + service = create_service() + sms_template = create_template(service=service, template_type="sms") + letter_template = create_template(service=service, template_type="letter") + + create_ft_billing(bst_date='2018-05-16', template=sms_template, rate=0.162) + create_ft_billing(bst_date='2018-05-17', template=sms_template, rate_multiplier=2, rate=0.162, billable_unit=2) + create_ft_billing(bst_date='2018-05-16', template=sms_template, rate_multiplier=2, rate=0.0150, billable_unit=2) + create_ft_billing(bst_date='2018-05-16', template=letter_template, rate=0.33, postage='second') + create_ft_billing(bst_date='2018-05-17', template=letter_template, rate=0.36, billable_unit=2, postage='second') + return service + + def test_fetch_billing_data_for_today_includes_data_with_the_right_key_type(notify_db_session): service = create_service() template = create_template(service=service, template_type="email") @@ -427,6 +440,38 @@ def test_fetch_monthly_billing_for_year(notify_db_session): assert str(results[47].month) == "2017-03-01" +def test_fetch_monthly_billing_for_year_variable_rates(notify_db_session): + service = set_up_yearly_data_variable_rates() + results = fetch_monthly_billing_for_year(service.id, 2018) + + # Test data is only for the month of May + assert len(results) == 4 + + assert str(results[0].month) == "2018-05-01" + assert results[0].notification_type == 'letter' + assert results[0].notifications_sent == 1 + assert results[0].billable_units == 1 + assert results[0].rate == Decimal('0.33') + + assert str(results[1].month) == "2018-05-01" + assert results[1].notification_type == 'letter' + assert results[1].notifications_sent == 1 + assert results[1].billable_units == 1 + assert results[1].rate == Decimal('0.36') + + assert str(results[2].month) == "2018-05-01" + assert results[2].notification_type == 'sms' + assert results[2].notifications_sent == 1 + assert results[2].billable_units == 4 + assert results[2].rate == Decimal('0.015') + + assert str(results[3].month) == "2018-05-01" + assert results[3].notification_type == 'sms' + assert results[3].notifications_sent == 2 + assert results[3].billable_units == 5 + assert results[3].rate == Decimal('0.162') + + @freeze_time('2018-08-01 13:30:00') def test_fetch_monthly_billing_for_year_adds_data_for_today(notify_db_session): service = create_service() @@ -468,6 +513,32 @@ def test_fetch_billing_totals_for_year(notify_db_session): assert results[3].rate == Decimal('0.162') +def test_fetch_billing_totals_for_year_variable_rates(notify_db_session): + service = set_up_yearly_data_variable_rates() + results = fetch_billing_totals_for_year(service_id=service.id, year=2018) + + assert len(results) == 4 + assert results[0].notification_type == 'letter' + assert results[0].notifications_sent == 1 + assert results[0].billable_units == 1 + assert results[0].rate == Decimal('0.33') + + assert results[1].notification_type == 'letter' + assert results[1].notifications_sent == 1 + assert results[1].billable_units == 1 + assert results[1].rate == Decimal('0.36') + + assert results[2].notification_type == 'sms' + assert results[2].notifications_sent == 1 + assert results[2].billable_units == 4 + assert results[2].rate == Decimal('0.015') + + assert results[3].notification_type == 'sms' + assert results[3].notifications_sent == 2 + assert results[3].billable_units == 5 + assert results[3].rate == Decimal('0.162') + + def test_delete_billing_data(notify_db_session): service_1 = create_service(service_name='1') service_2 = create_service(service_name='2')