mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05:00
Removed old endpoint.
Going to handle the migration in the clients.
This commit is contained in:
@@ -22,22 +22,6 @@ register_errors(template_statistics)
|
||||
|
||||
|
||||
@template_statistics.route('')
|
||||
def get_template_statistics_for_service(service_id):
|
||||
if request.args.get('limit_days'):
|
||||
try:
|
||||
limit_days = int(request.args['limit_days'])
|
||||
except ValueError as e:
|
||||
error = '{} is not an integer'.format(request.args['limit_days'])
|
||||
message = {'limit_days': [error]}
|
||||
raise InvalidRequest(message, status_code=400)
|
||||
else:
|
||||
limit_days = None
|
||||
stats = dao_get_template_statistics_for_service(service_id, limit_days=limit_days)
|
||||
data = template_statistics_schema.dump(stats, many=True).data
|
||||
return jsonify(data=data)
|
||||
|
||||
|
||||
@template_statistics.route('/replacement')
|
||||
def get_template_statistics_for_service_by_day(service_id):
|
||||
if request.args.get('limit_days'):
|
||||
try:
|
||||
|
||||
@@ -10,14 +10,14 @@ from tests.app.conftest import sample_template as create_sample_template, sample
|
||||
sample_email_template
|
||||
|
||||
|
||||
def test_get_all_template_statistics_with_bad_arg_returns_400(notify_api):
|
||||
def test_get_all_template_statistics_with_bad_arg_returns_400(notify_api, sample_service):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template-statistics/replacement'.format(sample_template.service_id),
|
||||
'/service/{}/template-statistics'.format(sample_service.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header],
|
||||
query_string={'limit_days': 'blurk'}
|
||||
)
|
||||
@@ -44,7 +44,7 @@ def test_get_template_statistics_for_service(notify_db, notify_db_session, notif
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template-statistics/replacement'.format(sample_service.id),
|
||||
'/service/{}/template-statistics'.format(sample_service.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
)
|
||||
|
||||
@@ -80,7 +80,7 @@ def test_get_template_statistics_for_service_by_day(notify_db, notify_db_session
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template-statistics/replacement'.format(sample_service.id),
|
||||
'/service/{}/template-statistics'.format(sample_service.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header],
|
||||
query_string={'limit_days': 1}
|
||||
)
|
||||
@@ -100,7 +100,7 @@ def test_get_template_statistics_for_service_by_day(notify_db, notify_db_session
|
||||
assert json_resp['data'][1]['day'] == '2016-08-18'
|
||||
|
||||
response_for_a_week = client.get(
|
||||
'/service/{}/template-statistics/replacement'.format(sample_service.id),
|
||||
'/service/{}/template-statistics'.format(sample_service.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header],
|
||||
query_string={'limit_days': 7}
|
||||
)
|
||||
@@ -130,7 +130,7 @@ def test_returns_empty_list_if_no_templates_used(notify_api, sample_service):
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template-statistics/replacement'.format(sample_service.id),
|
||||
'/service/{}/template-statistics'.format(sample_service.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
)
|
||||
|
||||
@@ -139,131 +139,6 @@ def test_returns_empty_list_if_no_templates_used(notify_api, sample_service):
|
||||
assert len(json_resp['data']) == 0
|
||||
|
||||
|
||||
@freeze_time('2016-04-09')
|
||||
def test_get_template_statistics_for_service_for_last_week(notify_api, sample_template):
|
||||
|
||||
# make 9 stats records from 1st to 9th April
|
||||
for i in range(1, 10):
|
||||
past_date = '2016-04-0{}'.format(i)
|
||||
with freeze_time(past_date):
|
||||
template_stats = TemplateStatistics(template_id=sample_template.id,
|
||||
service_id=sample_template.service_id)
|
||||
db.session.add(template_stats)
|
||||
db.session.commit()
|
||||
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template-statistics'.format(sample_template.service_id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header],
|
||||
query_string={'limit_days': 7}
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
assert len(json_resp['data']) == 8
|
||||
assert json_resp['data'][0]['day'] == '2016-04-09'
|
||||
assert json_resp['data'][6]['day'] == '2016-04-03'
|
||||
|
||||
|
||||
@freeze_time('2016-04-30')
|
||||
def test_get_template_statistics_for_service_for_last_week_with_no_data(notify_api, sample_template):
|
||||
|
||||
# make 9 stats records from 1st to 9th April
|
||||
for i in range(1, 10):
|
||||
past_date = '2016-04-0{}'.format(i)
|
||||
with freeze_time(past_date):
|
||||
template_stats = TemplateStatistics(template_id=sample_template.id,
|
||||
service_id=sample_template.service_id)
|
||||
db.session.add(template_stats)
|
||||
db.session.commit()
|
||||
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
# Date is frozen at 2016-04-30 and no data written since
|
||||
response = client.get(
|
||||
'/service/{}/template-statistics'.format(sample_template.service_id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header],
|
||||
query_string={'limit_days': 7}
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
assert len(json_resp['data']) == 0
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template-statistics'.format(sample_template.service_id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header],
|
||||
query_string={'limit_days': 30}
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
assert len(json_resp['data']) == 9
|
||||
|
||||
|
||||
def test_get_all_template_statistics_for_service(notify_api, sample_template):
|
||||
|
||||
# make 9 stats records from 1st to 9th April
|
||||
for i in range(1, 10):
|
||||
past_date = '2016-04-0{}'.format(i)
|
||||
with freeze_time(past_date):
|
||||
template_stats = TemplateStatistics(template_id=sample_template.id,
|
||||
service_id=sample_template.service_id)
|
||||
db.session.add(template_stats)
|
||||
db.session.commit()
|
||||
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template-statistics'.format(sample_template.service_id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
assert len(json_resp['data']) == 9
|
||||
assert json_resp['data'][0]['day'] == '2016-04-09'
|
||||
assert json_resp['data'][8]['day'] == '2016-04-01'
|
||||
|
||||
|
||||
def test_get_all_template_statistics_with_bad_limit_arg_returns_400(notify_api, sample_template):
|
||||
|
||||
# make 9 stats records from 1st to 9th April
|
||||
for i in range(1, 10):
|
||||
past_date = '2016-04-0{}'.format(i)
|
||||
with freeze_time(past_date):
|
||||
template_stats = TemplateStatistics(template_id=sample_template.id,
|
||||
service_id=sample_template.service_id)
|
||||
db.session.add(template_stats)
|
||||
db.session.commit()
|
||||
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template-statistics'.format(sample_template.service_id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header],
|
||||
query_string={'limit_days': 'blurk'}
|
||||
)
|
||||
|
||||
assert response.status_code == 400
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
assert json_resp['result'] == 'error'
|
||||
assert json_resp['message'] == {'limit_days': ['blurk is not an integer']}
|
||||
|
||||
|
||||
def test_get_template_statistics_for_template_only_returns_for_provided_template(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
|
||||
Reference in New Issue
Block a user