mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 06:21:50 -05:00
Merge pull request #121 from alphagov/revert-queue-config
Revert queue config
This commit is contained in:
@@ -152,38 +152,6 @@ def send_user_email_code(user_id):
|
||||
return jsonify({}), 204
|
||||
|
||||
|
||||
# TODO: Remove this method once the admin app has stopped using it.
|
||||
@user.route('/<int:user_id>/code', methods=['POST'])
|
||||
def send_user_code(user_id):
|
||||
user_to_send_to = get_model_users(user_id=user_id)
|
||||
|
||||
if not user_to_send_to:
|
||||
return jsonify(result="error", message="not found"), 404
|
||||
|
||||
verify_code, errors = old_request_verify_code_schema.load(request.get_json())
|
||||
if errors:
|
||||
return jsonify(result="error", message=errors), 400
|
||||
|
||||
from app.dao.users_dao import create_secret_code
|
||||
secret_code = create_secret_code()
|
||||
create_user_code(user_to_send_to, secret_code, verify_code.get('code_type'))
|
||||
if verify_code.get('code_type') == 'sms':
|
||||
mobile = user_to_send_to.mobile_number if verify_code.get('to', None) is None else verify_code.get('to')
|
||||
verification_message = {'to': mobile, 'secret_code': secret_code}
|
||||
send_sms_code.apply_async([encryption.encrypt(verification_message)], queue='sms-code')
|
||||
elif verify_code.get('code_type') == 'email':
|
||||
email = user_to_send_to.email_address if verify_code.get('to', None) is None else verify_code.get('to')
|
||||
verification_message = {
|
||||
'to_address': email,
|
||||
'from_address': current_app.config['VERIFY_CODE_FROM_EMAIL_ADDRESS'],
|
||||
'subject': 'Verification code',
|
||||
'body': secret_code}
|
||||
send_email_code.apply_async([encryption.encrypt(verification_message)], queue='email-code')
|
||||
else:
|
||||
abort(500)
|
||||
return jsonify({}), 204
|
||||
|
||||
|
||||
@user.route('/<int:user_id>', methods=['GET'])
|
||||
@user.route('', methods=['GET'])
|
||||
def get_user(user_id=None):
|
||||
|
||||
10
config.py
10
config.py
@@ -49,16 +49,6 @@ class Config(object):
|
||||
TWILIO_NUMBER = os.getenv('TWILIO_NUMBER')
|
||||
FIRETEXT_NUMBER = os.getenv('FIRETEXT_NUMBER')
|
||||
FIRETEXT_API_KEY = os.getenv("FIRETEXT_API_KEY")
|
||||
CELERY_QUEUES = [
|
||||
Queue('sms', Exchange('default'), routing_key='default'),
|
||||
Queue('email', Exchange('default'), routing_key='default'),
|
||||
Queue('sms-code', Exchange('default'), routing_key='default'),
|
||||
Queue('email-code', Exchange('default'), routing_key='default'),
|
||||
Queue('process-job', Exchange('default'), routing_key='default'),
|
||||
Queue('bulk-sms', Exchange('default'), routing_key='default'),
|
||||
Queue('bulk-email', Exchange('default'), routing_key='default'),
|
||||
Queue('email-invited-user', Exchange('default'), routing_key='default')
|
||||
]
|
||||
|
||||
|
||||
class Development(Config):
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
set -e
|
||||
|
||||
source environment.sh
|
||||
celery -A run_celery.notify_celery worker --loglevel=INFO --concurrency=4
|
||||
celery -A run_celery.notify_celery worker --loglevel=INFO --concurrency=4 -Q sms,sms-code,email-code,email,process-job,bulk-sms,bulk-email,email-invited-user
|
||||
|
||||
@@ -246,100 +246,6 @@ def test_user_verify_password_missing_password(notify_api,
|
||||
assert 'Required field missing data' in json_resp['message']['password']
|
||||
|
||||
|
||||
# TODO: Remove this test once the admin app has stopped using it.
|
||||
def test_send_user_code_for_sms(notify_api,
|
||||
sample_sms_code,
|
||||
mock_encryption,
|
||||
mock_celery_send_sms_code):
|
||||
"""
|
||||
Tests POST endpoint '/<user_id>/code' successful sms
|
||||
"""
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
data = json.dumps({'code_type': 'sms'})
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.send_user_code', user_id=sample_sms_code.user.id),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
resp = client.post(
|
||||
url_for('user.send_user_code', user_id=sample_sms_code.user.id),
|
||||
data=data,
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
|
||||
assert resp.status_code == 204
|
||||
app.celery.tasks.send_sms_code.apply_async.assert_called_once_with(['something_encrypted'],
|
||||
queue='sms-code')
|
||||
|
||||
|
||||
# TODO: Remove this test once the admin app has stopped using it.
|
||||
def test_send_user_code_for_email(notify_api,
|
||||
sample_email_code,
|
||||
mock_secret_code,
|
||||
mock_celery_send_email_code,
|
||||
mock_encryption):
|
||||
"""
|
||||
Tests POST endpoint '/<user_id>/code' successful email
|
||||
"""
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
data = json.dumps({'code_type': 'email'})
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.send_user_code', user_id=sample_email_code.user.id),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
resp = client.post(
|
||||
url_for('user.send_user_code', user_id=sample_email_code.user.id),
|
||||
data=data,
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
assert resp.status_code == 204
|
||||
|
||||
app.celery.tasks.send_email_code.apply_async.assert_called_once_with(['something_encrypted'],
|
||||
queue='email-code')
|
||||
|
||||
|
||||
# TODO: Remove this test once the admin app has stopped using it.
|
||||
def test_send_user_code_for_email_uses_optional_to_field(notify_api,
|
||||
sample_email_code,
|
||||
mock_secret_code,
|
||||
mock_celery_send_email_code,
|
||||
mock_encryption):
|
||||
"""
|
||||
Tests POST endpoint '/<user_id>/code' successful email with included in body
|
||||
"""
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
data = json.dumps({'code_type': 'email', 'to': 'different@email.gov.uk'})
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.send_user_code', user_id=sample_email_code.user.id),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
resp = client.post(
|
||||
url_for('user.send_user_code', user_id=sample_email_code.user.id),
|
||||
data=data,
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
assert resp.status_code == 204
|
||||
|
||||
app.celery.tasks.send_email_code.apply_async.assert_called_once_with(['something_encrypted'],
|
||||
queue='email-code')
|
||||
|
||||
|
||||
# TODO: Remove this test once the admin app has stopped using it.
|
||||
def test_request_verify_code_schema_invalid_code_type(notify_api, sample_user):
|
||||
from app.schemas import old_request_verify_code_schema
|
||||
data = json.dumps({'code_type': 'not_sms'})
|
||||
code, error = old_request_verify_code_schema.loads(data)
|
||||
assert error == {'code_type': ['Invalid code type']}
|
||||
|
||||
|
||||
# TODO: Remove this method once the admin app has stopped using it.
|
||||
def test_request_verify_code_schema_with_to(notify_api, sample_user):
|
||||
from app.schemas import old_request_verify_code_schema
|
||||
data = json.dumps({'code_type': 'sms', 'to': 'some@one.gov.uk'})
|
||||
code, error = old_request_verify_code_schema.loads(data)
|
||||
assert code == {'code_type': 'sms', 'to': 'some@one.gov.uk'}
|
||||
assert error == {}
|
||||
|
||||
|
||||
def test_send_user_sms_code(notify_api,
|
||||
sample_sms_code,
|
||||
mock_celery_send_sms_code,
|
||||
|
||||
Reference in New Issue
Block a user