コード例 #1
0
    def test_enrollments_sorted_most_recent(self):
        """
        Test that the list of newly created courses are properly sorted to show the most
        recent enrollments first.

        """
        self._configure_message_timeout(600)

        # Create a number of new enrollments and courses, and force their creation behind
        # the first enrollment
        courses = []
        for idx, seconds_past in zip(range(2, 6), [5, 10, 15, 20]):
            course_location = locator.CourseLocator(
                'Org{num}'.format(num=idx),
                'Course{num}'.format(num=idx),
                'Run{num}'.format(num=idx)
            )
            course, enrollment = self._create_course_and_enrollment(course_location)
            enrollment.created = datetime.datetime.now(UTC) - datetime.timedelta(seconds=seconds_past)
            enrollment.save()
            courses.append(course)

        courses_list = list(get_course_enrollments(self.student, None, []))
        self.assertEqual(len(courses_list), 6)

        recent_course_list = _get_recently_enrolled_courses(courses_list)
        self.assertEqual(len(recent_course_list), 5)

        self.assertEqual(recent_course_list[1].course.id, courses[0].id)
        self.assertEqual(recent_course_list[2].course.id, courses[1].id)
        self.assertEqual(recent_course_list[3].course.id, courses[2].id)
        self.assertEqual(recent_course_list[4].course.id, courses[3].id)
コード例 #2
0
    def test_dashboard_rendering_with_two_courses(self):
        """
        Tests that the dashboard renders the recent enrollment message appropriately for two courses.
        """
        self._configure_message_timeout(600)
        course_location = locator.CourseLocator(
            'Org2',
            'Course2',
            'Run2'
        )
        course, _ = self._create_course_and_enrollment(course_location)

        self.client.login(username=self.student.username, password=self.PASSWORD)
        response = self.client.get(reverse("dashboard"))

        courses_enrollments = list(get_course_enrollments(self.student, None, []))
        courses_enrollments.sort(key=lambda x: x.created, reverse=True)
        self.assertEqual(len(courses_enrollments), 3)

        recent_course_enrollments = _get_recently_enrolled_courses(courses_enrollments)
        self.assertEqual(len(recent_course_enrollments), 2)

        self.assertContains(
            response,
            "Thank you for enrolling in:".format(course_name=self.course.display_name)
        )
        self.assertContains(
            response,
            ' and '.join(enrollment.course.display_name for enrollment in recent_course_enrollments)
        )
コード例 #3
0
    def test_zero_second_delta(self):
        """
        Tests that the recent enrollment list is empty if configured to zero seconds.
        """
        self._configure_message_timeout(0)
        courses_list = list(get_course_enrollments(self.student, None, []))
        self.assertEqual(len(courses_list), 2)

        recent_course_list = _get_recently_enrolled_courses(courses_list)
        self.assertEqual(len(recent_course_list), 0)
コード例 #4
0
    def test_zero_second_delta(self):
        """
        Tests that the recent enrollment list is empty if configured to zero seconds.
        """
        config = DashboardConfiguration(recent_enrollment_time_delta=0)
        config.save()
        courses_list = list(get_course_enrollment_pairs(self.student, None, []))
        self.assertEqual(len(courses_list), 2)

        recent_course_list = _get_recently_enrolled_courses(courses_list)
        self.assertEqual(len(recent_course_list), 0)
コード例 #5
0
    def test_recently_enrolled_courses(self):
        """
        Test if the function for filtering recent enrollments works appropriately.
        """
        self._configure_message_timeout(60)

        # get courses through iterating all courses
        courses_list = list(get_course_enrollments(self.student, None, []))
        self.assertEqual(len(courses_list), 2)

        recent_course_list = _get_recently_enrolled_courses(courses_list)
        self.assertEqual(len(recent_course_list), 1)
コード例 #6
0
    def test_recently_enrolled_courses(self):
        """
        Test if the function for filtering recent enrollments works appropriately.
        """
        self._configure_message_timeout(60)

        # get courses through iterating all courses
        courses_list = list(get_course_enrollments(self.student, None, []))
        self.assertEqual(len(courses_list), 2)

        recent_course_list = _get_recently_enrolled_courses(courses_list)
        self.assertEqual(len(recent_course_list), 1)
コード例 #7
0
    def test_recently_enrolled_courses(self):
        """
        Test if the function for filtering recent enrollments works appropriately.
        """
        config = DashboardConfiguration(recent_enrollment_time_delta=60)
        config.save()
        # get courses through iterating all courses
        courses_list = list(get_course_enrollment_pairs(self.student, None, []))
        self.assertEqual(len(courses_list), 2)

        recent_course_list = _get_recently_enrolled_courses(courses_list)
        self.assertEqual(len(recent_course_list), 1)
コード例 #8
0
    def test_recently_enrolled_courses(self):
        """
        Test if the function for filtering recent enrollments works appropriately.
        """
        config = DashboardConfiguration(recent_enrollment_time_delta=60)
        config.save()
        # get courses through iterating all courses
        courses_list = list(get_course_enrollment_pairs(
            self.student, None, []))
        self.assertEqual(len(courses_list), 2)

        recent_course_list = _get_recently_enrolled_courses(courses_list)
        self.assertEqual(len(recent_course_list), 1)
コード例 #9
0
    def test_enrollments_sorted_most_recent(self):
        """
        Test that the list of newly created courses are properly sorted to show the most
        recent enrollments first.

        """
        config = DashboardConfiguration(recent_enrollment_time_delta=600)
        config.save()

        # Create a number of new enrollments and courses, and force their creation behind
        # the first enrollment
        course_location = locator.CourseLocator('Org2', 'Course2', 'Run2')
        _, enrollment2 = self._create_course_and_enrollment(course_location)
        enrollment2.created = datetime.datetime.now(UTC) - datetime.timedelta(
            seconds=5)
        enrollment2.save()

        course_location = locator.CourseLocator('Org3', 'Course3', 'Run3')
        _, enrollment3 = self._create_course_and_enrollment(course_location)
        enrollment3.created = datetime.datetime.now(UTC) - datetime.timedelta(
            seconds=10)
        enrollment3.save()

        course_location = locator.CourseLocator('Org4', 'Course4', 'Run4')
        _, enrollment4 = self._create_course_and_enrollment(course_location)
        enrollment4.created = datetime.datetime.now(UTC) - datetime.timedelta(
            seconds=15)
        enrollment4.save()

        course_location = locator.CourseLocator('Org5', 'Course5', 'Run5')
        _, enrollment5 = self._create_course_and_enrollment(course_location)
        enrollment5.created = datetime.datetime.now(UTC) - datetime.timedelta(
            seconds=20)
        enrollment5.save()

        courses_list = list(get_course_enrollment_pairs(
            self.student, None, []))
        self.assertEqual(len(courses_list), 6)

        recent_course_list = _get_recently_enrolled_courses(courses_list)
        self.assertEqual(len(recent_course_list), 5)

        self.assertEqual(recent_course_list[1][1], enrollment2)
        self.assertEqual(recent_course_list[2][1], enrollment3)
        self.assertEqual(recent_course_list[3][1], enrollment4)
        self.assertEqual(recent_course_list[4][1], enrollment5)
コード例 #10
0
    def test_enrollments_sorted_most_recent(self):
        """
        Test that the list of newly created courses are properly sorted to show the most
        recent enrollments first.
        Also test recent enrollment message rendered appropriately for more than two courses.
        """
        self._configure_message_timeout(600)

        # Create a number of new enrollments and courses, and force their creation behind
        # the first enrollment
        courses = []
        for idx, seconds_past in zip(range(2, 6), [5, 10, 15, 20]):
            course_location = locator.CourseLocator(
                'Org{num}'.format(num=idx),
                'Course{num}'.format(num=idx),
                'Run{num}'.format(num=idx)
            )
            course, enrollment = self._create_course_and_enrollment(course_location)
            enrollment.created = datetime.datetime.now(UTC) - datetime.timedelta(seconds=seconds_past)
            enrollment.save()
            courses.append(course)

        courses_list = list(get_course_enrollments(self.student, None, []))
        self.assertEqual(len(courses_list), 6)

        recent_course_list = _get_recently_enrolled_courses(courses_list)
        self.assertEqual(len(recent_course_list), 5)

        self.assertEqual(recent_course_list[1].course.id, courses[0].id)
        self.assertEqual(recent_course_list[2].course.id, courses[1].id)
        self.assertEqual(recent_course_list[3].course.id, courses[2].id)
        self.assertEqual(recent_course_list[4].course.id, courses[3].id)

        self.client.login(username=self.student.username, password=self.PASSWORD)
        response = self.client.get(reverse("dashboard"))

        # verify recent enrollment message
        self.assertContains(
            response,
            'Thank you for enrolling in:'.format(course_name=self.course.display_name)
        )
        self.assertContains(
            response,
            ', '.join(enrollment.course.display_name for enrollment in recent_course_list)
        )
コード例 #11
0
    def test_enrollments_sorted_most_recent(self):
        """
        Test that the list of newly created courses are properly sorted to show the most
        recent enrollments first.
        Also test recent enrollment message rendered appropriately for more than two courses.
        """
        self._configure_message_timeout(600)

        # Create a number of new enrollments and courses, and force their creation behind
        # the first enrollment
        courses = []
        for idx, seconds_past in zip(range(2, 6), [5, 10, 15, 20]):
            course_location = locator.CourseLocator(
                'Org{num}'.format(num=idx), 'Course{num}'.format(num=idx),
                'Run{num}'.format(num=idx))
            course, enrollment = self._create_course_and_enrollment(
                course_location)
            enrollment.created = datetime.datetime.now(
                UTC) - datetime.timedelta(seconds=seconds_past)
            enrollment.save()
            courses.append(course)

        courses_list = list(get_course_enrollments(self.student, None, []))
        self.assertEqual(len(courses_list), 6)

        recent_course_list = _get_recently_enrolled_courses(courses_list)
        self.assertEqual(len(recent_course_list), 5)

        self.assertEqual(recent_course_list[1].course.id, courses[0].id)
        self.assertEqual(recent_course_list[2].course.id, courses[1].id)
        self.assertEqual(recent_course_list[3].course.id, courses[2].id)
        self.assertEqual(recent_course_list[4].course.id, courses[3].id)

        self.client.login(username=self.student.username,
                          password=self.PASSWORD)
        response = self.client.get(reverse("dashboard"))

        # verify recent enrollment message
        self.assertContains(
            response, 'Thank you for enrolling in:'.format(
                course_name=self.course.display_name))
        self.assertContains(
            response, ', '.join(enrollment.course.display_name
                                for enrollment in recent_course_list))
コード例 #12
0
    def test_enrollments_sorted_most_recent(self):
        """
        Test that the list of newly created courses are properly sorted to show the most
        recent enrollments first.

        """
        config = DashboardConfiguration(recent_enrollment_time_delta=600)
        config.save()

        # Create a number of new enrollments and courses, and force their creation behind
        # the first enrollment
        course_location = locator.CourseLocator('Org2', 'Course2', 'Run2')
        _, enrollment2 = self._create_course_and_enrollment(course_location)
        enrollment2.created = datetime.datetime.now(UTC) - datetime.timedelta(seconds=5)
        enrollment2.save()

        course_location = locator.CourseLocator('Org3', 'Course3', 'Run3')
        _, enrollment3 = self._create_course_and_enrollment(course_location)
        enrollment3.created = datetime.datetime.now(UTC) - datetime.timedelta(seconds=10)
        enrollment3.save()

        course_location = locator.CourseLocator('Org4', 'Course4', 'Run4')
        _, enrollment4 = self._create_course_and_enrollment(course_location)
        enrollment4.created = datetime.datetime.now(UTC) - datetime.timedelta(seconds=15)
        enrollment4.save()

        course_location = locator.CourseLocator('Org5', 'Course5', 'Run5')
        _, enrollment5 = self._create_course_and_enrollment(course_location)
        enrollment5.created = datetime.datetime.now(UTC) - datetime.timedelta(seconds=20)
        enrollment5.save()

        courses_list = list(get_course_enrollment_pairs(self.student, None, []))
        self.assertEqual(len(courses_list), 6)

        recent_course_list = _get_recently_enrolled_courses(courses_list)
        self.assertEqual(len(recent_course_list), 5)

        self.assertEqual(recent_course_list[1][1], enrollment2)
        self.assertEqual(recent_course_list[2][1], enrollment3)
        self.assertEqual(recent_course_list[3][1], enrollment4)
        self.assertEqual(recent_course_list[4][1], enrollment5)