Ejemplo n.º 1
0
    def test_all_courses(self):
        """
        Verifies that we can calculate over all courses
        """

        course2 = CourseFactory.create(org='foo', course='bar', run='baz')

        CourseEnrollment.enroll(self.user, course2.id)

        self.assertEqual(CourseEnrollment.objects.filter(course_id=course2.id).count(), 1)

        with patch('social_engagement.engagement._get_user_social_stats') as mock_func:
            mock_func.return_value = {
                'num_threads': 1,
                'num_comments': 1,
                'num_replies': 1,
                'num_upvotes': 1,
                'num_thread_followers': 1,
                'num_comments_generated': 1,
            }

            # update whole course and re-calc
            update_all_courses_engagement_scores()

        leaderboard = StudentSocialEngagementScore.generate_leaderboard(self.course.id)
        self.assertEqual(len(leaderboard), 2)

        leaderboard = StudentSocialEngagementScore.generate_leaderboard(course2.id)
        self.assertEqual(len(leaderboard), 1)
    def test_closed_course(self, store):
        """
        Make sure we can force update closed course
        """

        course2 = CourseFactory.create(
            org='foo',
            course='bar',
            run='baz',
            end=datetime.now(pytz.UTC) - timedelta(days=1),
            default_store=store
        )

        CourseEnrollment.enroll(self.user, course2.id)
        CourseEnrollment.enroll(self.user2, course2.id)

        with patch('social_engagement.engagement._get_course_social_stats') as mock_func:
            mock_func.return_value = ((user_id, self.DEFAULT_STATS) for user_id in self.user_ids)
            # update whole course and re-calc
            update_course_engagement(course2.id, compute_if_closed_course=False)

            # shouldn't be anything in there because course is closed
            data = StudentSocialEngagementScore.generate_leaderboard(course2.id)
            self.assertEqual(len(data['queryset']), 0)
            self.assertEqual(data['course_avg'], 0)

            mock_func.return_value = ((user_id, self.DEFAULT_STATS) for user_id in self.user_ids)
            # update whole course and re-calc
            update_course_engagement(course2.id, compute_if_closed_course=True)

            # shouldn't be anything in there because course is closed
            data = StudentSocialEngagementScore.generate_leaderboard(course2.id)
            self.assertEqual(len(data['queryset']), 2)
            self.assertEqual(data['course_avg'], 85)
Ejemplo n.º 3
0
    def test_management_command_course(self):
        """
        Verify that we get None back
        """

        self.assertIsNone(StudentSocialEngagementScore.get_user_engagement_score(self.course.id, self.user.id))
        self.assertIsNone(StudentSocialEngagementScore.get_user_engagement_score(self.course.id, self.user2.id))

        self.assertEqual(get_notifications_count_for_user(self.user.id), 0)
        self.assertEqual(get_notifications_count_for_user(self.user2.id), 0)

        with patch('social_engagement.engagement._get_user_social_stats') as mock_func:
            mock_func.return_value = {
                'num_threads': 1,
                'num_comments': 1,
                'num_replies': 1,
                'num_upvotes': 1,
                'num_thread_followers': 1,
                'num_comments_generated': 1,
            }

            Command().handle(course_ids=[self.course.id])

            # shouldn't be anything in there because course is closed
            leaderboard = StudentSocialEngagementScore.generate_leaderboard(self.course.id)
            self.assertEqual(len(leaderboard), 2)

            leaderboard = StudentSocialEngagementScore.generate_leaderboard(self.course2.id)
            self.assertEqual(len(leaderboard), 0)

            self.assertEqual(get_notifications_count_for_user(self.user.id), 0)
            self.assertEqual(get_notifications_count_for_user(self.user2.id), 0)
Ejemplo n.º 4
0
    def test_all_courses(self, store):
        """
        Verifies that we can calculate over all courses
        """

        course2 = CourseFactory.create(org='foo',
                                       course='bar',
                                       run='baz',
                                       default_store=store)

        CourseEnrollment.enroll(self.user, course2.id)

        self.assertEqual(
            CourseEnrollment.objects.filter(course_id=course2.id).count(), 1)

        for course in (self.course, course2):
            with patch('social_engagement.engagement._get_course_social_stats'
                       ) as mock_func:
                mock_func.return_value = ((user_id, self.DEFAULT_STATS)
                                          for user_id in self.user_ids)
                # update whole course and re-calc
                update_course_engagement(course.id)

        data = StudentSocialEngagementScore.generate_leaderboard(
            self.course.id)
        self.assertEqual(len(data['queryset']), 2)
        self.assertEqual(data['course_avg'], 85)

        data = StudentSocialEngagementScore.generate_leaderboard(course2.id)
        self.assertEqual(len(data['queryset']), 1)
        self.assertEqual(data['course_avg'], 85)
Ejemplo n.º 5
0
    def test_no_engagment_records(self):
        """
        Verify that we get None back
        """

        self.assertIsNone(StudentSocialEngagementScore.get_user_engagement_score(self.course.id, self.user.id))
        self.assertIsNone(StudentSocialEngagementScore.get_user_engagement_score(self.course.id, self.user2.id))

        # no entries, means a rank of 0!
        self.assertEqual(
            StudentSocialEngagementScore.get_user_leaderboard_position(
                self.course.id,
                self.user.id
            )['score'],
            0
        )

        self.assertEqual(
            StudentSocialEngagementScore.get_user_leaderboard_position(
                self.course.id,
                self.user.id
            )['position'],
            0
        )

        self.assertFalse(
            StudentSocialEngagementScore.generate_leaderboard(self.course.id)
        )
    def test_closed_course(self, store):
        """
        Make sure we can force update closed course
        """

        course2 = CourseFactory.create(org='foo',
                                       course='bar',
                                       run='baz',
                                       end=datetime.now(pytz.UTC) -
                                       timedelta(days=1),
                                       default_store=store)

        CourseEnrollment.enroll(self.user, course2.id)
        CourseEnrollment.enroll(self.user2, course2.id)

        with patch('social_engagement.engagement._get_user_social_stats'
                   ) as mock_func:
            mock_func.return_value = {
                'num_threads': 1,
                'num_comments': 1,
                'num_replies': 1,
                'num_upvotes': 1,
                'num_thread_followers': 1,
                'num_comments_generated': 1,
            }

            # update whole course and re-calc
            update_all_courses_engagement_scores()

            # shouldn't be anything in there because course is closed
            course_avg, enrollment_count, leaderboard = StudentSocialEngagementScore.generate_leaderboard(
                course2.id)
            self.assertEqual(len(leaderboard), 0)
            self.assertEqual(course_avg, 0)

            # update whole course and re-calc
            update_all_courses_engagement_scores(compute_if_closed_course=True)

            # shouldn't be anything in there because course is closed
            course_avg, enrollment_count, leaderboard = StudentSocialEngagementScore.generate_leaderboard(
                course2.id)
            self.assertEqual(len(leaderboard), 2)
            self.assertEqual(course_avg, 85)
Ejemplo n.º 7
0
    def test_closed_course(self, store):
        """
        Make sure we can force update closed course
        """

        course2 = CourseFactory.create(org='foo',
                                       course='bar',
                                       run='baz',
                                       end=datetime.now(pytz.UTC) -
                                       timedelta(days=1),
                                       default_store=store)

        CourseEnrollment.enroll(self.user, course2.id)
        CourseEnrollment.enroll(self.user2, course2.id)

        with patch('social_engagement.engagement._get_course_social_stats'
                   ) as mock_func:
            mock_func.return_value = ((user_id, self.DEFAULT_STATS)
                                      for user_id in self.user_ids)
            # update whole course and re-calc
            update_course_engagement(course2.id,
                                     compute_if_closed_course=False)

            # shouldn't be anything in there because course is closed
            data = StudentSocialEngagementScore.generate_leaderboard(
                course2.id)
            self.assertEqual(len(data['queryset']), 0)
            self.assertEqual(data['course_avg'], 0)

            mock_func.return_value = ((user_id, self.DEFAULT_STATS)
                                      for user_id in self.user_ids)
            # update whole course and re-calc
            update_course_engagement(course2.id, compute_if_closed_course=True)

            # shouldn't be anything in there because course is closed
            data = StudentSocialEngagementScore.generate_leaderboard(
                course2.id)
            self.assertEqual(len(data['queryset']), 2)
            self.assertEqual(data['course_avg'], 85)
    def test_calc_course(self):
        """
        Verifies that we can calculate the whole course enrollments
        """

        with patch('social_engagement.engagement._get_course_social_stats') as mock_func:
            mock_func.return_value = ((user_id, self.DEFAULT_STATS) for user_id in self.user_ids)
            # update whole course and re-calc
            update_course_engagement(self.course.id)

        data = StudentSocialEngagementScore.generate_leaderboard(self.course.id)

        self.assertEqual(len(data['queryset']), 2)
    def test_all_courses(self, store):
        """
        Verifies that we can calculate over all courses
        """

        course2 = CourseFactory.create(org='foo',
                                       course='bar',
                                       run='baz',
                                       default_store=store)

        CourseEnrollment.enroll(self.user, course2.id)

        self.assertEqual(
            CourseEnrollment.objects.filter(course_id=course2.id).count(), 1)

        with patch('social_engagement.engagement._get_user_social_stats'
                   ) as mock_func:
            mock_func.return_value = {
                'num_threads': 1,
                'num_comments': 1,
                'num_replies': 1,
                'num_upvotes': 1,
                'num_thread_followers': 1,
                'num_comments_generated': 1,
            }

            # update whole course and re-calc
            update_all_courses_engagement_scores()

        course_avg, enrollment_count, leaderboard = StudentSocialEngagementScore.generate_leaderboard(
            self.course.id)
        self.assertEqual(len(leaderboard), 2)
        self.assertEqual(course_avg, 85)

        course_avg, enrollment_count, leaderboard = StudentSocialEngagementScore.generate_leaderboard(
            course2.id)
        self.assertEqual(len(leaderboard), 1)
        self.assertEqual(course_avg, 85)
Ejemplo n.º 10
0
    def test_closed_course(self):
        """
        Make sure we can force update closed course
        """

        course2 = CourseFactory.create(
            org='foo',
            course='bar',
            run='baz',
            end=datetime.now(pytz.UTC) - timedelta(days=1)
        )

        CourseEnrollment.enroll(self.user, course2.id)
        CourseEnrollment.enroll(self.user2, course2.id)

        with patch('social_engagement.engagement._get_user_social_stats') as mock_func:
            mock_func.return_value = {
                'num_threads': 1,
                'num_comments': 1,
                'num_replies': 1,
                'num_upvotes': 1,
                'num_thread_followers': 1,
                'num_comments_generated': 1,
            }

            # update whole course and re-calc
            update_all_courses_engagement_scores()

            # shouldn't be anything in there because course is closed
            leaderboard = StudentSocialEngagementScore.generate_leaderboard(course2.id)
            self.assertEqual(len(leaderboard), 0)

            # update whole course and re-calc
            update_all_courses_engagement_scores(compute_if_closed_course=True)

            # shouldn't be anything in there because course is closed
            leaderboard = StudentSocialEngagementScore.generate_leaderboard(course2.id)
            self.assertEqual(len(leaderboard), 2)
    def test_update_engagement_score(self):
        """
        Basic update operation
        """

        self.assertEqual(get_notifications_count_for_user(self.user.id), 0)

        StudentSocialEngagementScore.save_user_engagement_score(self.course.id, self.user.id, 10)

        # then update
        StudentSocialEngagementScore.save_user_engagement_score(self.course.id, self.user.id, 20)

        # read it back
        self.assertEqual(
            StudentSocialEngagementScore.get_user_leaderboard_position(
                self.course.id,
                user_id=self.user.id
            )['score'],
            20
        )

        # confirm there are two entries in the History table
        self.assertEqual(
            StudentSocialEngagementScoreHistory.objects.filter(
                course_id=self.course.id,
                user__id=self.user.id
            ).count(),
            2
        )

        self.assertEqual(
            StudentSocialEngagementScore.get_user_leaderboard_position(
                self.course.id,
                user_id=self.user.id
            )['position'],
            1
        )

        # look at the leaderboard
        data = StudentSocialEngagementScore.generate_leaderboard(self.course.id)
        self.assertIsNotNone(data['queryset'])
        self.assertEqual(len(data['queryset']), 1)
        self.assertEqual(data['total_user_count'], 2)
        self.assertEqual(data['course_avg'], 10)

        self.assertEqual(data['queryset'][0].user.id, self.user.id)
        self.assertEqual(data['queryset'][0].score, 20)

        # confirm there is a just a single notification was generated
        self.assertEqual(get_notifications_count_for_user(self.user.id), 1)
    def test_all_courses(self, store):
        """
        Verifies that we can calculate over all courses
        """

        course2 = CourseFactory.create(org='foo', course='bar', run='baz', default_store=store)

        CourseEnrollment.enroll(self.user, course2.id)

        self.assertEqual(CourseEnrollment.objects.filter(course_id=course2.id).count(), 1)

        for course in (self.course, course2):
            with patch('social_engagement.engagement._get_course_social_stats') as mock_func:
                mock_func.return_value = ((user_id, self.DEFAULT_STATS) for user_id in self.user_ids)
                # update whole course and re-calc
                update_course_engagement(course.id)

        data = StudentSocialEngagementScore.generate_leaderboard(self.course.id)
        self.assertEqual(len(data['queryset']), 2)
        self.assertEqual(data['course_avg'], 85)

        data = StudentSocialEngagementScore.generate_leaderboard(course2.id)
        self.assertEqual(len(data['queryset']), 1)
        self.assertEqual(data['course_avg'], 85)
Ejemplo n.º 13
0
    def test_calc_course(self):
        """
        Verifies that we can calculate the whole course enrollments
        """

        with patch('social_engagement.engagement._get_course_social_stats'
                   ) as mock_func:
            mock_func.return_value = ((user_id, self.DEFAULT_STATS)
                                      for user_id in self.user_ids)
            # update whole course and re-calc
            update_course_engagement(self.course.id)

        data = StudentSocialEngagementScore.generate_leaderboard(
            self.course.id)

        self.assertEqual(len(data['queryset']), 2)
Ejemplo n.º 14
0
    def test_save_first_engagement_score(self):
        """
        Basic write operation
        """

        self.assertEqual(get_notifications_count_for_user(self.user.id), 0)

        StudentSocialEngagementScore.save_user_engagement_score(self.course.id, self.user.id, 10)

        # read it back
        self.assertEqual(
            StudentSocialEngagementScore.get_user_leaderboard_position(
                self.course.id,
                self.user.id
            )['score'],
            10
        )

        # confirm there is an entry in the History table
        self.assertEqual(
            StudentSocialEngagementScoreHistory.objects.filter(
                course_id=self.course.id,
                user__id=self.user.id
            ).count(),
            1
        )

        self.assertEqual(
            StudentSocialEngagementScore.get_user_leaderboard_position(
                self.course.id,
                self.user.id
            )['position'],
            1
        )

        # look at the leaderboard
        leaderboard = StudentSocialEngagementScore.generate_leaderboard(self.course.id)
        self.assertIsNotNone(leaderboard)
        self.assertEqual(len(leaderboard), 1)

        self.assertEqual(leaderboard[0]['user__id'], self.user.id)
        self.assertEqual(leaderboard[0]['score'], 10)

        # confirm there is a notification was generated
        self.assertEqual(get_notifications_count_for_user(self.user.id), 1)
    def test_update_engagement_score(self):
        """
        Basic update operation
        """

        self.assertEqual(get_notifications_count_for_user(self.user.id), 0)

        StudentSocialEngagementScore.save_user_engagement_score(
            self.course.id, self.user.id, 10)

        # then update
        StudentSocialEngagementScore.save_user_engagement_score(
            self.course.id, self.user.id, 20)

        # read it back
        self.assertEqual(
            StudentSocialEngagementScore.get_user_leaderboard_position(
                self.course.id, self.user.id)['score'], 20)

        # confirm there are two entries in the History table
        self.assertEqual(
            StudentSocialEngagementScoreHistory.objects.filter(
                course_id=self.course.id, user__id=self.user.id).count(), 2)

        self.assertEqual(
            StudentSocialEngagementScore.get_user_leaderboard_position(
                self.course.id, self.user.id)['position'], 1)

        # look at the leaderboard
        course_avg, enrollment_count, leaderboard = StudentSocialEngagementScore.generate_leaderboard(
            self.course.id)
        self.assertIsNotNone(leaderboard)
        self.assertEqual(len(leaderboard), 1)
        self.assertEqual(enrollment_count, 2)
        self.assertEqual(course_avg, 10)

        self.assertEqual(leaderboard[0]['user__id'], self.user.id)
        self.assertEqual(leaderboard[0]['score'], 20)

        # confirm there is a just a single notification was generated
        self.assertEqual(get_notifications_count_for_user(self.user.id), 1)
Ejemplo n.º 16
0
    def test_calc_course(self):
        """
        Verifies that we can calculate the whole course enrollments
        """

        with patch('social_engagement.engagement._get_user_social_stats') as mock_func:
            mock_func.return_value = {
                'num_threads': 1,
                'num_comments': 1,
                'num_replies': 1,
                'num_upvotes': 1,
                'num_thread_followers': 1,
                'num_comments_generated': 1,
            }

            # update whole course and re-calc
            update_course_engagement_scores(self.course.id)

        leaderboard = StudentSocialEngagementScore.generate_leaderboard(self.course.id)

        self.assertEqual(len(leaderboard), 2)
Ejemplo n.º 17
0
    def test_no_engagment_records(self):
        """
        Verify that we get None back
        """

        self.assertIsNone(
            StudentSocialEngagementScore.get_user_engagement_score(
                self.course.id, self.user.id))
        self.assertIsNone(
            StudentSocialEngagementScore.get_user_engagement_score(
                self.course.id, self.user2.id))

        # no entries, means a rank of 0!
        result = StudentSocialEngagementScore.get_user_leaderboard_position(
            self.course.id, user_id=self.user.id)

        self.assertEqual(result['score'], 0)
        self.assertEqual(result['position'], 0)

        self.assertEqual(
            StudentSocialEngagementScore.generate_leaderboard(
                self.course.id)['total_user_count'], 0)
    def test_calc_course(self):
        """
        Verifies that we can calculate the whole course enrollments
        """

        with patch('social_engagement.engagement._get_user_social_stats'
                   ) as mock_func:
            mock_func.return_value = {
                'num_threads': 1,
                'num_comments': 1,
                'num_replies': 1,
                'num_upvotes': 1,
                'num_thread_followers': 1,
                'num_comments_generated': 1,
            }

            # update whole course and re-calc
            update_course_engagement_scores(self.course.id)

        course_avg, enrollment_count, leaderboard = StudentSocialEngagementScore.generate_leaderboard(
            self.course.id)

        self.assertEqual(len(leaderboard), 2)
Ejemplo n.º 19
0
    def test_save_first_engagement_score(self):
        """
        Basic write operation
        """

        self.assertEqual(get_notifications_count_for_user(self.user.id), 0)

        StudentSocialEngagementScore.save_user_engagement_score(
            self.course.id, self.user.id, 10)

        # read it back
        self.assertEqual(
            StudentSocialEngagementScore.get_user_leaderboard_position(
                self.course.id, user_id=self.user.id)['score'], 10)

        # confirm there is an entry in the History table
        self.assertEqual(
            StudentSocialEngagementScoreHistory.objects.filter(
                course_id=self.course.id, user__id=self.user.id).count(), 1)

        self.assertEqual(
            StudentSocialEngagementScore.get_user_leaderboard_position(
                self.course.id, user_id=self.user.id)['position'], 1)

        # look at the leaderboard
        data = StudentSocialEngagementScore.generate_leaderboard(
            self.course.id)
        self.assertIsNotNone(data['queryset'])
        self.assertEqual(len(data['queryset']), 1)
        self.assertEqual(data['total_user_count'], 2)
        self.assertEqual(data['course_avg'], 5)

        self.assertEqual(data['queryset'][0].user.id, self.user.id)
        self.assertEqual(data['queryset'][0].score, 10)

        # confirm there is a notification was generated
        self.assertEqual(get_notifications_count_for_user(self.user.id), 1)