Commit 9c2530ce by Jeff LaJoie

LEARNER-3638: Fixes expiration issues for learners who upgrade late into a course

parent 72bb440d
......@@ -54,10 +54,11 @@ class CourseEntitlementPolicy(models.Model):
# Compute the days left for the regain
days_since_course_start = (now - course_overview.start).days
days_since_enrollment = (now - entitlement.enrollment_course_run.created).days
days_since_entitlement_created = (now - entitlement.created).days
# We want to return whichever days value is less since it is then the more recent one
days_until_regain_ends = (self.regain_period.days - # pylint: disable=no-member
min(days_since_course_start, days_since_enrollment))
min(days_since_course_start, days_since_enrollment, days_since_entitlement_created))
# If the base days until expiration is less than the days until the regain period ends, use that instead
if days_until_expiry < days_until_regain_ends:
......
......@@ -168,6 +168,7 @@ class TestModels(TestCase):
self.enrollment.created = past_datetime
self.course.start = past_datetime
entitlement.save()
entitlement.refresh_from_db()
self.course.save()
self.enrollment.save()
assert entitlement.enrollment_course_run
......@@ -175,6 +176,21 @@ class TestModels(TestCase):
assert expired_at_datetime
assert entitlement.expired_at
# Verify that an entitlement that has just been created, but the user has been enrolled in the course for
# greater than 14 days, and the course started more than 14 days ago is not expired
entitlement = CourseEntitlementFactory.create(enrollment_course_run=self.enrollment)
past_datetime = datetime.utcnow().replace(tzinfo=pytz.UTC) - timedelta(days=20)
entitlement.created = datetime.utcnow().replace(tzinfo=pytz.UTC)
self.enrollment.created = past_datetime
self.course.start = past_datetime
entitlement.save()
self.enrollment.save()
self.course.save()
assert entitlement.enrollment_course_run
expired_at_datetime = entitlement.expired_at_datetime
assert expired_at_datetime is None
assert entitlement.expired_at is None
# Verify a date 451 days in the past (1 days after the policy expiration)
# That is enrolled and started in within the regain period is still expired
entitlement = CourseEntitlementFactory.create(enrollment_course_run=self.enrollment)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment