mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-21 23:06:10 -04:00
Compare commits
14 Commits
jaeger
...
optimise-f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d84d4e056b | ||
|
|
132e75f99f | ||
|
|
eec2c2859e | ||
|
|
58ab99d74b | ||
|
|
4c230a7235 | ||
|
|
8b4a424df1 | ||
|
|
15ce9fe3f9 | ||
|
|
d9b3b31a6a | ||
|
|
cd9b80f415 | ||
|
|
faa8faa0c4 | ||
|
|
c4dc0f64c5 | ||
|
|
6e32ca5996 | ||
|
|
4bb37a05ec | ||
|
|
bd433ad24f |
@@ -1,19 +1,23 @@
|
||||
import time
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
import uuid
|
||||
|
||||
from flask import _request_ctx_stack, request, g, jsonify, make_response
|
||||
from celery import current_task
|
||||
from flask import _request_ctx_stack, request, g, jsonify, make_response, current_app, has_request_context
|
||||
from flask_sqlalchemy import SQLAlchemy as _SQLAlchemy
|
||||
from flask_marshmallow import Marshmallow
|
||||
from flask_migrate import Migrate
|
||||
from gds_metrics import GDSMetrics
|
||||
from gds_metrics.metrics import Gauge, Histogram
|
||||
from time import monotonic
|
||||
from notifications_utils.clients.zendesk.zendesk_client import ZendeskClient
|
||||
from notifications_utils.clients.statsd.statsd_client import StatsdClient
|
||||
from notifications_utils.clients.redis.redis_client import RedisClient
|
||||
from notifications_utils.clients.encryption.encryption_client import Encryption
|
||||
from notifications_utils import logging, request_helper
|
||||
from sqlalchemy import event
|
||||
from werkzeug.exceptions import HTTPException as WerkzeugHTTPException
|
||||
from werkzeug.local import LocalProxy
|
||||
|
||||
@@ -64,6 +68,11 @@ clients = Clients()
|
||||
api_user = LocalProxy(lambda: _request_ctx_stack.top.api_user)
|
||||
authenticated_service = LocalProxy(lambda: _request_ctx_stack.top.authenticated_service)
|
||||
|
||||
CONCURRENT_REQUESTS = Gauge(
|
||||
'concurrent_web_request_count',
|
||||
'How many concurrent requests are currently being served',
|
||||
)
|
||||
|
||||
|
||||
def create_app(application):
|
||||
from app.config import configs
|
||||
@@ -108,6 +117,9 @@ def create_app(application):
|
||||
from app.commands import setup_commands
|
||||
setup_commands(application)
|
||||
|
||||
# set up sqlalchemy events
|
||||
setup_sqlalchemy_events(application)
|
||||
|
||||
return application
|
||||
|
||||
|
||||
@@ -255,17 +267,22 @@ def register_v2_blueprints(application):
|
||||
|
||||
|
||||
def init_app(app):
|
||||
|
||||
@app.before_request
|
||||
def record_user_agent():
|
||||
statsd_client.incr("user-agent.{}".format(process_user_agent(request.headers.get('User-Agent', None))))
|
||||
|
||||
@app.before_request
|
||||
def record_request_details():
|
||||
CONCURRENT_REQUESTS.inc()
|
||||
|
||||
g.start = monotonic()
|
||||
g.endpoint = request.endpoint
|
||||
|
||||
@app.after_request
|
||||
def after_request(response):
|
||||
CONCURRENT_REQUESTS.dec()
|
||||
|
||||
response.headers.add('Access-Control-Allow-Origin', '*')
|
||||
response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
|
||||
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
|
||||
@@ -311,3 +328,83 @@ def process_user_agent(user_agent_string):
|
||||
return "non-notify-user-agent"
|
||||
else:
|
||||
return "unknown"
|
||||
|
||||
|
||||
def setup_sqlalchemy_events(app):
|
||||
|
||||
TOTAL_DB_CONNECTIONS = Gauge(
|
||||
'db_connection_total_connected',
|
||||
'How many db connections are currently held (potentially idle) by the server',
|
||||
)
|
||||
|
||||
TOTAL_CHECKED_OUT_DB_CONNECTIONS = Gauge(
|
||||
'db_connection_total_checked_out',
|
||||
'How many db connections are currently checked out by web requests',
|
||||
)
|
||||
|
||||
DB_CONNECTION_OPEN_DURATION_SECONDS = Histogram(
|
||||
'db_connection_open_duration_seconds',
|
||||
'How long db connections are held open for in seconds',
|
||||
['method', 'host', 'path']
|
||||
)
|
||||
|
||||
# need this or db.engine isn't accessible
|
||||
with app.app_context():
|
||||
@event.listens_for(db.engine, 'connect')
|
||||
def connect(dbapi_connection, connection_record):
|
||||
# connection first opened with db
|
||||
TOTAL_DB_CONNECTIONS.inc()
|
||||
|
||||
@event.listens_for(db.engine, 'close')
|
||||
def close(dbapi_connection, connection_record):
|
||||
# connection closed (probably only happens with overflow connections)
|
||||
TOTAL_DB_CONNECTIONS.dec()
|
||||
|
||||
@event.listens_for(db.engine, 'checkout')
|
||||
def checkout(dbapi_connection, connection_record, connection_proxy):
|
||||
# connection given to a web worker
|
||||
TOTAL_CHECKED_OUT_DB_CONNECTIONS.inc()
|
||||
|
||||
# this will overwrite any previous checkout_at timestamp
|
||||
connection_record.info['checkout_at'] = time.monotonic()
|
||||
|
||||
# checkin runs after the request is already torn down, therefore we add the request_data onto the
|
||||
# connection_record as otherwise it won't have that information when checkin actually runs.
|
||||
# Note: this is not a problem for checkouts as the checkout always happens within a web request or task
|
||||
|
||||
# web requests
|
||||
if has_request_context():
|
||||
connection_record.info['request_data'] = {
|
||||
'method': request.method,
|
||||
'host': request.host,
|
||||
'url_rule': request.url_rule.rule if request.url_rule else 'No endpoint'
|
||||
}
|
||||
# celery apps
|
||||
elif current_task:
|
||||
connection_record.info['request_data'] = {
|
||||
'method': 'celery',
|
||||
'host': current_app.config['NOTIFY_APP_NAME'], # worker name
|
||||
'url_rule': current_task.name, # task name
|
||||
}
|
||||
# anything else. migrations possibly.
|
||||
else:
|
||||
current_app.logger.warning('Checked out sqlalchemy connection from outside of request/task')
|
||||
connection_record.info['request_data'] = {
|
||||
'method': 'unknown',
|
||||
'host': 'unknown',
|
||||
'url_rule': 'unknown',
|
||||
}
|
||||
|
||||
@event.listens_for(db.engine, 'checkin')
|
||||
def checkin(dbapi_connection, connection_record):
|
||||
# connection returned by a web worker
|
||||
TOTAL_CHECKED_OUT_DB_CONNECTIONS.dec()
|
||||
|
||||
# duration that connection was held by a single web request
|
||||
duration = time.monotonic() - connection_record.info['checkout_at']
|
||||
|
||||
DB_CONNECTION_OPEN_DURATION_SECONDS.labels(
|
||||
connection_record.info['request_data']['method'],
|
||||
connection_record.info['request_data']['host'],
|
||||
connection_record.info['request_data']['url_rule']
|
||||
).observe(duration)
|
||||
|
||||
@@ -6,12 +6,18 @@ from notifications_python_client.errors import (
|
||||
from notifications_utils import request_helper
|
||||
from sqlalchemy.exc import DataError
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
from gds_metrics import Histogram
|
||||
|
||||
from app.dao.services_dao import dao_fetch_service_by_id_with_api_keys
|
||||
|
||||
|
||||
GENERAL_TOKEN_ERROR_MESSAGE = 'Invalid token: make sure your API token matches the example at https://docs.notifications.service.gov.uk/rest-api.html#authorisation-header' # noqa
|
||||
|
||||
AUTH_DB_CONNECTION_DURATION_SECONDS = Histogram(
|
||||
'auth_db_connection_duration_seconds',
|
||||
'Time taken to get DB connection and fetch service from database',
|
||||
)
|
||||
|
||||
|
||||
class AuthError(Exception):
|
||||
def __init__(self, message, code, service_id=None, api_key_id=None):
|
||||
@@ -87,7 +93,8 @@ def requires_auth():
|
||||
issuer = __get_token_issuer(auth_token) # ie the `iss` claim which should be a service ID
|
||||
|
||||
try:
|
||||
service = dao_fetch_service_by_id_with_api_keys(issuer)
|
||||
with AUTH_DB_CONNECTION_DURATION_SECONDS.time():
|
||||
service = dao_fetch_service_by_id_with_api_keys(issuer)
|
||||
except DataError:
|
||||
raise AuthError("Invalid token: service id is not the right data type", 403)
|
||||
except NoResultFound:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import time
|
||||
|
||||
from gds_metrics.metrics import Histogram
|
||||
from celery import Celery, Task
|
||||
from celery.signals import worker_process_shutdown
|
||||
from flask import g, request
|
||||
@@ -19,6 +20,12 @@ def log_on_worker_shutdown(sender, signal, pid, exitcode, **kwargs):
|
||||
|
||||
|
||||
def make_task(app):
|
||||
SQS_APPLY_ASYNC_DURATION_SECONDS = Histogram(
|
||||
'sqs_apply_async_duration_seconds',
|
||||
'Time taken to put task on queue',
|
||||
['task_name']
|
||||
)
|
||||
|
||||
class NotifyTask(Task):
|
||||
abstract = True
|
||||
start = None
|
||||
@@ -52,7 +59,8 @@ def make_task(app):
|
||||
if has_request_context() and hasattr(request, 'request_id'):
|
||||
kwargs['request_id'] = request.request_id
|
||||
|
||||
return super().apply_async(args, kwargs, task_id, producer, link, link_error, **options)
|
||||
with SQS_APPLY_ASYNC_DURATION_SECONDS.labels(self.name).time():
|
||||
return super().apply_async(args, kwargs, task_id, producer, link, link_error, **options)
|
||||
|
||||
return NotifyTask
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ from app.models import (
|
||||
NOTIFICATION_TECHNICAL_FAILURE,
|
||||
NOTIFICATION_VALIDATION_FAILED,
|
||||
NOTIFICATION_VIRUS_SCAN_FAILED,
|
||||
LETTER_TYPE
|
||||
)
|
||||
from app.cronitor import cronitor
|
||||
|
||||
@@ -216,7 +217,7 @@ def group_letters(letter_pdfs):
|
||||
def sanitise_letter(self, filename):
|
||||
try:
|
||||
reference = get_reference_from_filename(filename)
|
||||
notification = dao_get_notification_by_reference(reference)
|
||||
notification = dao_get_notification_by_reference(reference=reference, notification_type=LETTER_TYPE)
|
||||
|
||||
current_app.logger.info('Notification ID {} Virus scan passed: {}'.format(notification.id, filename))
|
||||
|
||||
@@ -352,7 +353,7 @@ def _move_invalid_letter_and_update_status(
|
||||
def process_virus_scan_failed(filename):
|
||||
move_failed_pdf(filename, ScanErrorType.FAILURE)
|
||||
reference = get_reference_from_filename(filename)
|
||||
notification = dao_get_notification_by_reference(reference)
|
||||
notification = dao_get_notification_by_reference(reference=reference, notification_type=LETTER_TYPE)
|
||||
updated_count = update_letter_pdf_status(reference, NOTIFICATION_VIRUS_SCAN_FAILED, billable_units=0)
|
||||
|
||||
if updated_count != 1:
|
||||
@@ -371,7 +372,7 @@ def process_virus_scan_failed(filename):
|
||||
def process_virus_scan_error(filename):
|
||||
move_failed_pdf(filename, ScanErrorType.ERROR)
|
||||
reference = get_reference_from_filename(filename)
|
||||
notification = dao_get_notification_by_reference(reference)
|
||||
notification = dao_get_notification_by_reference(reference=reference, notification_type=LETTER_TYPE)
|
||||
updated_count = update_letter_pdf_status(reference, NOTIFICATION_TECHNICAL_FAILURE, billable_units=0)
|
||||
|
||||
if updated_count != 1:
|
||||
|
||||
@@ -10,7 +10,7 @@ from app import notify_celery, statsd_client
|
||||
from app.config import QueueNames
|
||||
from app.clients.email.aws_ses import get_aws_responses
|
||||
from app.dao import notifications_dao
|
||||
from app.models import NOTIFICATION_SENDING, NOTIFICATION_PENDING
|
||||
from app.models import NOTIFICATION_SENDING, NOTIFICATION_PENDING, EMAIL_TYPE
|
||||
|
||||
from app.notifications.notifications_ses_callback import (
|
||||
determine_notification_bounce_type,
|
||||
@@ -39,7 +39,9 @@ def process_ses_results(self, response):
|
||||
reference = ses_message['mail']['messageId']
|
||||
|
||||
try:
|
||||
notification = notifications_dao.dao_get_notification_or_history_by_reference(reference=reference)
|
||||
notification = notifications_dao.dao_get_notification_or_history_by_reference(
|
||||
reference=reference, notification_type=EMAIL_TYPE
|
||||
)
|
||||
except NoResultFound:
|
||||
message_time = iso8601.parse_date(ses_message['mail']['timestamp']).replace(tzinfo=None)
|
||||
if datetime.utcnow() - message_time < timedelta(minutes=5):
|
||||
|
||||
@@ -536,7 +536,7 @@ def update_letter_notification(filename, temporary_failures, update):
|
||||
|
||||
|
||||
def check_billable_units(notification_update):
|
||||
notification = dao_get_notification_or_history_by_reference(notification_update.reference)
|
||||
notification = dao_get_notification_or_history_by_reference(notification_update.reference, LETTER_TYPE)
|
||||
|
||||
if int(notification_update.page_count) != notification.billable_units:
|
||||
msg = 'Notification with id {} has {} billable_units but DVLA says page count is {}'.format(
|
||||
|
||||
@@ -650,33 +650,29 @@ def dao_get_notifications_by_recipient_or_reference(
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def dao_get_notification_by_reference(reference):
|
||||
def dao_get_notification_by_reference(reference, notification_type):
|
||||
return Notification.query.filter(
|
||||
Notification.reference == reference
|
||||
Notification.reference == reference,
|
||||
Notification.notification_type == notification_type
|
||||
).one()
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def dao_get_notification_or_history_by_reference(reference):
|
||||
def dao_get_notification_or_history_by_reference(reference, notification_type):
|
||||
try:
|
||||
# This try except is necessary because in test keys and research mode does not create notification history.
|
||||
# Otherwise we could just search for the NotificationHistory object
|
||||
return Notification.query.filter(
|
||||
Notification.reference == reference
|
||||
Notification.reference == reference,
|
||||
Notification.notification_type == notification_type
|
||||
).one()
|
||||
except NoResultFound:
|
||||
return NotificationHistory.query.filter(
|
||||
NotificationHistory.reference == reference
|
||||
NotificationHistory.reference == reference,
|
||||
NotificationHistory.notification_type == notification_type
|
||||
).one()
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def dao_get_notifications_by_references(references):
|
||||
return Notification.query.filter(
|
||||
Notification.reference.in_(references)
|
||||
).all()
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def dao_created_scheduled_notification(scheduled_notification):
|
||||
db.session.add(scheduled_notification)
|
||||
|
||||
@@ -72,8 +72,8 @@ def send_sms_to_provider(notification):
|
||||
notification.billable_units = template.fragment_count
|
||||
update_notification_to_sending(notification, provider)
|
||||
|
||||
delta_milliseconds = (datetime.utcnow() - notification.created_at).total_seconds() * 1000
|
||||
statsd_client.timing("sms.total-time", delta_milliseconds)
|
||||
delta_seconds = (datetime.utcnow() - notification.created_at).total_seconds()
|
||||
statsd_client.timing("sms.total-time", delta_seconds)
|
||||
|
||||
|
||||
def send_email_to_provider(notification):
|
||||
@@ -118,8 +118,8 @@ def send_email_to_provider(notification):
|
||||
notification.reference = reference
|
||||
update_notification_to_sending(notification, provider)
|
||||
|
||||
delta_milliseconds = (datetime.utcnow() - notification.created_at).total_seconds() * 1000
|
||||
statsd_client.timing("email.total-time", delta_milliseconds)
|
||||
delta_seconds = (datetime.utcnow() - notification.created_at).total_seconds()
|
||||
statsd_client.timing("email.total-time", delta_seconds)
|
||||
|
||||
|
||||
def update_notification_to_sending(notification, provider):
|
||||
|
||||
@@ -5,7 +5,7 @@ from app.dao.notifications_dao import dao_get_notification_or_history_by_referen
|
||||
from app.dao.service_callback_api_dao import (
|
||||
get_service_delivery_status_callback_api_for_service, get_service_complaint_callback_api_for_service
|
||||
)
|
||||
from app.models import Complaint
|
||||
from app.models import Complaint, EMAIL_TYPE
|
||||
from app.celery.service_callback_tasks import (
|
||||
send_delivery_status_to_service,
|
||||
send_complaint_to_service,
|
||||
@@ -33,7 +33,7 @@ def handle_complaint(ses_message):
|
||||
except KeyError as e:
|
||||
current_app.logger.exception("Complaint from SES failed to get reference from message", e)
|
||||
return
|
||||
notification = dao_get_notification_or_history_by_reference(reference)
|
||||
notification = dao_get_notification_or_history_by_reference(reference, EMAIL_TYPE)
|
||||
ses_complaint = ses_message.get('complaint', None)
|
||||
|
||||
complaint = Complaint(
|
||||
|
||||
@@ -34,6 +34,15 @@ from app.dao.notifications_dao import (
|
||||
from app.v2.errors import BadRequestError
|
||||
|
||||
|
||||
from gds_metrics import Histogram
|
||||
|
||||
|
||||
REDIS_GET_AND_INCR_DAILY_LIMIT_DURATION_SECONDS = Histogram(
|
||||
'redis_get_and_incr_daily_limit_duration_seconds',
|
||||
'Time taken to get and possibly incremement the daily limit cache key',
|
||||
)
|
||||
|
||||
|
||||
def create_content_for_notification(template, personalisation):
|
||||
template_object = template._as_utils_template_with_personalisation(personalisation)
|
||||
check_placeholders(template_object)
|
||||
@@ -115,8 +124,9 @@ def persist_notification(
|
||||
if not simulated:
|
||||
dao_create_notification(notification)
|
||||
if key_type != KEY_TYPE_TEST:
|
||||
if redis_store.get(redis.daily_limit_cache_key(service.id)):
|
||||
redis_store.incr(redis.daily_limit_cache_key(service.id))
|
||||
with REDIS_GET_AND_INCR_DAILY_LIMIT_DURATION_SECONDS.time():
|
||||
if redis_store.get(redis.daily_limit_cache_key(service.id)):
|
||||
redis_store.incr(redis.daily_limit_cache_key(service.id))
|
||||
|
||||
current_app.logger.info(
|
||||
"{} {} created at {}".format(notification_type, notification_id, notification_created_at)
|
||||
|
||||
@@ -22,15 +22,24 @@ from app.utils import get_public_notify_type_text
|
||||
from app.dao.service_email_reply_to_dao import dao_get_reply_to_by_id
|
||||
from app.dao.service_letter_contact_dao import dao_get_letter_contact_by_id
|
||||
|
||||
from gds_metrics.metrics import Histogram
|
||||
|
||||
|
||||
REDIS_EXCEEDED_RATE_LIMIT_DURATION_SECONDS = Histogram(
|
||||
'redis_exceeded_rate_limit_duration_seconds',
|
||||
'Time taken to check rate limit',
|
||||
)
|
||||
|
||||
|
||||
def check_service_over_api_rate_limit(service, api_key):
|
||||
if current_app.config['API_RATE_LIMIT_ENABLED'] and current_app.config['REDIS_ENABLED']:
|
||||
cache_key = rate_limit_cache_key(service.id, api_key.key_type)
|
||||
rate_limit = service.rate_limit
|
||||
interval = 60
|
||||
if redis_store.exceeded_rate_limit(cache_key, rate_limit, interval):
|
||||
current_app.logger.info("service {} has been rate limited for throughput".format(service.id))
|
||||
raise RateLimitError(rate_limit, interval, api_key.key_type)
|
||||
with REDIS_EXCEEDED_RATE_LIMIT_DURATION_SECONDS.time():
|
||||
if redis_store.exceeded_rate_limit(cache_key, rate_limit, interval):
|
||||
current_app.logger.info("service {} has been rate limited for throughput".format(service.id))
|
||||
raise RateLimitError(rate_limit, interval, api_key.key_type)
|
||||
|
||||
|
||||
def check_service_over_daily_message_limit(key_type, service):
|
||||
|
||||
@@ -7,6 +7,7 @@ from boto.exception import SQSError
|
||||
from flask import request, jsonify, current_app, abort
|
||||
from notifications_utils.postal_address import PostalAddress
|
||||
from notifications_utils.recipients import try_validate_and_format_phone_number
|
||||
from gds_metrics import Histogram
|
||||
|
||||
from app import (
|
||||
api_user,
|
||||
@@ -74,6 +75,12 @@ from app.v2.notifications.notification_schemas import (
|
||||
from app.v2.utils import get_valid_json
|
||||
|
||||
|
||||
POST_NOTIFICATION_JSON_PARSE_DURATION_SECONDS = Histogram(
|
||||
'post_notification_json_parse_duration_seconds',
|
||||
'Time taken to parse and validate post request json',
|
||||
)
|
||||
|
||||
|
||||
@v2_notification_blueprint.route('/{}'.format(LETTER_TYPE), methods=['POST'])
|
||||
def post_precompiled_letter_notification():
|
||||
request_json = get_valid_json()
|
||||
@@ -116,16 +123,17 @@ def post_precompiled_letter_notification():
|
||||
|
||||
@v2_notification_blueprint.route('/<notification_type>', methods=['POST'])
|
||||
def post_notification(notification_type):
|
||||
request_json = get_valid_json()
|
||||
with POST_NOTIFICATION_JSON_PARSE_DURATION_SECONDS.time():
|
||||
request_json = get_valid_json()
|
||||
|
||||
if notification_type == EMAIL_TYPE:
|
||||
form = validate(request_json, post_email_request)
|
||||
elif notification_type == SMS_TYPE:
|
||||
form = validate(request_json, post_sms_request)
|
||||
elif notification_type == LETTER_TYPE:
|
||||
form = validate(request_json, post_letter_request)
|
||||
else:
|
||||
abort(404)
|
||||
if notification_type == EMAIL_TYPE:
|
||||
form = validate(request_json, post_email_request)
|
||||
elif notification_type == SMS_TYPE:
|
||||
form = validate(request_json, post_sms_request)
|
||||
elif notification_type == LETTER_TYPE:
|
||||
form = validate(request_json, post_letter_request)
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
check_service_has_permission(notification_type, authenticated_service.permissions)
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ notifications-python-client==5.5.1
|
||||
# PaaS
|
||||
awscli-cwlogs>=1.4,<1.5
|
||||
|
||||
git+https://github.com/alphagov/notifications-utils.git@39.4.3#egg=notifications-utils==39.4.3
|
||||
git+https://github.com/alphagov/notifications-utils.git@39.4.4#egg=notifications-utils==39.4.4
|
||||
|
||||
# gds-metrics requires prometheseus 0.2.0, override that requirement as 0.7.1 brings significant performance gains
|
||||
prometheus-client==0.7.1
|
||||
gds-metrics==0.2.0
|
||||
|
||||
@@ -28,8 +28,10 @@ notifications-python-client==5.5.1
|
||||
# PaaS
|
||||
awscli-cwlogs>=1.4,<1.5
|
||||
|
||||
git+https://github.com/alphagov/notifications-utils.git@39.4.3#egg=notifications-utils==39.4.3
|
||||
git+https://github.com/alphagov/notifications-utils.git@39.4.4#egg=notifications-utils==39.4.4
|
||||
|
||||
# gds-metrics requires prometheseus 0.2.0, override that requirement as 0.7.1 brings significant performance gains
|
||||
prometheus-client==0.7.1
|
||||
gds-metrics==0.2.0
|
||||
|
||||
## The following requirements were added by pip freeze:
|
||||
@@ -66,7 +68,6 @@ mistune==0.8.4
|
||||
monotonic==1.5
|
||||
orderedset==2.0.1
|
||||
phonenumbers==8.11.2
|
||||
prometheus-client==0.2.0
|
||||
pyasn1==0.4.8
|
||||
pycparser==2.20
|
||||
PyPDF2==1.26.0
|
||||
|
||||
@@ -28,7 +28,6 @@ from app.dao.notifications_dao import (
|
||||
update_notification_status_by_id,
|
||||
update_notification_status_by_reference,
|
||||
dao_get_notification_by_reference,
|
||||
dao_get_notifications_by_references,
|
||||
dao_get_notification_or_history_by_reference,
|
||||
notifications_not_yet_sent,
|
||||
)
|
||||
@@ -1613,7 +1612,7 @@ def test_dao_update_notifications_by_reference_updates_history_when_one_of_two_n
|
||||
|
||||
def test_dao_get_notification_by_reference_with_one_match_returns_notification(sample_letter_template, notify_db):
|
||||
create_notification(template=sample_letter_template, reference='REF1')
|
||||
notification = dao_get_notification_by_reference('REF1')
|
||||
notification = dao_get_notification_by_reference('REF1', 'letter')
|
||||
|
||||
assert notification.reference == 'REF1'
|
||||
|
||||
@@ -1623,30 +1622,25 @@ def test_dao_get_notification_by_reference_with_multiple_matches_raises_error(sa
|
||||
create_notification(template=sample_letter_template, reference='REF1')
|
||||
|
||||
with pytest.raises(SQLAlchemyError):
|
||||
dao_get_notification_by_reference('REF1')
|
||||
dao_get_notification_by_reference('REF1', 'letter')
|
||||
|
||||
|
||||
def test_dao_get_notification_by_reference_with_no_matches_raises_error(notify_db):
|
||||
with pytest.raises(SQLAlchemyError):
|
||||
dao_get_notification_by_reference('REF1')
|
||||
dao_get_notification_by_reference('REF1', 'email')
|
||||
|
||||
|
||||
def test_dao_get_notifications_by_references(sample_template):
|
||||
create_notification(template=sample_template, reference='noref')
|
||||
notification_1 = create_notification(template=sample_template, reference='ref')
|
||||
notification_2 = create_notification(template=sample_template, reference='ref')
|
||||
|
||||
notifications = dao_get_notifications_by_references(['ref'])
|
||||
assert len(notifications) == 2
|
||||
assert notifications[0].id in [notification_1.id, notification_2.id]
|
||||
assert notifications[1].id in [notification_1.id, notification_2.id]
|
||||
def test_dao_get_notification_by_reference_with_no_matches_for_type_raises_error(sample_email_template):
|
||||
create_notification(template=sample_email_template, reference='REF1')
|
||||
with pytest.raises(SQLAlchemyError):
|
||||
dao_get_notification_by_reference('REF1', 'letter')
|
||||
|
||||
|
||||
def test_dao_get_notification_or_history_by_reference_with_one_match_returns_notification(
|
||||
sample_letter_template
|
||||
):
|
||||
create_notification(template=sample_letter_template, reference='REF1')
|
||||
notification = dao_get_notification_or_history_by_reference('REF1')
|
||||
notification = dao_get_notification_or_history_by_reference('REF1', 'letter')
|
||||
|
||||
assert notification.reference == 'REF1'
|
||||
|
||||
@@ -1658,12 +1652,18 @@ def test_dao_get_notification_or_history_by_reference_with_multiple_matches_rais
|
||||
create_notification(template=sample_letter_template, reference='REF1')
|
||||
|
||||
with pytest.raises(SQLAlchemyError):
|
||||
dao_get_notification_or_history_by_reference('REF1')
|
||||
dao_get_notification_or_history_by_reference('REF1', 'letter')
|
||||
|
||||
|
||||
def test_dao_get_notification_or_history_by_reference_with_no_matches_raises_error(notify_db):
|
||||
def test_dao_get_notification_or_history_by_reference_with_no_matches_raises_error(sample_letter_template):
|
||||
create_notification(template=sample_letter_template, reference='REF1')
|
||||
with pytest.raises(SQLAlchemyError):
|
||||
dao_get_notification_or_history_by_reference('REF1')
|
||||
dao_get_notification_or_history_by_reference('REF1', 'email')
|
||||
|
||||
|
||||
def test_dao_get_notification_or_history_by_reference_with_no_matches_for_type_raises_error(notify_db):
|
||||
with pytest.raises(SQLAlchemyError):
|
||||
dao_get_notification_or_history_by_reference('REF1', 'email')
|
||||
|
||||
|
||||
@pytest.mark.parametrize("notification_type",
|
||||
|
||||
@@ -4,7 +4,7 @@ from sqlalchemy.exc import DataError
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def app_for_test(mocker):
|
||||
def app_for_test():
|
||||
import flask
|
||||
from flask import Blueprint
|
||||
from app.authentication.auth import AuthError
|
||||
|
||||
Reference in New Issue
Block a user