Creating notification tasks should write send tasks to the research-mode queue if research mode service.

This commit is contained in:
Martyn Inglis
2016-09-28 15:29:10 +01:00
parent 20ccdab3bd
commit 3618a3967c
2 changed files with 61 additions and 2 deletions

View File

@@ -131,7 +131,10 @@ def send_sms(self,
created_at, notification, notification_id, service.id, SMS_TYPE, api_key_id, key_type created_at, notification, notification_id, service.id, SMS_TYPE, api_key_id, key_type
) )
) )
provider_tasks.deliver_sms.apply_async((notification_id), queue='send-sms') provider_tasks.deliver_sms.apply_async(
(notification_id),
queue='send-sms' if not service.research_mode else 'research-mode'
)
current_app.logger.info( current_app.logger.info(
"SMS {} created at {}".format(notification_id, created_at) "SMS {} created at {}".format(notification_id, created_at)
@@ -170,7 +173,10 @@ def send_email(self, service_id,
) )
) )
provider_tasks.deliver_email.apply_async((notification_id), queue='send-email') provider_tasks.deliver_email.apply_async(
(notification_id),
queue='send-email' if not service.research_mode else 'research-mode'
)
current_app.logger.info("Email {} created at {}".format(notification_id, created_at)) current_app.logger.info("Email {} created at {}".format(notification_id, created_at))
except SQLAlchemyError as e: except SQLAlchemyError as e:

View File

@@ -357,6 +357,32 @@ def test_should_send_template_to_correct_sms_task_and_persist(sample_template_wi
assert persisted_notification.notification_type == 'sms' assert persisted_notification.notification_type == 'sms'
def test_should_put_send_sms_task_in_research_mode_queue_if_research_mode_service(notify_db, notify_db_session, mocker):
service = sample_service(notify_db, notify_db_session)
service.research_mode = True
services_dao.dao_update_service(service)
template = sample_template(notify_db, notify_db_session, service=service)
notification = _notification_json(template, to="+447234123123")
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
notification_id = uuid.uuid4()
send_sms(
template.service_id,
notification_id,
encryption.encrypt(notification),
datetime.utcnow().strftime(DATETIME_FORMAT)
)
provider_tasks.deliver_sms.apply_async.assert_called_once_with(
(notification_id),
queue="research-mode"
)
def test_should_send_sms_if_restricted_service_and_valid_number(notify_db, notify_db_session, mocker): def test_should_send_sms_if_restricted_service_and_valid_number(notify_db, notify_db_session, mocker):
user = sample_user(notify_db, notify_db_session, mobile_numnber="07700 900890") user = sample_user(notify_db, notify_db_session, mobile_numnber="07700 900890")
service = sample_service(notify_db, notify_db_session, user=user, restricted=True) service = sample_service(notify_db, notify_db_session, user=user, restricted=True)
@@ -491,6 +517,33 @@ def test_should_not_send_email_if_restricted_service_and_invalid_email_address(n
Notification.query.filter_by(id=notification_id).one() Notification.query.filter_by(id=notification_id).one()
def test_should_put_send_email_task_in_research_mode_queue_if_research_mode_service(notify_db, notify_db_session, mocker):
service = sample_service(notify_db, notify_db_session)
service.research_mode = True
services_dao.dao_update_service(service)
template = sample_email_template(notify_db, notify_db_session, service=service)
notification = _notification_json(template, to="test@test.com")
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
notification_id = uuid.uuid4()
send_email(
template.service_id,
notification_id,
encryption.encrypt(notification),
datetime.utcnow().strftime(DATETIME_FORMAT)
)
provider_tasks.deliver_email.apply_async.assert_called_once_with(
(notification_id),
queue="research-mode"
)
def test_should_send_sms_template_to_and_persist_with_job_id(sample_job, sample_api_key, mocker): def test_should_send_sms_template_to_and_persist_with_job_id(sample_job, sample_api_key, mocker):
notification = _notification_json( notification = _notification_json(
sample_job.template, sample_job.template,