mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Building tests for the tasks class
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
from itsdangerous import URLSafeSerializer
|
||||
from app import notify_celery, twilio_client, db, encryption
|
||||
from app.clients.sms.twilio import TwilioClientException
|
||||
from app.dao.templates_dao import get_model_templates
|
||||
from app.dao.notifications_dao import save_notification
|
||||
from app.models import Notification
|
||||
from flask import current_app
|
||||
|
||||
|
||||
@notify_celery.task(name="send-sms", bind="True")
|
||||
@notify_celery.task(name="send-sms")
|
||||
def send_sms(service_id, notification_id, encrypted_notification):
|
||||
notification = encryption.decrypt(encrypted_notification)
|
||||
template = get_model_templates(notification['template'])
|
||||
@@ -14,7 +14,7 @@ def send_sms(service_id, notification_id, encrypted_notification):
|
||||
status = 'sent'
|
||||
|
||||
try:
|
||||
twilio_client.send_sms(notification, template.content)
|
||||
twilio_client.send_sms(notification['to'], template.content)
|
||||
except TwilioClientException as e:
|
||||
current_app.logger.info(e)
|
||||
status = 'failed'
|
||||
@@ -27,5 +27,4 @@ def send_sms(service_id, notification_id, encrypted_notification):
|
||||
status=status
|
||||
)
|
||||
|
||||
db.session.add(notification_db_object)
|
||||
db.session.commit()
|
||||
save_notification(notification_db_object)
|
||||
|
||||
@@ -10,7 +10,8 @@ class Encryption:
|
||||
self.salt = app.config.get('DANGEROUS_SALT')
|
||||
|
||||
def encrypt(self, thing_to_encrypt):
|
||||
return self.serializer.dumps(thing_to_encrypt, self.salt)
|
||||
return self.serializer.dumps(thing_to_encrypt, salt=
|
||||
self.salt)
|
||||
|
||||
def decrypt(self, thing_to_decrypt):
|
||||
return self.serializer.loads(thing_to_decrypt, salt=self.salt)
|
||||
|
||||
@@ -3,11 +3,9 @@ import uuid
|
||||
from flask import (
|
||||
Blueprint,
|
||||
jsonify,
|
||||
request,
|
||||
current_app
|
||||
request
|
||||
)
|
||||
|
||||
from itsdangerous import URLSafeSerializer
|
||||
from app import api_user, encryption
|
||||
from app.aws_sqs import add_notification_to_queue
|
||||
from app.dao import (templates_dao, notifications_dao)
|
||||
|
||||
Reference in New Issue
Block a user