Delete old platform-stats route

We no longer need the `/platform-stats` route in the service blueprint,
because admin is using the new `/platform-stats` route in the platform stats
blueprint instead.
This commit is contained in:
Katie Smith
2018-07-10 14:59:24 +01:00
parent 07d274c2e6
commit 0cb9e335b9
3 changed files with 0 additions and 96 deletions

View File

@@ -380,35 +380,6 @@ def fetch_stats_by_date_range_for_all_services(start_date, end_date, include_fro
return query.all() return query.all()
@statsd(namespace='dao')
def fetch_aggregate_stats_by_date_range_for_all_services(start_date, end_date, include_from_test_key=True):
start_date = get_london_midnight_in_utc(start_date)
end_date = get_london_midnight_in_utc(end_date + timedelta(days=1))
table = NotificationHistory
if start_date >= datetime.utcnow() - timedelta(days=7):
table = Notification
query = db.session.query(
table.notification_type,
table.status,
func.count(table.id).label('count')
).filter(
table.created_at >= start_date,
table.created_at < end_date
).group_by(
table.notification_type,
table.status
).order_by(
table.notification_type
)
if not include_from_test_key:
query = query.filter(table.key_type != KEY_TYPE_TEST)
return query.all()
@transactional @transactional
@version_class(Service) @version_class(Service)
@version_class(ApiKey) @version_class(ApiKey)

View File

@@ -47,7 +47,6 @@ from app.dao.services_dao import (
dao_remove_user_from_service, dao_remove_user_from_service,
dao_suspend_service, dao_suspend_service,
dao_update_service, dao_update_service,
fetch_aggregate_stats_by_date_range_for_all_services,
fetch_stats_by_date_range_for_all_services fetch_stats_by_date_range_for_all_services
) )
from app.dao.service_whitelist_dao import ( from app.dao.service_whitelist_dao import (
@@ -116,25 +115,6 @@ def handle_integrity_error(exc):
return jsonify(result='error', message="Internal server error"), 500 return jsonify(result='error', message="Internal server error"), 500
@service_blueprint.route('/platform-stats', methods=['GET'])
def get_platform_stats():
include_from_test_key = request.args.get('include_from_test_key', 'True') != 'False'
# If start and end date are not set, we are expecting today's stats.
today = str(datetime.utcnow().date())
start_date = datetime.strptime(request.args.get('start_date', today), '%Y-%m-%d').date()
end_date = datetime.strptime(request.args.get('end_date', today), '%Y-%m-%d').date()
data = fetch_aggregate_stats_by_date_range_for_all_services(start_date=start_date,
end_date=end_date,
include_from_test_key=include_from_test_key
)
stats = statistics.format_statistics(data)
result = jsonify(stats)
return result
@service_blueprint.route('', methods=['GET']) @service_blueprint.route('', methods=['GET'])
def get_services(): def get_services():
only_active = request.args.get('only_active') == 'True' only_active = request.args.get('only_active') == 'True'

View File

@@ -2782,50 +2782,3 @@ def test_get_organisation_for_service_id_return_empty_dict_if_service_not_in_org
service_id=fake_uuid service_id=fake_uuid
) )
assert response == {} assert response == {}
def test_get_platform_stats(client, notify_db_session):
service_1 = create_service(service_name='Service 1')
service_2 = create_service(service_name='Service 2')
sms_template = create_template(service=service_1)
email_template = create_template(service=service_2, template_type=EMAIL_TYPE)
letter_template = create_template(service=service_2, template_type=LETTER_TYPE)
create_notification(template=sms_template, status='sending')
create_notification(template=sms_template, status='delivered')
create_notification(template=sms_template, status='delivered')
create_notification(template=sms_template, status='delivered')
create_notification(template=email_template, status='temporary-failure')
create_notification(template=email_template, status='delivered')
create_notification(template=letter_template, status='sending')
create_notification(template=letter_template, status='sending')
response = client.get('/service/platform-stats',
headers=[('Content-Type', 'application/json'), create_authorization_header()]
)
assert response.status_code == 200
json_resp = json.loads(response.get_data(as_text=True))
assert json_resp['email'] == {'delivered': 1, 'requested': 2, 'failed': 1}
assert json_resp['letter'] == {'delivered': 0, 'requested': 2, 'failed': 0}
assert json_resp['sms'] == {'delivered': 3, 'requested': 4, 'failed': 0}
def test_get_platform_stats_creates_zero_stats(client, notify_db_session):
service_1 = create_service(service_name='Service 1')
service_2 = create_service(service_name='Service 2')
sms_template = create_template(service=service_1)
email_template = create_template(service=service_2, template_type=EMAIL_TYPE)
create_notification(template=sms_template, status='sending')
create_notification(template=sms_template, status='delivered')
create_notification(template=sms_template, status='delivered')
create_notification(template=sms_template, status='delivered')
create_notification(template=email_template, status='temporary-failure')
create_notification(template=email_template, status='delivered')
response = client.get('/service/platform-stats',
headers=[('Content-Type', 'application/json'), create_authorization_header()]
)
assert response.status_code == 200
json_resp = json.loads(response.get_data(as_text=True))
assert json_resp['email'] == {'failed': 1, 'requested': 2, 'delivered': 1}
assert json_resp['letter'] == {'failed': 0, 'requested': 0, 'delivered': 0}
assert json_resp['sms'] == {'failed': 0, 'requested': 4, 'delivered': 3}