Skip to content
Snippets Groups Projects
Commit 71283706 authored by Waheed Ahmed's avatar Waheed Ahmed
Browse files

Fix None type entitlement passing.

LEARNER-4513
parent 0d60d85e
No related merge requests found
......@@ -369,7 +369,8 @@ class CourseEntitlement(TimeStampedModel):
course_uuid = get_course_uuid_for_course(course_run_key)
if course_uuid:
entitlement = entitlements.filter(course_uuid=course_uuid).first()
if (is_course_run_entitlement_fulfillable(course_run_key=course_run_key, entitlement=entitlement) and
if (entitlement and is_course_run_entitlement_fulfillable(
course_run_key=course_run_key, entitlement=entitlement) and
entitlement.is_entitlement_redeemable()):
return entitlement
return None
......
......@@ -2,6 +2,7 @@
import unittest
from datetime import timedelta
from uuid import uuid4
from django.conf import settings
from django.test import TestCase
......@@ -89,6 +90,26 @@ class TestCourseEntitlementModelHelpers(ModuleStoreTestCase):
entitlement.refresh_from_db()
assert entitlement.enrollment_course_run is None
new_course = CourseFactory()
CourseModeFactory(
course_id=new_course.id,
mode_slug=CourseMode.VERIFIED,
# This must be in the future to ensure it is returned by downstream code.
expiration_datetime=now() + timedelta(days=1)
)
# Return invalid uuid so that no entitlement returned for this new course
mock_get_course_uuid.return_value = uuid4().hex
try:
CourseEntitlement.check_for_existing_entitlement_and_enroll(
user=self.user,
course_run_key=new_course.id,
)
assert not CourseEnrollment.is_enrolled(user=self.user, course_key=new_course.id)
except AttributeError as error:
self.fail(error.message)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class TestModels(TestCase):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment