Beispiel #1
0
    def test_get_course_about_section_render(self):

        # Test render works okay
        course_about = get_course_about_section(self.request, self.course, 'short_description')
        assert course_about == 'A course about toys.'

        # Test when render raises an exception
        with mock.patch('lms.djangoapps.courseware.courses.get_module') as mock_module_render:
            mock_module_render.return_value = mock.MagicMock(
                render=mock.Mock(side_effect=Exception('Render failed!'))
            )
            course_about = get_course_about_section(self.request, self.course, 'short_description')
            assert 'this module is temporarily unavailable' in course_about
Beispiel #2
0
def get_course_info(request, course_id):
    """
        Get course info related to dates and grades
    """
    if(not _has_page_access(request.user, course_id)):
        raise Http404()
    course_key = CourseKey.from_string(course_id)
    course = get_course_with_access(request.user, "load", course_key)

    grade_cutoff = min(course.grade_cutoffs.values())
    min_grade_approval = _grade_percent_scaled(grade_cutoff, grade_cutoff)
    course_start_date, course_end_date = _get_course_dates(course)
    course_effort = (
        get_course_about_section(request, course, "effort") or 'None'
    ).strip()

    course_info = {
        'grade_cutoff'      : grade_cutoff,
        'min_grade_approval': min_grade_approval,
        'start_date'        : course_start_date,
        'end_date'          : course_end_date,
        'effort'            : course_effort,
        'display_name'      : course.display_name_with_default
    }

    data = json.dumps(course_info, default=json_util.default)
    return HttpResponse(data)
Beispiel #3
0
 def get_description(self, course):
     """
     Get the representation for SerializerMethodField `description`
     """
     return get_course_about_section(self.context['request'], course,
                                     'short_description').strip()
Beispiel #4
0
 def get_short_description(self, course):
     """
     Get the representation for SerializerMethodField `short_description`
     """
     return get_course_about_section(self.context['request'], course, 'short_description').strip()