mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 08:51:30 -05:00
Added a test to ensure that all blueprints have a registered before_request method.
Added a test for the status endpoint.
This commit is contained in:
@@ -92,7 +92,6 @@ def register_blueprint(application):
|
|||||||
from app.notifications.receive_notifications import receive_notifications_blueprint
|
from app.notifications.receive_notifications import receive_notifications_blueprint
|
||||||
from app.notifications.notifications_ses_callback import ses_callback_blueprint
|
from app.notifications.notifications_ses_callback import ses_callback_blueprint
|
||||||
from app.notifications.notifications_sms_callback import sms_callback_blueprint
|
from app.notifications.notifications_sms_callback import sms_callback_blueprint
|
||||||
from app.status.healthcheck import status
|
|
||||||
from app.authentication.auth import requires_admin_auth, requires_auth, requires_no_auth
|
from app.authentication.auth import requires_admin_auth, requires_auth, requires_no_auth
|
||||||
|
|
||||||
service_blueprint.before_request(requires_admin_auth)
|
service_blueprint.before_request(requires_admin_auth)
|
||||||
@@ -107,9 +106,6 @@ def register_blueprint(application):
|
|||||||
status_blueprint.before_request(requires_no_auth)
|
status_blueprint.before_request(requires_no_auth)
|
||||||
application.register_blueprint(status_blueprint)
|
application.register_blueprint(status_blueprint)
|
||||||
|
|
||||||
notifications_blueprint.before_request(requires_auth)
|
|
||||||
receive_notifications_blueprint.before_request(requires_no_auth)
|
|
||||||
|
|
||||||
ses_callback_blueprint.before_request(requires_no_auth)
|
ses_callback_blueprint.before_request(requires_no_auth)
|
||||||
application.register_blueprint(ses_callback_blueprint)
|
application.register_blueprint(ses_callback_blueprint)
|
||||||
|
|
||||||
@@ -149,13 +145,11 @@ def register_blueprint(application):
|
|||||||
organisation_blueprint.before_request(requires_admin_auth)
|
organisation_blueprint.before_request(requires_admin_auth)
|
||||||
application.register_blueprint(organisation_blueprint, url_prefix='/organisation')
|
application.register_blueprint(organisation_blueprint, url_prefix='/organisation')
|
||||||
|
|
||||||
status.before_request(requires_no_auth)
|
|
||||||
application.register_blueprint(status)
|
|
||||||
|
|
||||||
|
|
||||||
def register_v2_blueprints(application):
|
def register_v2_blueprints(application):
|
||||||
from app.v2.notifications.post_notifications import v2_notification_blueprint as post_notifications
|
from app.v2.notifications.post_notifications import v2_notification_blueprint as post_notifications
|
||||||
from app.v2.notifications.get_notifications import v2_notification_blueprint as get_notifications
|
from app.v2.notifications.get_notifications import v2_notification_blueprint as get_notifications
|
||||||
|
from app.v2.template.get_template import template_blueprint
|
||||||
from app.authentication.auth import requires_auth
|
from app.authentication.auth import requires_auth
|
||||||
|
|
||||||
post_notifications.before_request(requires_auth)
|
post_notifications.before_request(requires_auth)
|
||||||
@@ -164,26 +158,11 @@ def register_v2_blueprints(application):
|
|||||||
get_notifications.before_request(requires_auth)
|
get_notifications.before_request(requires_auth)
|
||||||
application.register_blueprint(get_notifications)
|
application.register_blueprint(get_notifications)
|
||||||
|
|
||||||
|
template_blueprint.before_request(requires_auth)
|
||||||
|
application.register_blueprint(template_blueprint)
|
||||||
|
|
||||||
|
|
||||||
def init_app(app):
|
def init_app(app):
|
||||||
# @app.before_request
|
|
||||||
# def required_authentication():
|
|
||||||
# no_auth_req = [
|
|
||||||
# url_for('status.show_status'),
|
|
||||||
# url_for('notifications.process_ses_response'),
|
|
||||||
# url_for('notifications.process_firetext_response'),
|
|
||||||
# url_for('notifications.process_mmg_response'),
|
|
||||||
# url_for('notifications.receive_mmg_sms'),
|
|
||||||
# url_for('status.show_delivery_status'),
|
|
||||||
# url_for('spec.get_spec')
|
|
||||||
# ]
|
|
||||||
#
|
|
||||||
# if request.path not in no_auth_req:
|
|
||||||
# from app.authentication import auth
|
|
||||||
# error = auth.requires_auth()
|
|
||||||
# if error:
|
|
||||||
# return error
|
|
||||||
|
|
||||||
@app.before_request
|
@app.before_request
|
||||||
def record_user_agent():
|
def record_user_agent():
|
||||||
statsd_client.incr("user-agent.{}".format(process_user_agent(request.headers.get('User-Agent', None))))
|
statsd_client.incr("user-agent.{}".format(process_user_agent(request.headers.get('User-Agent', None))))
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ from app.dao import (
|
|||||||
|
|
||||||
from app.notifications.process_client_response import validate_callback_data
|
from app.notifications.process_client_response import validate_callback_data
|
||||||
|
|
||||||
ses_callback_blueprint = Blueprint('notifications_ses_callback_', __name__)
|
ses_callback_blueprint = Blueprint('notifications_ses_callback', __name__)
|
||||||
|
|
||||||
from app.errors import (
|
from app.errors import (
|
||||||
register_errors,
|
register_errors,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from flask import request, jsonify
|
|||||||
from app.errors import InvalidRequest, register_errors
|
from app.errors import InvalidRequest, register_errors
|
||||||
from app.notifications.process_client_response import validate_callback_data, process_sms_client_response
|
from app.notifications.process_client_response import validate_callback_data, process_sms_client_response
|
||||||
|
|
||||||
sms_callback_blueprint = Blueprint("sms_callback_blueprint", __name__, url_prefix="/notifications/sms")
|
sms_callback_blueprint = Blueprint("sms_callback", __name__, url_prefix="/notifications/sms")
|
||||||
register_errors(sms_callback_blueprint)
|
register_errors(sms_callback_blueprint)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
13
tests/app/status/test_status.py
Normal file
13
tests/app/status/test_status.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
from flask import json
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_status_all_ok(client):
|
||||||
|
path = '/_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['db_version']
|
||||||
|
assert resp_json['travis_commit']
|
||||||
|
assert resp_json['travis_build_number']
|
||||||
|
assert resp_json['build_time']
|
||||||
12
tests/app/test_route_authentication.py
Normal file
12
tests/app/test_route_authentication.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
def test_all_routes_have_authentication(client):
|
||||||
|
# This tests that each blueprint registered on the application has a before_request function registered.
|
||||||
|
# The None row is removed from the comparison as that is not blueprint specific but app specific.
|
||||||
|
before_req_funcs = set(x for x in client.application.before_request_funcs if x is not None)
|
||||||
|
|
||||||
|
blueprint_names = set(client.application.blueprints.keys())
|
||||||
|
assert blueprint_names == before_req_funcs
|
||||||
|
|
||||||
|
# The static route is always available by default for a Flask app to serve anything in the static folder.
|
||||||
|
routes_blueprint_names = set(
|
||||||
|
[x.split('.')[0] for x in client.application.view_functions.keys() if x.split('.')[0] != 'static'])
|
||||||
|
assert sorted(blueprint_names) == sorted(routes_blueprint_names)
|
||||||
Reference in New Issue
Block a user