Merge branch 'master' into write-to-postgres-not-sqs

Conflicts:
	app/notifications/rest.py
	tests/app/notifications/rest/test_send_notification.py
This commit is contained in:
Martyn Inglis
2016-09-08 09:15:07 +01:00
3 changed files with 40 additions and 30 deletions

View File

@@ -45,7 +45,6 @@ from app.errors import (
register_errors,
InvalidRequest
)
from app.celery.provider_tasks import send_sms_to_provider, send_email_to_provider
register_errors(notifications)
from app.celery.provider_tasks import send_sms_to_provider, send_email_to_provider
@@ -195,16 +194,16 @@ def send_notification(notification_type):
service_id = str(api_user.service_id)
service = services_dao.dao_fetch_service_by_id(service_id)
service_stats = sum(row.count for row in dao_fetch_todays_stats_for_service(service.id))
if all((api_user.key_type != KEY_TYPE_TEST, service_stats >= service.message_limit)):
error = 'Exceeded send limits ({}) for today'.format(service.message_limit)
raise InvalidRequest(error, status_code=429)
notification, errors = (
sms_template_notification_schema if notification_type == SMS_TYPE else email_notification_schema
).load(request.get_json())
if all((api_user.key_type != KEY_TYPE_TEST, service.restricted)):
service_stats = sum(row.count for row in dao_fetch_todays_stats_for_service(service.id))
if service_stats >= service.message_limit:
error = 'Exceeded send limits ({}) for today'.format(service.message_limit)
raise InvalidRequest(error, status_code=429)
if errors:
raise InvalidRequest(errors, status_code=400)
@@ -233,8 +232,8 @@ def send_notification(notification_type):
raise InvalidRequest(errors, status_code=400)
if (
template_object.template_type == SMS_TYPE and
template_object.replaced_content_count > current_app.config.get('SMS_CHAR_COUNT_LIMIT')
template_object.template_type == SMS_TYPE and
template_object.replaced_content_count > current_app.config.get('SMS_CHAR_COUNT_LIMIT')
):
char_count = current_app.config.get('SMS_CHAR_COUNT_LIMIT')
message = 'Content has a character count greater than the limit of {}'.format(char_count)