Merge branch 'master' into scheduled-delivery-of-jobs-cleanup

Conflicts:
	tests/app/job/test_rest.py
This commit is contained in:
Rebecca Law
2016-09-02 11:03:21 +01:00
18 changed files with 172 additions and 121 deletions

View File

@@ -84,7 +84,7 @@ def process_job(job_id):
create_uuid(),
encrypted,
datetime.utcnow().strftime(DATETIME_FORMAT)),
queue='bulk-sms'
queue='db-sms'
)
if template.template_type == EMAIL_TYPE:
@@ -93,7 +93,7 @@ def process_job(job_id):
create_uuid(),
encrypted,
datetime.utcnow().strftime(DATETIME_FORMAT)),
queue='bulk-email')
queue='db-email')
finished = datetime.utcnow()
job.status = 'finished'

View File

@@ -6,10 +6,10 @@ from app.clients.sms import (SmsClient, SmsClientException)
mmg_response_map = {
'2': {
"message": ' Temporary failure',
"message": ' Permanent failure',
"notification_statistics_status": STATISTICS_FAILURE,
"success": False,
"notification_status": 'temporary-failure'
"notification_status": 'permanent-failure'
},
'3': {
"message": 'Delivered',

View File

@@ -129,4 +129,7 @@ def create_job(service_id):
if job.job_status == JOB_STATUS_PENDING:
process_job.apply_async([str(job.id)], queue="process-job")
return jsonify(data=job_schema.dump(job).data), 201
job_json = job_schema.dump(job).data
job_json['statistics'] = []
return jsonify(data=job_json), 201

View File

@@ -15,7 +15,7 @@ from notifications_utils.renderers import PassThrough
from app.clients.email.aws_ses import get_aws_responses
from app import api_user, encryption, create_uuid, DATETIME_FORMAT, DATE_FORMAT, statsd_client
from app.dao.services_dao import dao_fetch_todays_stats_for_service
from app.models import KEY_TYPE_TEAM
from app.models import KEY_TYPE_TEAM, KEY_TYPE_TEST
from app.dao import (
templates_dao,
services_dao,
@@ -77,15 +77,6 @@ def process_ses_response():
notification_status = aws_response_dict['notification_status']
try:
source = ses_message['mail']['source']
if is_not_a_notification(source):
current_app.logger.info(
"SES callback for notify success:. source {} status {}".format(source, notification_status)
)
return jsonify(
result="success", message="SES callback succeeded"
), 200
reference = ses_message['mail']['messageId']
if not notifications_dao.update_notification_status_by_reference(
reference,
@@ -117,18 +108,6 @@ def process_ses_response():
raise InvalidRequest(error, status_code=400)
def is_not_a_notification(source):
invite_email = "{}@{}".format(
current_app.config['INVITATION_EMAIL_FROM'],
current_app.config['NOTIFY_EMAIL_DOMAIN']
)
if current_app.config['VERIFY_CODE_FROM_EMAIL_ADDRESS'] == source:
return True
if invite_email == source:
return True
return False
@notifications.route('/notifications/sms/mmg', methods=['POST'])
def process_mmg_response():
client_name = 'MMG'
@@ -215,7 +194,10 @@ def send_notification(notification_type):
service_stats = sum(row.count for row in dao_fetch_todays_stats_for_service(service.id))
if service_stats >= service.message_limit:
if all((
api_user.key_type != KEY_TYPE_TEST,
service_stats >= service.message_limit
)):
error = 'Exceeded send limits ({}) for today'.format(service.message_limit)
raise InvalidRequest(error, status_code=429)
@@ -259,12 +241,16 @@ def send_notification(notification_type):
errors = {'content': [message]}
raise InvalidRequest(errors, status_code=400)
if (service.restricted or api_user.key_type == KEY_TYPE_TEAM) and not allowed_to_send_to(
notification['to'],
itertools.chain.from_iterable(
[user.mobile_number, user.email_address] for user in service.users
if all((
api_user.key_type != KEY_TYPE_TEST,
service.restricted or api_user.key_type == KEY_TYPE_TEAM,
not allowed_to_send_to(
notification['to'],
itertools.chain.from_iterable(
[user.mobile_number, user.email_address] for user in service.users
)
)
):
)):
if (api_user.key_type == KEY_TYPE_TEAM):
message = 'Cant send to this recipient using a team-only API key'
else:

View File

@@ -64,13 +64,6 @@ def _validate_datetime_not_in_past(dte, msg="Date cannot be in the past"):
raise ValidationError(msg)
# TODO I think marshmallow provides a better integration and error handling.
# Would be better to replace functionality in dao with the marshmallow supported
# functionality.
# http://marshmallow.readthedocs.org/en/latest/api_reference.html
# http://marshmallow.readthedocs.org/en/latest/extending.html
class BaseSchema(ma.ModelSchema):
def __init__(self, load_json=False, *args, **kwargs):