コード例 #1
0
 def test_metric_aggregation(self, course_id, entity_type, event_type,
                             metric_display_name, expect_id_aggregation):
     """
     Verify that some metrics are counted by unique ID, while some are
     counted by total interactions.
     """
     create_engagement(course_id, self.DEFAULT_USERNAME, entity_type,
                       event_type, 'entity-id', 5)
     create_engagement(course_id, self.DEFAULT_USERNAME, entity_type,
                       event_type, 'entity-id', 5)
     expected_data = {
         'days': [{
             'date': '2015-01-01',
             'discussion_contributions': 0,
             'problems_attempted': 0,
             'problems_completed': 0,
             'videos_viewed': 0,
         }]
     }
     if expect_id_aggregation:
         expected_data['days'][0][metric_display_name] = 1
     else:
         expected_data['days'][0][metric_display_name] = 10
     path = self.path_template.format(self.DEFAULT_USERNAME,
                                      urlquote(course_id))
     response = self.authenticated_get(path)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.data, expected_data)
コード例 #2
0
 def test_day_gap(self, course_id):
     path = self.path_template.format(self.DEFAULT_USERNAME, urlquote(course_id))
     first_day = datetime.datetime(2015, 5, 26, tzinfo=pytz.utc)
     last_day = datetime.datetime(2015, 5, 28, tzinfo=pytz.utc)
     create_engagement(course_id, self.DEFAULT_USERNAME, VIDEO, VIEWED, 'id-1', 1, date=first_day)
     create_engagement(course_id, self.DEFAULT_USERNAME, PROBLEM, ATTEMPTED, 'id-2', 1, date=last_day)
     response = self.authenticated_get(path)
     self.assertEqual(response.status_code, 200)
     expected = {
         'days': [
             {
                 'date': '2015-05-26',
                 'discussion_contributions': 0,
                 'problems_attempted': 0,
                 'problems_completed': 0,
                 'videos_viewed': 1
             },
             {
                 'date': '2015-05-27',
                 'discussion_contributions': 0,
                 'problems_attempted': 0,
                 'problems_completed': 0,
                 'videos_viewed': 0
             },
             {
                 'date': '2015-05-28',
                 'discussion_contributions': 0,
                 'problems_attempted': 1,
                 'problems_completed': 0,
                 'videos_viewed': 0
             },
         ]
     }
     self.assertEqual(response.data, expected)
    def setUpClass(cls):
        super().setUpClass()

        cls.default_username = '******'
        cls.enterprise_customer_uuid = '5c0dd495-e726-46fa-a6a8-2d8d26c716c9'
        cls.path = f'/api/v0/enterprise/{cls.enterprise_customer_uuid}/engagements/'

        create_enterprise_user(cls.enterprise_customer_uuid,
                               cls.default_username)
        create_engagement(CourseSamples.course_ids[0], cls.default_username,
                          PROBLEM, ATTEMPTED, 'entity-id', 5)
        create_engagement(CourseSamples.course_ids[0], cls.default_username,
                          PROBLEM, COMPLETED, 'entity-id', 3)
        create_engagement(CourseSamples.course_ids[0], cls.default_username,
                          DISCUSSION, CONTRIBUTED, 'entity-id', 2)
        create_engagement(CourseSamples.course_ids[0], cls.default_username,
                          VIDEO, VIEWED, 'entity-id', 7)
コード例 #4
0
 def test_timeline(self, course_id):
     """
     Smoke test the learner engagement timeline.
     """
     path = self.path_template.format(self.DEFAULT_USERNAME,
                                      urlquote(course_id))
     day_one = datetime.datetime(2015, 1, 1, tzinfo=pytz.utc)
     day_two = datetime.datetime(2015, 1, 2, tzinfo=pytz.utc)
     create_engagement(course_id,
                       self.DEFAULT_USERNAME,
                       PROBLEM,
                       ATTEMPTED,
                       'id-1',
                       count=100,
                       date=day_one)
     create_engagement(course_id,
                       self.DEFAULT_USERNAME,
                       PROBLEM,
                       COMPLETED,
                       'id-2',
                       count=12,
                       date=day_one)
     create_engagement(course_id,
                       self.DEFAULT_USERNAME,
                       DISCUSSION,
                       CONTRIBUTED,
                       'id-3',
                       count=6,
                       date=day_one)
     create_engagement(course_id,
                       self.DEFAULT_USERNAME,
                       DISCUSSION,
                       CONTRIBUTED,
                       'id-4',
                       count=10,
                       date=day_two)
     create_engagement(course_id,
                       self.DEFAULT_USERNAME,
                       VIDEO,
                       VIEWED,
                       'id-5',
                       count=44,
                       date=day_two)
     create_engagement(course_id,
                       self.DEFAULT_USERNAME,
                       PROBLEM,
                       ATTEMPTED,
                       'id-6',
                       count=8,
                       date=day_two)
     create_engagement(course_id,
                       self.DEFAULT_USERNAME,
                       PROBLEM,
                       ATTEMPTED,
                       'id-7',
                       count=4,
                       date=day_two)
     response = self.authenticated_get(path)
     self.assertEqual(response.status_code, 200)
     expected = {
         'days': [
             {
                 'date': '2015-01-01',
                 'discussion_contributions': 6,
                 'problems_attempted': 1,
                 'problems_completed': 1,
                 'videos_viewed': 0
             },
             {
                 'date': '2015-01-02',
                 'discussion_contributions': 10,
                 'problems_attempted': 2,
                 'problems_completed': 0,
                 'videos_viewed': 1
             },
         ]
     }
     self.assertEqual(response.data, expected)
コード例 #5
0
    def test_get(self, course_id):
        activity_date_today = timezone.now()
        activity_date_more_than_7_days_ago = (timezone.now() -
                                              datetime.timedelta(days=9))
        create_engagement(course_id, 'user1', VIDEO, VIEWED, 'id-1', 3,
                          activity_date_today)
        create_engagement(course_id, 'user1', PROBLEM, ATTEMPTED, 'id-2', 4,
                          activity_date_today)
        create_engagement(course_id, 'user1', PROBLEM, COMPLETED, 'id-2', 4,
                          activity_date_more_than_7_days_ago)
        create_engagement(course_id, 'user1', DISCUSSION, CONTRIBUTED, 'id-3',
                          2, activity_date_today)
        create_engagement(course_id, 'user2', DISCUSSION, CONTRIBUTED, 'id-3',
                          2, activity_date_today)
        create_engagement(course_id, 'user2', DISCUSSION, CONTRIBUTED, 'id-3',
                          11, activity_date_more_than_7_days_ago)

        create_engagement(course_id, 'user3', PROBLEM, COMPLETED, 'id-4', 6,
                          activity_date_today)
        create_engagement(course_id, 'user3', PROBLEM, COMPLETED, 'id-4', 5,
                          activity_date_more_than_7_days_ago)
        create_engagement(course_id, 'user3', PROBLEM, COMPLETED, 'id-4', 4,
                          activity_date_more_than_7_days_ago)
        create_engagement(course_id, 'user3', PROBLEM, ATTEMPTED, 'id-4', 3,
                          activity_date_more_than_7_days_ago)

        activity_date_today = activity_date_today.strftime(
            settings.DATE_FORMAT)
        activity_date_more_than_7_days_ago = activity_date_more_than_7_days_ago.strftime(
            settings.DATE_FORMAT)

        response = self._get_data(course_id)
        self.assertEqual(response.status_code, 200)
        expected = [
            OrderedDict([('username', 'user1'), ('videos_overall', 3),
                         ('videos_last_week', 1), ('problems_overall', 8),
                         ('problems_last_week', 4),
                         ('correct_problems_overall', 4),
                         ('correct_problems_last_week', None),
                         ('problems_attempts_overall', 4),
                         ('problems_attempts_last_week', 4),
                         ('forum_posts_overall', 2),
                         ('forum_posts_last_week', 2),
                         ('date_last_active', activity_date_today)]),
            OrderedDict([('username', 'user2'), ('videos_overall', None),
                         ('videos_last_week', None),
                         ('problems_overall', None),
                         ('problems_last_week', None),
                         ('correct_problems_overall', None),
                         ('correct_problems_last_week', None),
                         ('problems_attempts_overall', None),
                         ('problems_attempts_last_week', None),
                         ('forum_posts_overall', 13),
                         ('forum_posts_last_week', 2),
                         ('date_last_active', activity_date_today)]),
            OrderedDict([('username', 'user3'), ('videos_overall', None),
                         ('videos_last_week', None), ('problems_overall', 18),
                         ('problems_last_week', 6),
                         ('correct_problems_overall', 15),
                         ('correct_problems_last_week', 6),
                         ('problems_attempts_overall', 3),
                         ('problems_attempts_last_week', None),
                         ('forum_posts_overall', None),
                         ('forum_posts_last_week', None),
                         ('date_last_active', activity_date_today)]),
        ]
        self.assertListEqual(response.data, expected)