From 7332874415245be45828325059089cefa1c5513d Mon Sep 17 00:00:00 2001 From: Jenny Duckett Date: Fri, 9 Dec 2016 17:37:18 +0000 Subject: [PATCH] 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. --- tests/app/notifications/test_process_notification.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/app/notifications/test_process_notification.py b/tests/app/notifications/test_process_notification.py index 16b7ee0f2..7190e0fac 100644 --- a/tests/app/notifications/test_process_notification.py +++ b/tests/app/notifications/test_process_notification.py @@ -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)