Use namedtuple in test_send_notification_to_queue

This makes this test a couple of seconds faster - 0.7s instead of 2.5s for me
locally. sample_notification also creates a service, template, user and
permissions, but we don't need any of these objects to exist in the database
for this test. It's particularly helpful for this test because there are so
many parameterized cases. Thanks @leohemsted for suggesting doing this here.
This commit is contained in:
Jenny Duckett
2016-12-09 17:37:18 +00:00
parent e569c54f45
commit 7332874415

View File

@@ -5,6 +5,7 @@ import pytest
from boto3.exceptions import Boto3Error
from sqlalchemy.exc import SQLAlchemyError
from freezegun import freeze_time
from collections import namedtuple
from app.models import Template, Notification, NotificationHistory
from app.notifications import SendNotificationToQueueError
@@ -151,9 +152,14 @@ def test_send_notification_to_queue(notify_db, notify_db_session,
research_mode, requested_queue, expected_queue,
notification_type, key_type, mocker):
mocked = mocker.patch('app.celery.provider_tasks.deliver_{}.apply_async'.format(notification_type))
template = sample_template(notify_db, notify_db_session) if notification_type == 'sms' \
else sample_email_template(notify_db, notify_db_session)
notification = sample_notification(notify_db, notify_db_session, template=template, key_type=key_type)
Notification = namedtuple('Notification', ['id', 'key_type', 'notification_type', 'created_at'])
notification = Notification(
id=uuid.uuid4(),
key_type=key_type,
notification_type=notification_type,
created_at=datetime.datetime(2016, 11, 11, 16, 8, 18),
)
send_notification_to_queue(notification=notification, research_mode=research_mode, queue=requested_queue)
mocked.assert_called_once_with([str(notification.id)], queue=expected_queue)