mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:26:08 -05:00
Removed the _delivery_status endpoint.
The test this status check was doing does not reflect real traffic of Notify. It is typical for messages to be in 'sending' for a while (people turn off their phone for example).
This commit is contained in:
@@ -1,17 +1,10 @@
|
|||||||
from datetime import (
|
|
||||||
datetime,
|
|
||||||
timedelta
|
|
||||||
)
|
|
||||||
|
|
||||||
from flask import (
|
from flask import (
|
||||||
jsonify,
|
jsonify,
|
||||||
Blueprint,
|
Blueprint,
|
||||||
request,
|
request
|
||||||
current_app
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from app import db, version
|
from app import db, version
|
||||||
from app.models import Notification
|
|
||||||
|
|
||||||
status = Blueprint('status', __name__)
|
status = Blueprint('status', __name__)
|
||||||
|
|
||||||
@@ -29,38 +22,7 @@ def show_status():
|
|||||||
db_version=get_db_version()), 200
|
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():
|
def get_db_version():
|
||||||
try:
|
query = 'SELECT version_num FROM alembic_version'
|
||||||
query = 'SELECT version_num FROM alembic_version'
|
full_name = db.session.execute(query).fetchone()[0]
|
||||||
full_name = db.session.execute(query).fetchone()[0]
|
return full_name
|
||||||
return full_name
|
|
||||||
except:
|
|
||||||
return 'n/a'
|
|
||||||
|
|||||||
@@ -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