Delete job-stats endpoints

Deleted these endpoints:
* /service/<uuid:service_id>/job-stats/<job_id>
* /service/<uuid:service_id>/job-stats
This commit is contained in:
Katie Smith
2018-03-05 16:17:56 +00:00
parent 4f7dd1d258
commit 44c4026df2
2 changed files with 1 additions and 149 deletions

View File

@@ -5,16 +5,13 @@ from flask import (
current_app current_app
) )
from app import DATETIME_FORMAT
from app.dao.jobs_dao import ( from app.dao.jobs_dao import (
dao_create_job, dao_create_job,
dao_update_job, dao_update_job,
dao_get_job_by_service_id_and_job_id, dao_get_job_by_service_id_and_job_id,
dao_get_jobs_by_service_id, dao_get_jobs_by_service_id,
dao_get_future_scheduled_job_by_id_and_service_id, dao_get_future_scheduled_job_by_id_and_service_id,
dao_get_notification_outcomes_for_job, dao_get_notification_outcomes_for_job)
dao_get_job_stats_for_service,
dao_get_job_statistics_for_job)
from app.dao.services_dao import dao_fetch_service_by_id from app.dao.services_dao import dao_fetch_service_by_id
from app.dao.templates_dao import dao_get_template_by_id from app.dao.templates_dao import dao_get_template_by_id
from app.dao.notifications_dao import get_notifications_for_job from app.dao.notifications_dao import get_notifications_for_job
@@ -51,13 +48,6 @@ def get_job_by_service_and_job_id(service_id, job_id):
return jsonify(data=data) return jsonify(data=data)
@job_blueprint.route('/job-stats/<job_id>', methods=['GET'])
def get_job_stats_by_service_and_job_id(service_id, job_id):
statistic = dao_get_job_statistics_for_job(service_id=service_id, job_id=job_id)
return jsonify(_serialize_job_stats(statistic))
@job_blueprint.route('/<job_id>/cancel', methods=['POST']) @job_blueprint.route('/<job_id>/cancel', methods=['POST'])
def cancel_job(service_id, job_id): def cancel_job(service_id, job_id):
job = dao_get_future_scheduled_job_by_id_and_service_id(job_id, service_id) job = dao_get_future_scheduled_job_by_id_and_service_id(job_id, service_id)
@@ -118,57 +108,6 @@ def get_jobs_by_service(service_id):
return jsonify(**get_paginated_jobs(service_id, limit_days, statuses, page)) return jsonify(**get_paginated_jobs(service_id, limit_days, statuses, page))
@job_blueprint.route('/job-stats', methods=['GET'])
def get_jobs_for_service(service_id):
if request.args.get('limit_days'):
try:
limit_days = int(request.args['limit_days'])
except ValueError:
errors = {'limit_days': ['{} is not an integer'.format(request.args['limit_days'])]}
raise InvalidRequest(errors, status_code=400)
else:
limit_days = None
statuses = _parse_statuses(request.args.get('statuses', ''))
page = int(request.args.get('page', 1))
pagination = dao_get_job_stats_for_service(service_id=service_id,
page=page,
page_size=current_app.config['PAGE_SIZE'],
limit_days=limit_days,
statuses=statuses)
return jsonify({
'data': [_serialize_job_stats(x) for x in pagination.items],
'page_size': pagination.per_page,
'total': pagination.total,
'links': pagination_links(
pagination,
'.get_jobs_by_service',
service_id=service_id
)
})
def _parse_statuses(statuses):
return [x.strip() for x in statuses.split(',')]
def _serialize_job_stats(stat):
return {
"job_id": stat.job_id,
"original_file_name": stat.original_file_name,
"created_at": stat.created_at.strftime(DATETIME_FORMAT),
"scheduled_for": stat.scheduled_for,
"template_id": stat.template_id,
"template_version": stat.template_version,
"job_status": stat.job_status,
"service_id": stat.service_id,
"requested": stat.notification_count,
"sent": stat.sent,
"delivered": stat.delivered,
"failed": stat.failed
}
@job_blueprint.route('', methods=['POST']) @job_blueprint.route('', methods=['POST'])
def create_job(service_id): def create_job(service_id):
service = dao_fetch_service_by_id(service_id) service = dao_fetch_service_by_id(service_id)

View File

@@ -6,7 +6,6 @@ from freezegun import freeze_time
import pytest import pytest
import pytz import pytz
import app.celery.tasks import app.celery.tasks
from app import DATETIME_FORMAT
from tests import create_authorization_header from tests import create_authorization_header
from tests.conftest import set_config from tests.conftest import set_config
@@ -769,89 +768,3 @@ def test_get_all_notifications_for_job_returns_csv_format(
notification = resp['notifications'][0] notification = resp['notifications'][0]
assert set(notification.keys()) == \ assert set(notification.keys()) == \
set(['created_at', 'template_type', 'template_name', 'job_name', 'status', 'row_number', 'recipient']) set(['created_at', 'template_type', 'template_name', 'job_name', 'status', 'row_number', 'recipient'])
# New endpoint to get job statistics the old tests will be refactored away.
def test_get_jobs_for_service_new_endpoint(client, notify_db, notify_db_session, sample_template):
_setup_jobs(notify_db, notify_db_session, sample_template)
service_id = sample_template.service.id
path = '/service/{}/job/job-stats'.format(service_id)
auth_header = create_authorization_header()
response = client.get(path, headers=[auth_header])
assert response.status_code == 200
resp_json = json.loads(response.get_data(as_text=True))
assert len(resp_json['data']) == 5
assert resp_json['data'][0]["job_id"]
assert resp_json['data'][0]["created_at"]
assert not resp_json['data'][0]["scheduled_for"]
assert resp_json['data'][0]["template_id"]
assert resp_json['data'][0]["template_version"]
assert resp_json['data'][0]["service_id"]
assert resp_json['data'][0]["requested"]
assert resp_json['data'][0]["sent"] == 0
assert resp_json['data'][0]["delivered"] == 0
assert resp_json['data'][0]["failed"] == 0
def test_get_jobs_raises_for_bad_limit_days(client, sample_service):
path = '/service/{}/job/job-stats'.format(sample_service.id)
auth_header = create_authorization_header()
response = client.get(path,
query_string={'limit_days': 'bad_number'},
headers=[auth_header])
assert response.status_code == 400
resp_json = json.loads(response.get_data(as_text=True))
assert resp_json["result"] == "error"
assert resp_json["message"] == {'limit_days': ['bad_number is not an integer']}
def test_parse_status_turns_comma_sep_strings_into_list():
statuses = "started, finished, pending"
from app.job.rest import _parse_statuses
assert _parse_statuses(statuses) == ["started", "finished", "pending"]
def test_parse_status_turns_empty_string_into_empty_list():
statuses = ""
from app.job.rest import _parse_statuses
assert _parse_statuses(statuses) == ['']
def test_get_job_stats_by_service_id_and_job_id(client, sample_job):
auth_header = create_authorization_header()
response = client.get("/service/{}/job/job-stats/{}".format(sample_job.service_id, sample_job.id),
headers=[auth_header])
assert response.status_code == 200
resp_json = json.loads(response.get_data(as_text=True))
assert resp_json["job_id"] == str(sample_job.id)
assert resp_json["created_at"] == sample_job.created_at.strftime(DATETIME_FORMAT)
assert not resp_json["scheduled_for"]
assert resp_json["template_id"] == str(sample_job.template_id)
assert resp_json["template_version"] == sample_job.template_version
assert resp_json["service_id"] == str(sample_job.service_id)
assert resp_json["requested"] == sample_job.notification_count
assert resp_json["sent"] == 0
assert resp_json["delivered"] == 0
assert resp_json["failed"] == 0
def test_get_job_stats_with_invalid_job_id_returns404(client, sample_template):
path = '/service/{}/job/job-stats/{}'.format(sample_template.service.id, uuid.uuid4())
auth_header = create_authorization_header()
response = client.get(path, headers=[auth_header])
assert response.status_code == 404
resp_json = json.loads(response.get_data(as_text=True))
assert resp_json['result'] == 'error'
assert resp_json['message'] == 'No result found'
def test_get_job_stats_with_invalid_service_id_returns404(client, sample_job):
path = '/service/{}/job/job-stats/{}'.format(uuid.uuid4(), sample_job.id)
auth_header = create_authorization_header()
response = client.get(path, headers=[auth_header])
assert response.status_code == 404
resp_json = json.loads(response.get_data(as_text=True))
assert resp_json['result'] == 'error'
assert resp_json['message'] == 'No result found'