Commit 3fbb1571 by Albert St. Aubin

Update to policy check utilities for Course Entitlements

parent 31e8b679
...@@ -70,6 +70,9 @@ class CourseEntitlementPolicy(models.Model): ...@@ -70,6 +70,9 @@ class CourseEntitlementPolicy(models.Model):
to by leaving and regaining their entitlement within policy.regain_period days from start date of to by leaving and regaining their entitlement within policy.regain_period days from start date of
the course or their redemption, whichever comes later, and the expiration period hasn't passed yet the course or their redemption, whichever comes later, and the expiration period hasn't passed yet
""" """
if entitlement.expired_at:
return False
if entitlement.enrollment_course_run: if entitlement.enrollment_course_run:
if GeneratedCertificate.certificate_for_student( if GeneratedCertificate.certificate_for_student(
entitlement.user_id, entitlement.enrollment_course_run.course_id) is not None: entitlement.user_id, entitlement.enrollment_course_run.course_id) is not None:
...@@ -86,6 +89,10 @@ class CourseEntitlementPolicy(models.Model): ...@@ -86,6 +89,10 @@ class CourseEntitlementPolicy(models.Model):
yet been redeemed (enrollment_course_run is NULL) and policy.refund_period has not yet passed, or if yet been redeemed (enrollment_course_run is NULL) and policy.refund_period has not yet passed, or if
the entitlement has been redeemed, but the regain period hasn't passed yet. the entitlement has been redeemed, but the regain period hasn't passed yet.
""" """
# If the Entitlement is expired already it is not refundable
if entitlement.expired_at:
return False
# If there's no order number, it cannot be refunded # If there's no order number, it cannot be refunded
if entitlement.order_number is None: if entitlement.order_number is None:
return False return False
...@@ -108,7 +115,8 @@ class CourseEntitlementPolicy(models.Model): ...@@ -108,7 +115,8 @@ class CourseEntitlementPolicy(models.Model):
# This is < because a get_days_since_created of expiration_period means that that many days have passed, # This is < because a get_days_since_created of expiration_period means that that many days have passed,
# which should then expire the entitlement # which should then expire the entitlement
return (entitlement.get_days_since_created() < self.expiration_period.days # pylint: disable=no-member return (entitlement.get_days_since_created() < self.expiration_period.days # pylint: disable=no-member
and not entitlement.enrollment_course_run) and not entitlement.enrollment_course_run
and not entitlement.expired_at)
def __unicode__(self): def __unicode__(self):
return u'Course Entitlement Policy: expiration_period: {}, refund_period: {}, regain_period: {}'\ return u'Course Entitlement Policy: expiration_period: {}, refund_period: {}, regain_period: {}'\
......
...@@ -46,6 +46,10 @@ class TestModels(TestCase): ...@@ -46,6 +46,10 @@ class TestModels(TestCase):
assert entitlement.is_entitlement_redeemable() is False assert entitlement.is_entitlement_redeemable() is False
entitlement = CourseEntitlementFactory.create(expired_at=datetime.now())
assert entitlement.is_entitlement_refundable() is False
def test_is_entitlement_refundable(self): def test_is_entitlement_refundable(self):
""" """
Test that the entitlement is refundable when created now, and is not refundable when created 70 days Test that the entitlement is refundable when created now, and is not refundable when created 70 days
...@@ -83,6 +87,10 @@ class TestModels(TestCase): ...@@ -83,6 +87,10 @@ class TestModels(TestCase):
assert entitlement.is_entitlement_refundable() is True assert entitlement.is_entitlement_refundable() is True
entitlement = CourseEntitlementFactory.create(expired_at=datetime.now())
assert entitlement.is_entitlement_refundable() is False
def test_is_entitlement_regainable(self): def test_is_entitlement_regainable(self):
""" """
Test that the entitlement is not expired when created now, and is expired when created20 days Test that the entitlement is not expired when created now, and is expired when created20 days
...@@ -113,6 +121,10 @@ class TestModels(TestCase): ...@@ -113,6 +121,10 @@ class TestModels(TestCase):
assert entitlement.is_entitlement_regainable() is False assert entitlement.is_entitlement_regainable() is False
entitlement = CourseEntitlementFactory.create(expired_at=datetime.now())
assert entitlement.is_entitlement_regainable
def test_get_days_until_expiration(self): def test_get_days_until_expiration(self):
""" """
Test that the expiration period is always less than or equal to the policy expiration Test that the expiration period is always less than or equal to the policy expiration
......
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