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.
This commit is contained in:
Rebecca Law
2016-10-25 18:04:03 +01:00
parent a5e07d8aff
commit 23a4f00e56
9 changed files with 199 additions and 1 deletions

View File

@@ -0,0 +1,14 @@
def persist_notification():
'''
persist the notification
:return:
'''
pass
def send_notificaiton_to_queue():
'''
send the notification to the queue
:return:
'''
pass

View File

@@ -0,0 +1,25 @@
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)