mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-12 05:31:16 -05:00
Merge pull request #1321 from alphagov/remove-delivery_status
Removed the _delivery_status endpoint
This commit is contained in:
@@ -1,17 +1,10 @@
|
||||
from datetime import (
|
||||
datetime,
|
||||
timedelta
|
||||
)
|
||||
|
||||
from flask import (
|
||||
jsonify,
|
||||
Blueprint,
|
||||
request,
|
||||
current_app
|
||||
request
|
||||
)
|
||||
|
||||
from app import db, version
|
||||
from app.models import Notification
|
||||
|
||||
status = Blueprint('status', __name__)
|
||||
|
||||
@@ -29,38 +22,7 @@ def show_status():
|
||||
db_version=get_db_version()), 200
|
||||
|
||||
|
||||
@status.route('/_delivery_status')
|
||||
def show_delivery_status():
|
||||
if request.args.get('elb', None):
|
||||
return jsonify(status="ok"), 200
|
||||
else:
|
||||
notifications_alert = current_app.config['NOTIFICATIONS_ALERT']
|
||||
some_number_of_minutes_ago = datetime.utcnow() - timedelta(minutes=notifications_alert)
|
||||
notifications = Notification.query.filter(Notification.status == 'sending',
|
||||
Notification.created_at < some_number_of_minutes_ago).all()
|
||||
message = "{} notifications in sending state over {} minutes".format(len(notifications), notifications_alert)
|
||||
if notifications:
|
||||
return jsonify(
|
||||
status="error",
|
||||
message=message,
|
||||
travis_commit=version.__travis_commit__,
|
||||
travis_build_number=version.__travis_job_number__,
|
||||
build_time=version.__time__,
|
||||
db_version=get_db_version()), 500
|
||||
|
||||
return jsonify(
|
||||
status="ok",
|
||||
message=message,
|
||||
travis_commit=version.__travis_commit__,
|
||||
travis_build_number=version.__travis_job_number__,
|
||||
build_time=version.__time__,
|
||||
db_version=get_db_version()), 200
|
||||
|
||||
|
||||
def get_db_version():
|
||||
try:
|
||||
query = 'SELECT version_num FROM alembic_version'
|
||||
full_name = db.session.execute(query).fetchone()[0]
|
||||
return full_name
|
||||
except:
|
||||
return 'n/a'
|
||||
query = 'SELECT version_num FROM alembic_version'
|
||||
full_name = db.session.execute(query).fetchone()[0]
|
||||
return full_name
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
import json
|
||||
|
||||
from datetime import (
|
||||
datetime,
|
||||
timedelta
|
||||
)
|
||||
|
||||
from tests.app.conftest import sample_notification
|
||||
|
||||
|
||||
def test_get_delivery_status_all_ok(notify_api, notify_db):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
path = '/_delivery_status'
|
||||
response = client.get(path)
|
||||
assert response.status_code == 200
|
||||
resp_json = json.loads(response.get_data(as_text=True))
|
||||
assert resp_json['status'] == 'ok'
|
||||
assert resp_json['message'] == '0 notifications in sending state over 5 minutes'
|
||||
|
||||
|
||||
def test_get_delivery_status_with_undelivered_notification(notify_api, notify_db, notify_db_session):
|
||||
|
||||
notification = sample_notification(notify_db=notify_db, notify_db_session=notify_db_session, status='sending')
|
||||
more_than_five_mins_ago = datetime.utcnow() - timedelta(minutes=10)
|
||||
notification.created_at = more_than_five_mins_ago
|
||||
notify_db.session.add(notification)
|
||||
notify_db.session.commit()
|
||||
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
path = '/_delivery_status'
|
||||
response = client.get(path)
|
||||
assert response.status_code == 500
|
||||
resp_json = json.loads(response.get_data(as_text=True))
|
||||
assert resp_json['status'] == 'error'
|
||||
assert resp_json['message'] == '1 notifications in sending state over 5 minutes'
|
||||
Reference in New Issue
Block a user