Celery task to send the sms verify code.

Each celery task will use it's own queue.
This commit is contained in:
Rebecca Law
2016-02-17 15:41:33 +00:00
parent d6bea65626
commit d022d036dc
7 changed files with 57 additions and 18 deletions

View File

@@ -4,7 +4,9 @@ from datetime import (datetime, timedelta)
from flask import url_for
from app.models import (VerifyCode)
from app import db
import app.celery.tasks
from app import db, encryption
from tests import create_authorization_header
@@ -247,13 +249,10 @@ def test_user_verify_password_missing_password(notify_api,
assert 'Required field missing data' in json_resp['message']['password']
@moto.mock_sqs
def test_send_user_code_for_sms(notify_api,
notify_db,
notify_db_session,
sample_sms_code,
sqs_client_conn,
mock_secret_code):
mock_secret_code,
mock_celery_send_sms_code):
"""
Tests POST endpoint '/<user_id>/code' successful sms
"""
@@ -270,20 +269,20 @@ def test_send_user_code_for_sms(notify_api,
headers=[('Content-Type', 'application/json'), auth_header])
assert resp.status_code == 204
encrpyted = encryption.encrypt({'to': sample_sms_code.user.mobile_number, 'secret_code': '11111'})
app.celery.tasks.send_sms_code.apply_async.assert_called_once_with([encrpyted], queue='sms_code')
@moto.mock_sqs
def test_send_user_code_for_sms_with_optional_to_field(notify_api,
notify_db,
notify_db_session,
sample_sms_code,
sqs_client_conn,
mock_secret_code):
mock_secret_code,
mock_celery_send_sms_code):
"""
Tests POST endpoint '/<user_id>/code' successful sms with optional to field
"""
with notify_api.test_request_context():
with notify_api.test_client() as client:
data = json.dumps({'code_type': 'sms', 'to': '+441119876757'})
auth_header = create_authorization_header(
path=url_for('user.send_user_code', user_id=sample_sms_code.user.id),
@@ -295,6 +294,8 @@ def test_send_user_code_for_sms_with_optional_to_field(notify_api,
headers=[('Content-Type', 'application/json'), auth_header])
assert resp.status_code == 204
encrpyted = encryption.encrypt({'to': '+441119876757', 'secret_code': '11111'})
app.celery.tasks.send_sms_code.apply_async.assert_called_once_with([encrpyted], queue='sms_code')
@moto.mock_sqs