removed unused import and minor syntax

This commit is contained in:
venusbb
2017-11-02 17:02:00 +00:00
parent 6875ab150a
commit ad386b7d28
4 changed files with 26 additions and 18 deletions

View File

@@ -101,9 +101,9 @@ def get_free_sms_fragment_limit(service_id):
financial_year_start = request.args.get('financial_year_start')
result = dao_get_free_sms_fragment_limit_for_year(service_id, financial_year_start)
annual_billing = dao_get_free_sms_fragment_limit_for_year(service_id, financial_year_start)
if result is None:
if annual_billing is None:
# An entry does not exist in annual_billing table for that service and year. If it is a past year,
# we return the oldest entry.
# If it is the current or future years, we create an entry in the db table using the newest record,
@@ -117,14 +117,15 @@ def get_free_sms_fragment_limit(service_id):
financial_year_start = get_current_financial_year_start_year()
if int(financial_year_start) < get_current_financial_year_start_year():
result = sms_list[0] # The oldest entry
annual_billing = sms_list[0] # The oldest entry
else:
result = sms_list[-1] # The newest entry
annual_billing = sms_list[-1] # The newest entry
result = dao_create_or_update_annual_billing_for_year(service_id, result.free_sms_fragment_limit,
financial_year_start)
annual_billing = dao_create_or_update_annual_billing_for_year(service_id,
annual_billing.free_sms_fragment_limit,
financial_year_start)
return jsonify(result.serialize_free_sms_items()), 200
return jsonify(annual_billing.serialize_free_sms_items()), 200
@billing_blueprint.route('/free-sms-fragment-limit', methods=["POST"])

View File

@@ -1,7 +1,6 @@
from app import db, create_uuid
from app import db
from app.dao.dao_utils import (
transactional,
version_class
)
from app.models import AnnualBilling
from app.dao.date_util import get_current_financial_year_start_year

View File

@@ -16,10 +16,9 @@ from tests.app.db import (
from tests import create_authorization_header
from app.dao.date_util import get_current_financial_year_start_year
from app.dao.annual_billing_dao import dao_get_free_sms_fragment_limit_for_year
from tests.app.db import create_annual_billing
import uuid
import app
APR_2016_MONTH_START = datetime(2016, 3, 31, 23, 00, 00)
APR_2016_MONTH_END = datetime(2016, 4, 30, 22, 59, 59, 99999)
@@ -271,20 +270,20 @@ def test_create_update_free_sms_fragment_limit_invalid_schema(client, sample_ser
def test_create_free_sms_fragment_limit_current_year(client, sample_service):
current_year = get_current_financial_year_start_year()
data = {'free_sms_fragment_limit': 9999}
response = client.post('service/{}/billing/free-sms-fragment-limit'.format(sample_service.id),
data=json.dumps(data),
headers=[('Content-Type', 'application/json'), create_authorization_header()])
response_get = client.get(
'service/{}/billing/free-sms-fragment-limit?financial_year_start=2017'.format(sample_service.id),
'service/{}/billing/free-sms-fragment-limit?financial_year_start={}'.format(sample_service.id, current_year),
headers=[('Content-Type', 'application/json'), create_authorization_header()])
json_resp = json.loads(response_get.get_data(as_text=True))
assert response.status_code == 201
assert response_get.status_code == 200
assert json_resp['financial_year_start'] == get_current_financial_year_start_year()
assert json_resp['financial_year_start'] == current_year
assert json_resp['free_sms_fragment_limit'] == 9999
@@ -308,6 +307,10 @@ def test_create_free_sms_fragment_limit_past_year(client, sample_service):
def test_update_free_sms_fragment_limit(client, sample_service):
current_year = get_current_financial_year_start_year()
annual_billing = dao_get_free_sms_fragment_limit_for_year(sample_service.id, current_year)
assert annual_billing.free_sms_fragment_limit == 250000
data_new = {'financial_year_start': current_year, 'free_sms_fragment_limit': 9999}
response = client.post('service/{}/billing/free-sms-fragment-limit'.format(sample_service.id),
data=json.dumps(data_new),
@@ -346,6 +349,9 @@ def test_get_free_sms_fragment_limit_past_year_not_exist(client, sample_service)
create_annual_billing(sample_service.id, 9999, current_year - 1)
create_annual_billing(sample_service.id, 10000, current_year + 1)
annual_billing = dao_get_free_sms_fragment_limit_for_year(sample_service.id, current_year - 2)
assert annual_billing is None
res_get = client.get(
'service/{}/billing/free-sms-fragment-limit?financial_year_start={}'
.format(sample_service.id, current_year - 2),
@@ -359,8 +365,11 @@ def test_get_free_sms_fragment_limit_past_year_not_exist(client, sample_service)
def test_get_free_sms_fragment_limit_future_year_not_exist(client, sample_service):
current_year = get_current_financial_year_start_year()
create_annual_billing(sample_service.id, 9999, current_year - 1)
create_annual_billing(sample_service.id, 10000, current_year + 1)
create_annual_billing(sample_service.id, free_sms_fragment_limit=9999, financial_year_start=current_year - 1)
create_annual_billing(sample_service.id, free_sms_fragment_limit=10000, financial_year_start=current_year + 1)
annual_billing = dao_get_free_sms_fragment_limit_for_year(sample_service.id, current_year + 2)
assert annual_billing is None
res_get = client.get(
'service/{}/billing/free-sms-fragment-limit?financial_year_start={}'

View File

@@ -1,9 +1,8 @@
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_update_annual_billing_for_current_and_future_years,
)
from tests.app.db import create_annual_billing