Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mchlwellman committed Nov 1, 2024
1 parent 93400bd commit 7dc7eb3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/celery/twilio_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 = (
Expand All @@ -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()
Expand Down
9 changes: 3 additions & 6 deletions tests/app/celery/test_twilio_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
)


TWILIO_STATUS_PAGE_SIZE = 5


@pytest.mark.parametrize(
'status, expected',
[
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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])

Expand Down

0 comments on commit 7dc7eb3

Please sign in to comment.