incorporate reviewers comments

This commit is contained in:
venusbb
2017-10-26 11:49:56 +01:00
parent e8f659837a
commit 9aa7489655
5 changed files with 52 additions and 5 deletions

View File

@@ -34,7 +34,7 @@ def dao_get_all_free_sms_fragment_limit(service_id):
).order_by(AnnualBilling.financial_year_start).all()
def insert_annual_billing(service):
def dao_insert_annual_billing(service):
"""
This method is called from create_service which is wrapped in a transaction.
"""

View File

@@ -42,7 +42,7 @@ from app.models import (
from app.service.statistics import format_monthly_template_notification_stats
from app.statsd_decorators import statsd
from app.utils import get_london_month_from_utc_column, get_london_midnight_in_utc
from app.dao.annual_billing_dao import insert_annual_billing
from app.dao.annual_billing_dao import dao_insert_annual_billing
DEFAULT_SERVICE_PERMISSIONS = [
SMS_TYPE,
@@ -181,7 +181,7 @@ def dao_create_service(service, user, service_id=None, service_permissions=None)
service.permissions.append(service_permission)
insert_service_sms_sender(service, service.sms_sender)
insert_annual_billing(service)
dao_insert_annual_billing(service)
db.session.add(service)

View File

@@ -17,6 +17,7 @@ from tests import create_authorization_header
from app.dao.annual_billing_dao import (dao_get_free_sms_fragment_limit_for_year,
dao_create_or_update_annual_billing_for_year)
from app.models import AnnualBilling
import uuid
APR_2016_MONTH_START = datetime(2016, 3, 31, 23, 00, 00)
APR_2016_MONTH_END = datetime(2016, 4, 30, 22, 59, 59, 99999)
@@ -359,3 +360,12 @@ def test_get_free_sms_fragment_limit_no_year_data_return_404(client, sample_serv
json_resp = json.loads(response_get.get_data(as_text=True))
assert response_get.status_code == 404
def test_get_free_sms_fragment_limit_unknown_service_id_return_404(client):
response_get = client.get(
'service/{}/billing/free-sms-fragment-limit'.format(uuid.uuid4()),
headers=[('Content-Type', 'application/json'), create_authorization_header()])
json_resp = json.loads(response_get.get_data(as_text=True))
assert response_get.status_code == 404

View File

@@ -2,11 +2,12 @@ from app.service.utils 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_free_sms_fragment_limit_for_year,
dao_get_annual_billing
)
def test_sample_service_has_free_sms_fragment_limit(notify_db_session, sample_service):
def test_get_sample_service_has_default_free_sms_fragment_limit(notify_db_session, sample_service):
# when sample_service was created, it automatically create an entry in the annual_billing table
free_limit = dao_get_free_sms_fragment_limit_for_year(sample_service.id, get_current_financial_year_start_year())
@@ -33,3 +34,24 @@ def test_dao_update_free_sms_fragment_limit(notify_db_session, sample_service):
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]
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)
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

View File

@@ -0,0 +1,15 @@
from app.service.utils import get_current_financial_year_start_year
from freezegun import freeze_time
# see get_financial_year for conversion of financial years.
@freeze_time("2001-03-31 22:59:59.999999")
def test_get_current_financial_year_start_year_before_march():
current_fy = get_current_financial_year_start_year()
assert current_fy == 2000
@freeze_time("2001-03-31 23:00:00.000000")
def test_get_current_financial_year_start_year_after_april():
current_fy = get_current_financial_year_start_year()
assert current_fy == 2001