Skip to content

Commit

Permalink
Merge pull request #55 from edx/ddumesnil/no-pls-for-archive-enrollme…
Browse files Browse the repository at this point in the history
…nts-AA-194

AA-194: Don't return dates for enrollments created after course end
  • Loading branch information
Dillon-Dumesnil authored Jun 17, 2020
2 parents 6742d9c + df6b568 commit 7a6f187
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion edx_when/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

from __future__ import absolute_import, unicode_literals

__version__ = '1.2.7'
__version__ = '1.2.8'

default_app_config = 'edx_when.apps.EdxWhenConfig' # pylint: disable=invalid-name
5 changes: 5 additions & 0 deletions edx_when/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def actual_date(self, schedule=None, end_datetime=None):
self
)
)

# If the user enrolled after the course ended, we don't want to return any dates.
if end_datetime and schedule.start_date > end_datetime:
return None

# If the course has an end date defined, we will prefer the course end date
# if the relative date is later than the course end date.
# Note: This can result in several dates being listed the same as the course end date
Expand Down
6 changes: 6 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ def test_actual_date_failure(self, abs_date, rel_date, schedule):
with self.assertRaises(ValueError):
policy.actual_date(schedule)

def test_actual_date_schedule_after_end(self):
# This only applies for relative dates so we are not testing abs date.
policy = DatePolicy(rel_date=timedelta(days=1))
schedule = DummySchedule(start_date=datetime(2020, 4, 1))
self.assertIsNone(policy.actual_date(schedule, end_datetime=datetime(2020, 1, 1)))

def test_mixed_dates(self):
with self.assertRaises(ValidationError):
DatePolicy(abs_date=datetime(2020, 1, 1), rel_date=timedelta(days=1)).full_clean()
Expand Down

0 comments on commit 7a6f187

Please sign in to comment.