mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-16 20:48:37 -04:00
- Add update dao_update_annual_billing_for_current_and_future_years
- moved get_current_financial_year_start_year from service.utils to dao.date_utils - Moved logic for data persistence from rest to dao when updating records in db
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
from app.service.utils import get_current_financial_year_start_year
|
||||
from app.dao.date_util import get_current_financial_year_start_year
|
||||
from app.models import AnnualBilling
|
||||
from app.dao.annual_billing_dao import (
|
||||
dao_create_or_update_annual_billing_for_year,
|
||||
dao_get_free_sms_fragment_limit_for_year,
|
||||
dao_get_annual_billing
|
||||
dao_get_annual_billing,
|
||||
dao_update_annual_billing_for_current_and_future_years,
|
||||
)
|
||||
from tests.app.db import create_annual_billing
|
||||
|
||||
|
||||
def test_get_sample_service_has_default_free_sms_fragment_limit(notify_db_session, sample_service):
|
||||
@@ -18,40 +20,44 @@ def test_get_sample_service_has_default_free_sms_fragment_limit(notify_db_sessio
|
||||
|
||||
|
||||
def test_dao_update_free_sms_fragment_limit(notify_db_session, sample_service):
|
||||
year = 1999
|
||||
old_limit = 1000
|
||||
new_limit = 9999
|
||||
|
||||
data = AnnualBilling(
|
||||
free_sms_fragment_limit=old_limit,
|
||||
financial_year_start=year,
|
||||
service_id=sample_service.id,
|
||||
)
|
||||
|
||||
dao_create_or_update_annual_billing_for_year(data)
|
||||
data.free_sms_fragment_limit = new_limit
|
||||
dao_create_or_update_annual_billing_for_year(data)
|
||||
year = get_current_financial_year_start_year()
|
||||
dao_create_or_update_annual_billing_for_year(sample_service.id, new_limit, year)
|
||||
new_free_limit = dao_get_free_sms_fragment_limit_for_year(sample_service.id, year)
|
||||
|
||||
assert new_free_limit.free_sms_fragment_limit == new_limit
|
||||
|
||||
|
||||
def test_create_then_get_annual_billing(notify_db_session, sample_service):
|
||||
years = [1999, 2001]
|
||||
limits = [1000, 2000]
|
||||
def test_create_annual_billing_not_specify_year(notify_db_session, sample_service):
|
||||
|
||||
for i in [0, 1]:
|
||||
data = AnnualBilling(
|
||||
free_sms_fragment_limit=limits[i],
|
||||
financial_year_start=years[i],
|
||||
service_id=sample_service.id,
|
||||
)
|
||||
dao_create_or_update_annual_billing_for_year(data)
|
||||
dao_create_or_update_annual_billing_for_year(sample_service.id, 9999)
|
||||
|
||||
free_limit = dao_get_annual_billing(sample_service.id)
|
||||
assert len(free_limit) == 3 # sample service already has one entry
|
||||
assert free_limit[0].free_sms_fragment_limit == 1000
|
||||
assert free_limit[0].financial_year_start == 1999
|
||||
assert free_limit[0].service_id == sample_service.id
|
||||
assert free_limit[1].free_sms_fragment_limit == 2000
|
||||
assert free_limit[1].financial_year_start == 2001
|
||||
free_limit = dao_get_free_sms_fragment_limit_for_year(sample_service.id)
|
||||
|
||||
assert free_limit.free_sms_fragment_limit == 9999
|
||||
|
||||
|
||||
def test_create_annual_billing_specify_year(notify_db_session, sample_service):
|
||||
|
||||
dao_create_or_update_annual_billing_for_year(sample_service.id, 9999, 2016)
|
||||
|
||||
free_limit = dao_get_free_sms_fragment_limit_for_year(sample_service.id, 2016)
|
||||
|
||||
assert free_limit.free_sms_fragment_limit == 9999
|
||||
|
||||
|
||||
def test_dao_update_annual_billing_for_current_and_future_years(notify_db_session, sample_service):
|
||||
current_year = get_current_financial_year_start_year()
|
||||
limits = [240000, 250000, 260000, 270000]
|
||||
create_annual_billing(sample_service.id, limits[0], current_year - 1)
|
||||
create_annual_billing(sample_service.id, limits[2], current_year + 1)
|
||||
create_annual_billing(sample_service.id, limits[3], current_year + 2)
|
||||
|
||||
dao_update_annual_billing_for_current_and_future_years(sample_service.id, 9999, current_year)
|
||||
|
||||
free_limit = dao_get_free_sms_fragment_limit_for_year(sample_service.id, current_year - 1)
|
||||
assert free_limit.free_sms_fragment_limit == 240000
|
||||
|
||||
for year in range(current_year, current_year + 3):
|
||||
free_limit = dao_get_free_sms_fragment_limit_for_year(sample_service.id, year)
|
||||
assert free_limit.free_sms_fragment_limit == 9999
|
||||
|
||||
Reference in New Issue
Block a user