Commit d37264ae by Albert St. Aubin

Bug fix for unpublished courses that users have putchased within a program

[LEARNER-2715]
parent b96f646d
...@@ -550,7 +550,7 @@ class TestProgramProgressMeter(TestCase): ...@@ -550,7 +550,7 @@ class TestProgramProgressMeter(TestCase):
self.assertEqual(meter._is_course_complete(course), True) self.assertEqual(meter._is_course_complete(course), True)
def _create_course(self, course_price): def _create_course(self, course_price, course_run_count=1):
""" """
Creates the course in mongo and update it with the instructor data. Creates the course in mongo and update it with the instructor data.
Also creates catalog course with respect to course run. Also creates catalog course with respect to course run.
...@@ -558,17 +558,18 @@ def _create_course(self, course_price): ...@@ -558,17 +558,18 @@ def _create_course(self, course_price):
Returns: Returns:
Catalog course dict. Catalog course dict.
""" """
course = ModuleStoreCourseFactory() course_runs = []
course.start = datetime.datetime.now(utc) - datetime.timedelta(days=1) for x in range(course_run_count):
course.end = datetime.datetime.now(utc) + datetime.timedelta(days=1) course = ModuleStoreCourseFactory.create(run='Run_' + str(x))
course.instructor_info = self.instructors course.start = datetime.datetime.now(utc) - datetime.timedelta(days=1)
course = self.update_course(course, self.user.id) course.end = datetime.datetime.now(utc) + datetime.timedelta(days=1)
course.instructor_info = self.instructors
course_run = CourseRunFactory( course = self.update_course(course, self.user.id)
key=unicode(course.id),
seats=[SeatFactory(price=course_price)] run = CourseRunFactory(key=unicode(course.id), seats=[SeatFactory(price=course_price)])
) course_runs.append(run)
return CourseFactory(course_runs=[course_run])
return CourseFactory(course_runs=course_runs)
@ddt.ddt @ddt.ddt
...@@ -810,6 +811,25 @@ class TestProgramDataExtender(ModuleStoreTestCase): ...@@ -810,6 +811,25 @@ class TestProgramDataExtender(ModuleStoreTestCase):
data = ProgramDataExtender(program2, self.user).extend() data = ProgramDataExtender(program2, self.user).extend()
self.assertTrue(data['is_learner_eligible_for_one_click_purchase']) self.assertTrue(data['is_learner_eligible_for_one_click_purchase'])
def test_learner_eligibility_for_one_click_purchase_with_unpublished(self):
"""
Learner should be eligible for one click purchase if:
- program is eligible for one click purchase
- There are courses remaining that have not been purchased and enrolled in.
"""
course1 = _create_course(self, self.course_price, course_run_count=2)
course2 = _create_course(self, self.course_price)
CourseEnrollmentFactory(user=self.user, course_id=course1['course_runs'][0]['key'], mode='verified')
course1['course_runs'][0]['status'] = 'unpublished'
program2 = ProgramFactory(
courses=[course1, course2],
is_program_eligible_for_one_click_purchase=True,
applicable_seat_types=['verified'],
)
data = ProgramDataExtender(program2, self.user).extend()
self.assertEqual(len(data['skus']), 1)
self.assertTrue(data['is_learner_eligible_for_one_click_purchase'])
def test_learner_eligibility_for_one_click_purchase_professional_no_id(self): def test_learner_eligibility_for_one_click_purchase_professional_no_id(self):
""" """
Learner should not be eligible for one click purchase if: Learner should not be eligible for one click purchase if:
......
...@@ -463,26 +463,44 @@ class ProgramDataExtender(object): ...@@ -463,26 +463,44 @@ class ProgramDataExtender(object):
if is_learner_eligible_for_one_click_purchase: if is_learner_eligible_for_one_click_purchase:
for course in self.data['courses']: for course in self.data['courses']:
add_course_sku = False add_course_sku = False
unpublished_enrollment = False
unpublished_course_runs = filter(lambda run: run['status'] == 'unpublished', course['course_runs'])
published_course_runs = filter(lambda run: run['status'] == 'published', course['course_runs']) published_course_runs = filter(lambda run: run['status'] == 'published', course['course_runs'])
if len(published_course_runs) == 1: if len(published_course_runs) == 1:
# Look at the course runs for a course and determine if the course SKU should be added. # Look at the course runs for a course and determine if the course SKU should be added.
course_run = published_course_runs[0]
(enrollment_mode, active) = CourseEnrollment.enrollment_mode_for_user( if len(unpublished_course_runs) > 0:
self.user, for course_run in unpublished_course_runs:
CourseKey.from_string(course_run['key']) (enrollment_mode, active) = CourseEnrollment.enrollment_mode_for_user(
) self.user,
CourseKey.from_string(course_run['key'])
if enrollment_mode is not None and active is not None: )
# Check all the applicable seat types
# this will also check for no-id-professional as professional if enrollment_mode is not None and active is not None:
applicable_seat = any(seat_type in enrollment_mode for seat_type in applicable_seat_types) # Check all the applicable seat types
# this will also check for no-id-professional as professional
# If no applicable seat is found add the course SKU to the list applicable_seat = any(seat_type in enrollment_mode
if not applicable_seat or not active: for seat_type in applicable_seat_types)
# If no applicable seat is found add the course SKU to the list
if applicable_seat:
unpublished_enrollment = True
if not unpublished_enrollment:
course_run = published_course_runs[0]
(enrollment_mode, active) = CourseEnrollment.enrollment_mode_for_user(
self.user,
CourseKey.from_string(course_run['key'])
)
if enrollment_mode is not None and active is not None:
applicable_seat = any(seat_type in enrollment_mode for seat_type in applicable_seat_types)
if not applicable_seat or not active:
add_course_sku = True
else:
# There is no enrollment information for the course add the course SKU
add_course_sku = True add_course_sku = True
else:
# There is no enrollment information for the course add the course SKU
add_course_sku = True
if add_course_sku: if add_course_sku:
for seat in published_course_runs[0]['seats']: for seat in published_course_runs[0]['seats']:
......
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