mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-25 00:33:41 -04:00
removed unused import and minor syntax
This commit is contained in:
@@ -101,9 +101,9 @@ def get_free_sms_fragment_limit(service_id):
|
|||||||
|
|
||||||
financial_year_start = request.args.get('financial_year_start')
|
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,
|
# 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.
|
# 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,
|
# 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()
|
financial_year_start = get_current_financial_year_start_year()
|
||||||
|
|
||||||
if int(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:
|
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,
|
annual_billing = dao_create_or_update_annual_billing_for_year(service_id,
|
||||||
financial_year_start)
|
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"])
|
@billing_blueprint.route('/free-sms-fragment-limit', methods=["POST"])
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from app import db, create_uuid
|
from app import db
|
||||||
from app.dao.dao_utils import (
|
from app.dao.dao_utils import (
|
||||||
transactional,
|
transactional,
|
||||||
version_class
|
|
||||||
)
|
)
|
||||||
from app.models import AnnualBilling
|
from app.models import AnnualBilling
|
||||||
from app.dao.date_util import get_current_financial_year_start_year
|
from app.dao.date_util import get_current_financial_year_start_year
|
||||||
|
|||||||
@@ -16,10 +16,9 @@ from tests.app.db import (
|
|||||||
from tests import create_authorization_header
|
from tests import create_authorization_header
|
||||||
|
|
||||||
from app.dao.date_util import get_current_financial_year_start_year
|
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
|
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_START = datetime(2016, 3, 31, 23, 00, 00)
|
||||||
APR_2016_MONTH_END = datetime(2016, 4, 30, 22, 59, 59, 99999)
|
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):
|
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}
|
data = {'free_sms_fragment_limit': 9999}
|
||||||
response = client.post('service/{}/billing/free-sms-fragment-limit'.format(sample_service.id),
|
response = client.post('service/{}/billing/free-sms-fragment-limit'.format(sample_service.id),
|
||||||
data=json.dumps(data),
|
data=json.dumps(data),
|
||||||
headers=[('Content-Type', 'application/json'), create_authorization_header()])
|
headers=[('Content-Type', 'application/json'), create_authorization_header()])
|
||||||
|
|
||||||
response_get = client.get(
|
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()])
|
headers=[('Content-Type', 'application/json'), create_authorization_header()])
|
||||||
|
|
||||||
json_resp = json.loads(response_get.get_data(as_text=True))
|
json_resp = json.loads(response_get.get_data(as_text=True))
|
||||||
assert response.status_code == 201
|
assert response.status_code == 201
|
||||||
assert response_get.status_code == 200
|
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
|
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):
|
def test_update_free_sms_fragment_limit(client, sample_service):
|
||||||
current_year = get_current_financial_year_start_year()
|
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}
|
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),
|
response = client.post('service/{}/billing/free-sms-fragment-limit'.format(sample_service.id),
|
||||||
data=json.dumps(data_new),
|
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, 9999, current_year - 1)
|
||||||
create_annual_billing(sample_service.id, 10000, 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(
|
res_get = client.get(
|
||||||
'service/{}/billing/free-sms-fragment-limit?financial_year_start={}'
|
'service/{}/billing/free-sms-fragment-limit?financial_year_start={}'
|
||||||
.format(sample_service.id, current_year - 2),
|
.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):
|
def test_get_free_sms_fragment_limit_future_year_not_exist(client, sample_service):
|
||||||
current_year = get_current_financial_year_start_year()
|
current_year = get_current_financial_year_start_year()
|
||||||
create_annual_billing(sample_service.id, 9999, 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, 10000, 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(
|
res_get = client.get(
|
||||||
'service/{}/billing/free-sms-fragment-limit?financial_year_start={}'
|
'service/{}/billing/free-sms-fragment-limit?financial_year_start={}'
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
from app.dao.date_util 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 (
|
from app.dao.annual_billing_dao import (
|
||||||
dao_create_or_update_annual_billing_for_year,
|
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,
|
|
||||||
dao_update_annual_billing_for_current_and_future_years,
|
dao_update_annual_billing_for_current_and_future_years,
|
||||||
)
|
)
|
||||||
from tests.app.db import create_annual_billing
|
from tests.app.db import create_annual_billing
|
||||||
|
|||||||
Reference in New Issue
Block a user