예제 #1
0
 def test_get_run_data(self):
     """Test for the get_run_data method"""
     edx_user_data = CachedEdxUserData(self.user)
     run_data = edx_user_data.get_run_data(self.p1_course_run_keys[0])
     assert isinstance(run_data, UserCachedRunData)
     assert isinstance(run_data.enrollment, Enrollment)
     assert isinstance(run_data.certificate, Certificate)
     assert isinstance(run_data.current_grade, CurrentGrade)
     assert run_data.enrollment.course_id == self.p1_course_run_keys[0]
     assert run_data.certificate.course_id == self.p1_course_run_keys[0]
     assert run_data.current_grade.course_id == self.p1_course_run_keys[0]
 def test_get_run_data(self):
     """Test for the get_run_data method"""
     edx_user_data = CachedEdxUserData(self.user)
     run_data = edx_user_data.get_run_data(self.p1_course_run_keys[0])
     assert isinstance(run_data, UserCachedRunData)
     assert isinstance(run_data.enrollment, Enrollment)
     assert isinstance(run_data.certificate, Certificate)
     assert isinstance(run_data.current_grade, CurrentGrade)
     assert run_data.enrollment.course_id == self.p1_course_run_keys[0]
     assert run_data.certificate.course_id == self.p1_course_run_keys[0]
     assert run_data.current_grade.course_id == self.p1_course_run_keys[0]
예제 #3
0
 def test_compute_grade_odd_grade(self, odd_value):
     """
     Tests in case the grade coming from edX is not a number
     """
     # test for grade computed on current grades
     test_values = (
         (self.run_fa, api._compute_grade_for_fa, ),
         (self.run_no_fa, api._compute_grade_for_non_fa, ),
     )
     for course_run, grade_func in test_values:
         course_key = course_run.edx_course_key
         current_grade = self.current_grades[course_key]
         current_grade.data['percent'] = odd_value
         current_grade.save()
         user_edx_data = CachedEdxUserData(self.user)
         run_data = user_edx_data.get_run_data(course_key)
         grade = grade_func(run_data)
         assert grade.grade == 0.0
예제 #4
0
def get_final_grade(user, course_run):
    """
    Public function to compute final grades for the a user in a course run.

    Args:
        user (User): a django User
        course_run (CourseRun): a course run model object

    Returns:
        UserFinalGrade: a namedtuple of (grade, passed,) representing the final grade
            of the user in the course run and whether she passed it
    """
    # pull the cached data for the user
    user_data = CachedEdxUserData(user, course_run.course.program)
    run_data = user_data.get_run_data(course_run.edx_course_key)
    # pick the right function
    final_grade_func = _get_compute_func(course_run)
    return final_grade_func(run_data)
예제 #5
0
파일: api.py 프로젝트: mitodl/micromasters
def get_final_grade(user, course_run):
    """
    Public function to compute final grades for the a user in a course run.

    Args:
        user (User): a django User
        course_run (CourseRun): a course run model object

    Returns:
        UserFinalGrade: a namedtuple of (grade, passed,) representing the final grade
            of the user in the course run and whether she passed it
    """
    # pull the cached data for the user
    user_data = CachedEdxUserData(user, course_run.course.program)
    run_data = user_data.get_run_data(course_run.edx_course_key)
    # pick the right function
    final_grade_func = _get_compute_func(course_run)
    return final_grade_func(run_data)
예제 #6
0
 def test_compute_grade_odd_grade(self, odd_value):
     """
     Tests in case the grade coming from edX is not a number
     """
     # test for grade computed on current grades
     test_values = (
         (self.run_fa, api._compute_grade_for_fa, ),
         (self.run_no_fa, api._compute_grade_for_non_fa, ),
     )
     for course_run, grade_func in test_values:
         course_key = course_run.edx_course_key
         current_grade = self.current_grades[course_key]
         current_grade.data['percent'] = odd_value
         current_grade.save()
         user_edx_data = CachedEdxUserData(self.user)
         run_data = user_edx_data.get_run_data(course_key)
         grade = grade_func(run_data)
         assert grade.grade == 0.0