def test_pre_requisite_course(self):
     pre_requisite_course = CourseFactory.create(org='edX', course='900', display_name='pre requisite course')
     course = CourseFactory.create(pre_requisite_courses=[str(pre_requisite_course.id)])
     self.setup_user()
     url = reverse('about_course', args=[str(course.id)])
     resp = self.client.get(url)
     assert resp.status_code == 200
     pre_requisite_courses = get_prerequisite_courses_display(course)
     pre_requisite_course_about_url = reverse('about_course', args=[str(pre_requisite_courses[0]['key'])])
     assert '<span class="important-dates-item-text pre-requisite"><a href="{}">{}</a></span>'.format(pre_requisite_course_about_url, pre_requisite_courses[0]['display']) in resp.content.decode(resp.charset).strip('\n')  # pylint: disable=line-too-long
Beispiel #2
0
def get_course_cards_and_gross_details(user, courses):
    """
    Decides status, grade and message for each course in the list of courses and appends a CourseCard object containing
    course, status, grade, message and prerequisite course name in a list. It also computes whether any course from the
    list of courses has been started and whether all the courses have been completed.

    Arguments:
        user (User): User object
        courses (list): List containing Course objects

    Returns:
        course_cards (list): A list containing dictionaries with status, grade, message and course
        is_any_course_started (bool): Flag indicating if any course has been started yet
        are_courses_completed (bool): Flag indicating if all courses have been passed
    """
    open_course_cards = []
    locked_course_cards = []
    unlocked_course_cards = []
    is_any_course_started = False
    are_courses_completed = bool(courses)

    for course in courses:
        message = grade = status = pre_req = ''
        course_completion = 0
        pre_requisite_courses = get_prerequisite_courses_display(course)

        if pre_requisite_courses:
            status, message, pre_req = get_information_for_course_with_prerequisite(
                user, pre_requisite_courses[0])

        if status != LOCKED:
            is_any_course_started, status, grade, message, course_completion = get_information_for_unlocked_course(
                user, course, is_any_course_started)

        if status != COMPLETED:
            are_courses_completed = False

        course_card = CourseCard(course=course,
                                 status=status,
                                 grade=grade,
                                 message=message,
                                 pre_req=pre_req,
                                 completion=course_completion)

        if pre_requisite_courses:
            if status == LOCKED:
                locked_course_cards.append(course_card)
            else:
                unlocked_course_cards.append(course_card)
        else:
            open_course_cards.append(course_card)

    course_cards = open_course_cards + unlocked_course_cards + locked_course_cards

    return course_cards, is_any_course_started, are_courses_completed
Beispiel #3
0
 def test_pre_requisite_course(self):
     pre_requisite_course = CourseFactory.create(
         org='edX', course='900', display_name='pre requisite course')
     course = CourseFactory.create(
         pre_requisite_courses=[text_type(pre_requisite_course.id)])
     self.setup_user()
     url = reverse('about_course', args=[text_type(course.id)])
     resp = self.client.get(url)
     self.assertEqual(resp.status_code, 200)
     pre_requisite_courses = get_prerequisite_courses_display(course)
     pre_requisite_course_about_url = reverse(
         'about_course', args=[text_type(pre_requisite_courses[0]['key'])])
     self.assertIn(
         u"<span class=\"important-dates-item-text pre-requisite\"><a href=\"{}\">{}</a></span>"
         .format(pre_requisite_course_about_url,
                 pre_requisite_courses[0]['display']),
         resp.content.decode(resp.charset).strip('\n'))
Beispiel #4
0
    def test_about_page_unfulfilled_prereqs(self):
        pre_requisite_course = CourseFactory.create(
            org='edX',
            course='901',
            display_name='pre requisite course',
        )

        pre_requisite_courses = [text_type(pre_requisite_course.id)]

        # for this failure to occur, the enrollment window needs to be in the past
        course = CourseFactory.create(
            org='edX',
            course='1000',
            # closed enrollment
            enrollment_start=datetime.datetime(2013, 1, 1),
            enrollment_end=datetime.datetime(2014, 1, 1),
            start=datetime.datetime(2013, 1, 1),
            end=datetime.datetime(2030, 1, 1),
            pre_requisite_courses=pre_requisite_courses,
        )
        set_prerequisite_courses(course.id, pre_requisite_courses)

        self.setup_user()
        self.enroll(self.course, True)
        self.enroll(pre_requisite_course, True)

        url = reverse('about_course', args=[text_type(course.id)])
        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 200)
        pre_requisite_courses = get_prerequisite_courses_display(course)
        pre_requisite_course_about_url = reverse(
            'about_course', args=[text_type(pre_requisite_courses[0]['key'])])
        self.assertIn(
            u"<span class=\"important-dates-item-text pre-requisite\"><a href=\"{}\">{}</a></span>"
            .format(pre_requisite_course_about_url,
                    pre_requisite_courses[0]['display']),
            resp.content.decode(resp.charset).strip('\n'))

        url = reverse('about_course',
                      args=[six.text_type(pre_requisite_course.id)])
        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 200)
    def test_about_page_unfulfilled_prereqs(self):
        pre_requisite_course = CourseFactory.create(
            org='edX',
            course='901',
            display_name='pre requisite course',
        )

        pre_requisite_courses = [str(pre_requisite_course.id)]

        # for this failure to occur, the enrollment window needs to be in the past
        course = CourseFactory.create(
            org='edX',
            course='1000',
            # closed enrollment
            enrollment_start=datetime.datetime(2013, 1, 1),
            enrollment_end=datetime.datetime(2014, 1, 1),
            start=datetime.datetime(2013, 1, 1),
            end=datetime.datetime(2030, 1, 1),
            pre_requisite_courses=pre_requisite_courses,
        )
        set_prerequisite_courses(course.id, pre_requisite_courses)

        self.setup_user()
        self.enroll(self.course, True)
        self.enroll(pre_requisite_course, True)

        url = reverse('about_course', args=[str(course.id)])
        resp = self.client.get(url)
        assert resp.status_code == 200
        pre_requisite_courses = get_prerequisite_courses_display(course)
        pre_requisite_course_about_url = reverse(
            'about_course', args=[str(pre_requisite_courses[0]['key'])])
        assert '<span class="important-dates-item-text pre-requisite"><a href="{}">{}</a></span>'.format(pre_requisite_course_about_url, pre_requisite_courses[0]['display']) in resp.content.decode(resp.charset).strip('\n')  # pylint: disable=line-too-long

        url = reverse('about_course', args=[str(pre_requisite_course.id)])
        resp = self.client.get(url)
        assert resp.status_code == 200