celery test cleanup

* Alter config so an error will be raised if you forget to mock out a
  celery call in one of your tests
* Remove an unneeded exception type that was masking errors
This commit is contained in:
Leo Hemsted
2017-06-19 14:58:38 +01:00
parent 88a479a4bb
commit ac7665bfc6
8 changed files with 16 additions and 33 deletions

View File

@@ -755,13 +755,15 @@ def test_should_delete_notification_and_return_error_if_sqs_fails(
save_model_api_key(api_key)
auth_header = create_jwt_token(secret=api_key.secret, client_id=str(api_key.service_id))
response = client.post(
path='/notifications/{}'.format(template_type),
data=json.dumps(data),
headers=[('Content-Type', 'application/json'), ('Authorization', 'Bearer {}'.format(auth_header))])
with pytest.raises(Exception) as e:
client.post(
path='/notifications/{}'.format(template_type),
data=json.dumps(data),
headers=[('Content-Type', 'application/json'), ('Authorization', 'Bearer {}'.format(auth_header))]
)
assert str(e.value) == 'failed to talk to SQS'
mocked.assert_called_once_with([fake_uuid], queue='send-tasks')
assert response.status_code == 500
assert not notifications_dao.get_notification_by_id(fake_uuid)
assert not NotificationHistory.query.get(fake_uuid)

View File

@@ -8,7 +8,6 @@ from freezegun import freeze_time
from collections import namedtuple
from app.models import Template, Notification, NotificationHistory, ScheduledNotification
from app.notifications import SendNotificationToQueueError
from app.notifications.process_notifications import (
create_content_for_notification,
persist_notification,
@@ -238,7 +237,7 @@ def test_send_notification_to_queue(notify_db, notify_db_session,
def test_send_notification_to_queue_throws_exception_deletes_notification(sample_notification, mocker):
mocked = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async', side_effect=Boto3Error("EXPECTED"))
with pytest.raises(SendNotificationToQueueError):
with pytest.raises(Boto3Error):
send_notification_to_queue(sample_notification, False)
mocked.assert_called_once_with([(str(sample_notification.id))], queue='send-sms')

View File

@@ -2247,7 +2247,9 @@ def test_fetch_service_inbound_api(client, sample_service):
assert json.loads(response.get_data(as_text=True))["data"] == service_inbound_api.serialize()
def test_send_one_off_notification(admin_request, sample_template):
def test_send_one_off_notification(admin_request, sample_template, mocker):
mocker.patch('app.service.send_notification.send_notification_to_queue')
response = admin_request.post(
'service.create_one_off_notification',
service_id=sample_template.service_id,