From 7dc7eb3a5bfec1acbd98a6318658f004bea81e15 Mon Sep 17 00:00:00 2001 From: Michael Wellman Date: Fri, 1 Nov 2024 12:48:25 -0400 Subject: [PATCH] Fixed tests --- app/celery/twilio_tasks.py | 4 ++-- tests/app/celery/test_twilio_tasks.py | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/app/celery/twilio_tasks.py b/app/celery/twilio_tasks.py index 65d4fb7b5a..aeda948d66 100644 --- a/app/celery/twilio_tasks.py +++ b/app/celery/twilio_tasks.py @@ -4,7 +4,6 @@ from sqlalchemy import select from app import db, notify_celery, twilio_sms_client -from app.config import TWILIO_STATUS_PAGE_SIZE from app.constants import NOTIFICATION_STATUS_TYPES_COMPLETED from app.models import Notification @@ -13,6 +12,7 @@ def _get_notifications() -> list: """ Returns a list of notifications not in final state """ + current_app.logger.info('Getting notifications to update status') one_hour_ago = datetime.now(timezone.utc) - timedelta(hours=1) query = ( @@ -21,7 +21,7 @@ def _get_notifications() -> list: .where(Notification.sent_by == 'twilio') .where(~Notification.status.in_(NOTIFICATION_STATUS_TYPES_COMPLETED)) .where(Notification.created_at > one_hour_ago) - .limit(TWILIO_STATUS_PAGE_SIZE) + .limit(current_app.config['TWILIO_STATUS_PAGE_SIZE']) ) current_app.logger.debug('Query: %s', query) return db.session.execute(query).scalars().all() diff --git a/tests/app/celery/test_twilio_tasks.py b/tests/app/celery/test_twilio_tasks.py index b6c19d1b43..7d7b580da7 100644 --- a/tests/app/celery/test_twilio_tasks.py +++ b/tests/app/celery/test_twilio_tasks.py @@ -17,9 +17,6 @@ ) -TWILIO_STATUS_PAGE_SIZE = 5 - - @pytest.mark.parametrize( 'status, expected', [ @@ -35,7 +32,7 @@ ) def test__get_notifications_statuses(sample_notification, status, expected): created_at = datetime.now(timezone.utc) - timedelta(minutes=30) - notification = sample_notification(created_at=created_at, status=status) + notification = sample_notification(created_at=created_at, status=status, sent_by='twilio') notifications = _get_notifications() notification_ids = [n.id for n in notifications] @@ -56,7 +53,7 @@ def test__get_notifications_statuses(sample_notification, status, expected): ) def test__get_notifications_datefilter(sample_notification, minute_offset, expected): created_at = datetime.now(timezone.utc) - timedelta(minutes=minute_offset) - notification = sample_notification(created_at=created_at, status=NOTIFICATION_CREATED) + notification = sample_notification(created_at=created_at, status=NOTIFICATION_CREATED, sent_by='twilio') notifications = _get_notifications() notification_ids = [n.id for n in notifications] @@ -67,7 +64,7 @@ def test__get_notifications_datefilter(sample_notification, minute_offset, expec def test_update_twilio_status_with_results(mocker, sample_notification): - notification = sample_notification() + notification = sample_notification(status=NOTIFICATION_CREATED, sent_by='twilio') mocker.patch('app.celery.twilio_tasks._get_notifications', return_value=[notification])