def can_be_added_to_allowlist(user, course_key): """ Determines if a student is able to be added to the allowlist in a given course-run. """ log.info( f"Checking if student {user.id} in course {course_key} can be added to the allowlist." ) if not is_user_enrolled_in_course(user, course_key): log.info(f"Student {user.id} is not enrolled in course {course_key}") return False if is_certificate_invalidated(user, course_key): log.info( f"Student {user.id} is on the certificate invalidation list for course {course_key}" ) return False if is_on_allowlist(user, course_key): log.info( f"Student {user.id} already appears on allowlist in course {course_key}" ) return False return True
def test_is_user_enrolled_in_course(self): """ Verify the correct value is returned when a learner is actively enrolled in a course-run. """ CourseEnrollmentFactory.create(user_id=self.user.id, course_id=self.course.id) result = is_user_enrolled_in_course(self.user, self.course_run_key) assert result
def test_is_user_enrolled_in_course_no_enrollment(self): """ Verify the correct value is returned when a learner is not enrolled in a course-run. """ result = is_user_enrolled_in_course(self.user, self.course_run_key) assert not result