Skip to content

Commit

Permalink
fix: assignment auto-expiration date
Browse files Browse the repository at this point in the history
ENT-8146 | Use the assignment.created time as the starting
point for assignment auto-expiration if a successful notification
action does not yet exist.
  • Loading branch information
iloveagent57 committed Jan 12, 2024
1 parent 90fa068 commit 3c77c0b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
9 changes: 7 additions & 2 deletions enterprise_access/apps/content_assignments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,14 @@ def get_auto_expiration_date(self):
reset the auto-expiration date.
"""
last_notification = self.get_last_successful_notified_action()
# If we're currently sending the first notification message,
# we won't yet have a successful action, so use the creation time of
# the assignment as the starting_point
if not last_notification:
return None
return last_notification.completed_at + timezone.timedelta(days=NUM_DAYS_BEFORE_AUTO_CANCELLATION)
starting_point = self.created
else:
starting_point = last_notification.completed_at
return starting_point + timezone.timedelta(days=NUM_DAYS_BEFORE_AUTO_CANCELLATION)

def get_last_successful_linked_action(self):
"""
Expand Down
14 changes: 10 additions & 4 deletions enterprise_access/apps/content_assignments/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,20 @@ def test_get_set_reminded_actions(self):

def test_get_auto_expiration_date_no_action(self):
"""
Test that this method returns None if there is no last successful
Test that this method returns a date 90 days from the assignment
creation time if there is no last successful
notified action.
"""
self.assertIsNone(self.assignment.get_auto_expiration_date())

self.assertEqual(
self.assignment.get_auto_expiration_date(),
self.assignment.created + timezone.timedelta(days=NUM_DAYS_BEFORE_AUTO_CANCELLATION),
)
self.assignment.add_errored_notified_action(Exception('foo'))

self.assertIsNone(self.assignment.get_auto_expiration_date())
self.assertEqual(
self.assignment.get_auto_expiration_date(),
self.assignment.created + timezone.timedelta(days=NUM_DAYS_BEFORE_AUTO_CANCELLATION),
)

def test_get_auto_expiration_date(self):
"""
Expand Down

0 comments on commit 3c77c0b

Please sign in to comment.