Add tests for when email / sms disabled

This commit is contained in:
Ken Tsang
2017-06-26 14:18:43 +01:00
committed by venusbb
parent b04d01ba27
commit c1caa4a5da
4 changed files with 72 additions and 7 deletions

View File

@@ -16,7 +16,7 @@ from app.errors import (
InvalidRequest
)
from app.models import KEY_TYPE_TEAM, PRIORITY
from app.models import INTERNATIONAL_SMS_TYPE, SMS_TYPE
from app.models import INTERNATIONAL_SMS_TYPE, SMS_TYPE, INBOUND_SMS_TYPE, EMAIL_TYPE
from app.notifications.process_notifications import (
persist_notification,
send_notification_to_queue,
@@ -119,7 +119,11 @@ def send_notification(notification_type):
_service_allowed_to_send_to(notification_form, authenticated_service)
if notification_type == SMS_TYPE:
_service_has_permission(authenticated_service, SMS_TYPE)
_service_can_send_internationally(authenticated_service, notification_form['to'])
elif notification_type == EMAIL_TYPE:
print('email')
_service_has_permission(authenticated_service, EMAIL_TYPE)
# Do not persist or send notification to the queue if it is a simulated recipient
simulated = simulated_recipient(notification_form['to'], notification_type)
@@ -162,6 +166,22 @@ def get_notification_return_data(notification_id, notification, template):
return output
def _service_has_permission(service, notify_type):
print(service.permissions)
if notify_type not in [p.permission for p in service.permissions]:
notify_type_text = notify_type + 's'
action = 'send'
if notify_type == SMS_TYPE or notify_type == INBOUND_SMS_TYPE:
notify_type_text = 'text messages'
if notify_type == INBOUND_SMS_TYPE:
action = 'receive'
raise InvalidRequest(
{'to': ["Cannot {action} {type}".format(action=action, type=notify_type_text)]},
status_code=400
)
def _service_can_send_internationally(service, number):
international_phone_info = get_international_phone_info(number)