mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-18 05:28:49 -04:00
celery test cleanup
* Alter config so an error will be raised if you forget to mock out a celery call in one of your tests * Remove an unneeded exception type that was masking errors
This commit is contained in:
@@ -297,6 +297,8 @@ class Test(Config):
|
||||
STATSD_HOST = "localhost"
|
||||
STATSD_PORT = 1000
|
||||
|
||||
BROKER_URL = 'you-forgot-to-mock-celery-in-your-tests://'
|
||||
|
||||
for queue in QueueNames.all_queues():
|
||||
Config.CELERY_QUEUES.append(
|
||||
Queue(queue, Exchange('default'), routing_key=queue)
|
||||
|
||||
@@ -7,7 +7,6 @@ from sqlalchemy.orm.exc import NoResultFound
|
||||
from marshmallow import ValidationError
|
||||
from jsonschema import ValidationError as JsonSchemaValidationError
|
||||
from app.authentication.auth import AuthError
|
||||
from app.notifications import SendNotificationToQueueError
|
||||
|
||||
|
||||
class InvalidRequest(Exception):
|
||||
@@ -90,11 +89,6 @@ def register_errors(blueprint):
|
||||
current_app.logger.exception(e)
|
||||
return jsonify(result='error', message="No result found"), 404
|
||||
|
||||
@blueprint.errorhandler(SendNotificationToQueueError)
|
||||
def failed_to_create_notification(e):
|
||||
current_app.logger.exception(e)
|
||||
return jsonify(result='error', message=e.message), 500
|
||||
|
||||
@blueprint.errorhandler(SQLAlchemyError)
|
||||
def db_error(e):
|
||||
current_app.logger.exception(e)
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
|
||||
|
||||
class SendNotificationToQueueError(Exception):
|
||||
status_code = 500
|
||||
|
||||
def __init__(self):
|
||||
self.message = "Failed to create the notification"
|
||||
|
||||
@@ -17,7 +17,7 @@ from app.models import SMS_TYPE, Notification, KEY_TYPE_TEST, EMAIL_TYPE, Schedu
|
||||
from app.dao.notifications_dao import (dao_create_notification,
|
||||
dao_delete_notifications_and_history_by_id,
|
||||
dao_created_scheduled_notification)
|
||||
from app.v2.errors import BadRequestError, SendNotificationToQueueError
|
||||
from app.v2.errors import BadRequestError
|
||||
from app.utils import get_template_instance, cache_key_for_service_template_counter, convert_bst_to_utc
|
||||
|
||||
|
||||
@@ -110,10 +110,9 @@ def send_notification_to_queue(notification, research_mode, queue=None):
|
||||
|
||||
try:
|
||||
deliver_task.apply_async([str(notification.id)], queue=queue)
|
||||
except Exception as e:
|
||||
current_app.logger.exception(e)
|
||||
except Exception:
|
||||
dao_delete_notifications_and_history_by_id(notification.id)
|
||||
raise SendNotificationToQueueError()
|
||||
raise
|
||||
|
||||
current_app.logger.info(
|
||||
"{} {} sent to the {} queue for delivery".format(notification.notification_type,
|
||||
|
||||
@@ -5,7 +5,6 @@ from sqlalchemy.exc import DataError
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
from app.authentication.auth import AuthError
|
||||
from app.errors import InvalidRequest
|
||||
from app.notifications import SendNotificationToQueueError
|
||||
|
||||
|
||||
class TooManyRequestsError(InvalidRequest):
|
||||
@@ -61,13 +60,6 @@ def register_errors(blueprint):
|
||||
def auth_error(error):
|
||||
return jsonify(error.to_dict_v2()), error.code
|
||||
|
||||
@blueprint.errorhandler(SendNotificationToQueueError)
|
||||
def failed_to_create_notification(error):
|
||||
current_app.logger.exception(error)
|
||||
return jsonify(
|
||||
status_code=500,
|
||||
errors=[{"error": error.__class__.__name__, "message": error.message}]), 500
|
||||
|
||||
@blueprint.errorhandler(Exception)
|
||||
def internal_server_error(error):
|
||||
current_app.logger.exception(error)
|
||||
|
||||
Reference in New Issue
Block a user