def test_in_progress_course_upgrade_deadline_check(self, offset, mock_get_programs): """ Verify that if the user's enrollment is not of the same type as the course run, the course will only count as in progress if there is another available seat with the right type for which the upgrade deadline has not passed. """ course_run_key = generate_course_run_key() now = datetime.datetime.now(utc) upgrade_deadline = None if not offset else str(now + datetime.timedelta( days=offset)) required_seat = SeatFactory(type='verified', upgrade_deadline=upgrade_deadline) enrolled_seat = SeatFactory(type='audit') seats = [required_seat, enrolled_seat] data = [ ProgramFactory(courses=[ CourseFactory(course_runs=[ CourseRunFactory( key=course_run_key, type='verified', seats=seats), ]), ]) ] mock_get_programs.return_value = data CourseEnrollmentFactory(user=self.user, course_id=course_run_key, mode='audit') meter = ProgramProgressMeter(self.site, self.user) program = data[0] expected = [ ProgressFactory(uuid=program['uuid'], completed=0, in_progress=1 if offset in [None, 1] else 0, not_started=1 if offset in [-1] else 0) ] self.assertEqual(meter.progress(count_only=True), expected)
def test_in_progress_course_upgrade_deadline_check(self, modifier, mock_get_programs): """ Verify that if the user's enrollment is not of the same type as the course run, the course will only count as in progress if there is another available seat with the right type, where the upgrade deadline has not expired. """ course_run_key = generate_course_run_key() now = datetime.datetime.now(utc) date_modifier = modifier * datetime.timedelta(days=1) seat_with_upgrade_deadline = SeatFactory(type='test', upgrade_deadline=str(now + date_modifier)) enrolled_seat = SeatFactory(type='verified') seats = [seat_with_upgrade_deadline, enrolled_seat] data = [ ProgramFactory( courses=[ CourseFactory(course_runs=[ CourseRunFactory(key=course_run_key, type='test', seats=seats), ]), ] ) ] mock_get_programs.return_value = data self._create_enrollments(course_run_key) meter = ProgramProgressMeter(self.user) program = data[0] expected = [ ProgressFactory( uuid=program['uuid'], completed=0, in_progress=1 if modifier == 1 else 0, not_started=1 if modifier == -1 else 0 ) ] self.assertEqual(meter.progress(count_only=True), expected)
def _create_course(self, course_price): """ Creates the course in mongo and update it with the instructor data. Also creates catalog course with respect to course run. Returns: Catalog course dict. """ course = ModuleStoreCourseFactory() course.start = datetime.datetime.now(utc) - datetime.timedelta(days=1) course.end = datetime.datetime.now(utc) + datetime.timedelta(days=1) course.instructor_info = self.instructors course = self.update_course(course, self.user.id) course_run = CourseRunFactory(key=unicode(course.id), seats=[SeatFactory(price=course_price)]) return CourseFactory(course_runs=[course_run])