Files
notifications-api/app/notifications/validators.py
Rebecca Law 23a4f00e56 New package structure for the version 2 of the public api.
Start building up the validators required for post notificaiton.
The app/v2/errors.py is a rough sketch, will be passed a code, the error can look up the message and link for the error message.
2016-10-25 18:04:03 +01:00

26 lines
1.0 KiB
Python

from app.dao import services_dao
from app.errors import InvalidRequest
from app.models import KEY_TYPE_TEST
def check_service_message_limit(key_type, service):
if all((key_type != KEY_TYPE_TEST,
service.restricted)):
service_stats = services_dao.fetch_todays_total_message_count(service.id)
if service_stats >= service.message_limit:
error = 'Exceeded send limits ({}) for today'.format(service.message_limit)
raise InvalidRequest(error, status_code=429)
def check_template_is_for_notification_type(notification_type, template_type):
if notification_type != template_type:
raise InvalidRequest("{0} template is not suitable for {1} notification".format(template_type,
notification_type),
status_code=400)
def check_template_is_active(template):
if template.archived:
raise InvalidRequest('Template has been deleted', status_code=400)