mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
Added free_sms_fragment_limit model, schema, dao and Rest
This commit is contained in:
@@ -14,6 +14,8 @@ from tests.app.db import (
|
||||
)
|
||||
|
||||
from tests import create_authorization_header
|
||||
from app.dao.annual_billing_dao import dao_get_free_sms_fragment_limit_for_year, dao_create_new_annual_billing_for_year
|
||||
from app.models import AnnualBilling
|
||||
|
||||
APR_2016_MONTH_START = datetime(2016, 3, 31, 23, 00, 00)
|
||||
APR_2016_MONTH_END = datetime(2016, 4, 30, 22, 59, 59, 99999)
|
||||
@@ -251,3 +253,123 @@ def test_transform_billing_calculates_with_different_rate_multipliers(sample_ser
|
||||
'month': 'April',
|
||||
'rate': 0.12,
|
||||
})
|
||||
|
||||
|
||||
# def test_get_annual_billing(client, sample_service):
|
||||
#
|
||||
# years = [2016, 2017, 2018]
|
||||
# for y in years:
|
||||
# data = AnnualBilling(
|
||||
# free_sms_fragment_limit=250000,
|
||||
# financial_year_start=y,
|
||||
# service_id=sample_service.id,
|
||||
# )
|
||||
# dao_create_new_free_sms_fragment_limit_for_year(data)
|
||||
#
|
||||
# response = client.get('service/{}/annual-billing'.format(sample_service.id),
|
||||
# headers=[('Content-Type', 'application/json'), create_authorization_header()])
|
||||
#
|
||||
# json_resp = json.loads(response.get_data(as_text=True))
|
||||
#
|
||||
# assert len(json_resp['data']) == 3
|
||||
# assert response.status_code == 200
|
||||
#
|
||||
#
|
||||
# def test_get_annual_billing_no_data_throws_error(client, sample_service):
|
||||
#
|
||||
# response = client.get('service/{}/annual-billing'.format(sample_service.id),
|
||||
# headers=[('Content-Type', 'application/json'), create_authorization_header()])
|
||||
#
|
||||
# json_resp = json.loads(response.get_data(as_text=True))
|
||||
#
|
||||
# assert response.status_code == 404
|
||||
|
||||
|
||||
def test_get_free_sms_fragment_limit(client, sample_service):
|
||||
years = [2016, 2017, 2018]
|
||||
sms_allowance = [1000, 2000, 3000]
|
||||
for i in range(0, len(years)):
|
||||
y = years[i]
|
||||
sms_l = sms_allowance[i]
|
||||
data = AnnualBilling(
|
||||
free_sms_fragment_limit=sms_l,
|
||||
financial_year_start=y,
|
||||
service_id=sample_service.id,
|
||||
)
|
||||
dao_create_new_annual_billing_for_year(data)
|
||||
|
||||
response = client.get('service/{}/billing/free-sms-fragment-limit?financial_year_start=2017'
|
||||
.format(sample_service.id),
|
||||
headers=[('Content-Type', 'application/json'), create_authorization_header()])
|
||||
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
assert response.status_code == 200
|
||||
|
||||
assert json_resp['data']['free_sms_fragment_limit'] == 2000
|
||||
assert json_resp['data']['financial_year_start'] == 2017
|
||||
|
||||
response = client.get(
|
||||
'service/{}/billing/free-sms-fragment-limit'.format(sample_service.id),
|
||||
headers=[('Content-Type', 'application/json'), create_authorization_header()])
|
||||
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
|
||||
assert len(json_resp['data']) == 3
|
||||
assert response.status_code == 200
|
||||
for i in range(0, len(years)):
|
||||
assert json_resp['data'][i]['free_sms_fragment_limit'] == sms_allowance[i]
|
||||
assert json_resp['data'][i]['financial_year_start'] == years[i]
|
||||
|
||||
|
||||
def test_create_update_free_sms_fragment_limit_invalid_schema(client, sample_service):
|
||||
|
||||
response = client.post('service/{}/billing/free-sms-fragment-limit'.format(sample_service.id),
|
||||
data={},
|
||||
headers=[('Content-Type', 'application/json'), create_authorization_header()])
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
|
||||
assert response.status_code == 400
|
||||
assert 'JSON' in json_resp['message']
|
||||
|
||||
|
||||
def test_create_free_sms_fragment_limit(client, sample_service):
|
||||
|
||||
data = {'financial_year_start': 2017, 'free_sms_fragment_limit': 250}
|
||||
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),
|
||||
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['data']['financial_year_start'] == 2017
|
||||
assert json_resp['data']['free_sms_fragment_limit'] == 250
|
||||
|
||||
|
||||
def test_update_free_sms_fragment_limit(client, sample_service):
|
||||
|
||||
data_old = {'financial_year_start': 2015, 'free_sms_fragment_limit': 1000}
|
||||
response = client.post('service/{}/billing/free-sms-fragment-limit'.format(sample_service.id),
|
||||
data=json.dumps(data_old),
|
||||
headers=[('Content-Type', 'application/json'), create_authorization_header()])
|
||||
|
||||
data_new = {'financial_year_start': 2015, 'free_sms_fragment_limit': 9999}
|
||||
response = client.post('service/{}/billing/free-sms-fragment-limit'.format(sample_service.id),
|
||||
data=json.dumps(data_new),
|
||||
headers=[('Content-Type', 'application/json'), create_authorization_header()])
|
||||
|
||||
response_get = client.get(
|
||||
'service/{}/billing/free-sms-fragment-limit?financial_year_start=2015'.format(sample_service.id),
|
||||
headers=[('Content-Type', 'application/json'), create_authorization_header()])
|
||||
|
||||
json_resp = json.loads(response_get.get_data(as_text=True))
|
||||
new_free_limit = dao_get_free_sms_fragment_limit_for_year(sample_service.id, 2015)
|
||||
|
||||
assert response.status_code == 201
|
||||
assert response_get.status_code == 200
|
||||
assert json_resp['data']['financial_year_start'] == 2015
|
||||
assert json_resp['data']['free_sms_fragment_limit'] == 9999
|
||||
|
||||
46
tests/app/dao/test_annual_billing_dao.py
Normal file
46
tests/app/dao/test_annual_billing_dao.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# from datetime import datetime, timedelta
|
||||
# import uuid
|
||||
# import functools
|
||||
# import pytest
|
||||
|
||||
from app.models import AnnualBilling
|
||||
from app.dao.annual_billing_dao import (
|
||||
dao_create_new_annual_billing_for_year,
|
||||
dao_get_free_sms_fragment_limit_for_year,
|
||||
dao_update_new_free_sms_fragment_limit_for_year
|
||||
)
|
||||
|
||||
|
||||
def test_dao_create_get_free_sms_fragment_limit(notify_db_session, sample_service):
|
||||
year = 2016
|
||||
data = AnnualBilling(
|
||||
free_sms_fragment_limit=250000,
|
||||
financial_year_start=year,
|
||||
service_id=sample_service.id,
|
||||
)
|
||||
dao_create_new_annual_billing_for_year(data)
|
||||
|
||||
free_limit = dao_get_free_sms_fragment_limit_for_year(sample_service.id, year)
|
||||
|
||||
assert free_limit.free_sms_fragment_limit == 250000
|
||||
assert free_limit.financial_year_start == year
|
||||
assert free_limit.service_id == sample_service.id
|
||||
|
||||
|
||||
def test_dao_update_free_sms_fragment_limit(notify_db_session, sample_service):
|
||||
year = 2016
|
||||
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_new_annual_billing_for_year(data)
|
||||
data.free_sms_fragment_limit = new_limit
|
||||
dao_update_new_free_sms_fragment_limit_for_year(data)
|
||||
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
|
||||
Reference in New Issue
Block a user