示例#1
0
    def test_partial_updates(self):
        instant = now()
        completion = BlockCompletion.objects.create(
            user=self.user,
            context_key=self.course_key,
            block_key=self.blocks[4],
            completion=0.75,
            modified=instant,
        )

        updater = AggregationUpdater(self.user, self.course_key,
                                     mock.MagicMock())
        updater.update(changed_blocks={self.blocks[4]})
        course_agg = Aggregator.objects.get(course_key=self.course_key,
                                            block_key=self.blocks[0])
        chap1_agg = Aggregator.objects.get(course_key=self.course_key,
                                           block_key=self.blocks[1])
        chap2_agg = Aggregator.objects.get(course_key=self.course_key,
                                           block_key=self.blocks[2])
        self.assertEqual(chap1_agg.earned, 0.75)
        self.assertEqual(chap1_agg.last_modified, completion.modified)
        self.assertEqual(chap2_agg.earned, 0.0)
        self.assertEqual(chap2_agg.last_modified, OLD_DATETIME)
        self.assertEqual(course_agg.earned, 0.75)
        self.assertEqual(course_agg.last_modified, completion.modified)
 def test_blockstructure_caching(self):
     mock_modulestore = mock.MagicMock()
     updater = AggregationUpdater(self.user, self.course_key, mock_modulestore)
     updater.calculate_updated_aggregators()
     mock_modulestore.bulk_operations.assert_called_once()
     mock_modulestore.bulk_operations.reset_mock()
     updater.calculate_updated_aggregators()
     mock_modulestore.bulk_operations.assert_not_called()
示例#3
0
    def setUp(self):
        """
        For the purpose of the tests, we will use the following course
        structure:

                        course
                          |
                +--+---+--^-+----+----+
               /   |   |    |    |     \\
            html html html html other hidden
                                /   \\
                              html hidden

        where `course` and `other` are a completion_mode of AGGREGATOR (but
        only `course` is registered to store aggregations), `html` is
        COMPLETABLE, and `hidden` is EXCLUDED.
        """
        super(AggregationUpdaterTestCase, self).setUp()
        self.agg_modified = now() - timedelta(days=1)
        course_key = CourseKey.from_string('course-v1:edx+course+test')
        stubcompat = StubCompat([
            course_key.make_usage_key('course', 'course'),
            course_key.make_usage_key('html', 'course-html0'),
            course_key.make_usage_key('html', 'course-html1'),
            course_key.make_usage_key('html', 'course-html2'),
            course_key.make_usage_key('html', 'course-html3'),
            course_key.make_usage_key('other', 'course-other'),
            course_key.make_usage_key('hidden', 'course-hidden0'),
            course_key.make_usage_key('html', 'course-other-html4'),
            course_key.make_usage_key('hidden', 'course-other-hidden1'),
        ])
        for compat_module in 'completion_aggregator.core.compat', 'completion_aggregator.core.compat':
            patch = mock.patch(compat_module, stubcompat)
            patch.start()
            self.addCleanup(patch.stop)
        user = get_user_model().objects.create(username='******')
        self.course_key = CourseKey.from_string('course-v1:edx+course+test')
        self.agg, _ = Aggregator.objects.submit_completion(
            user=user,
            course_key=self.course_key,
            block_key=self.course_key.make_usage_key('course', 'course'),
            aggregation_name='course',
            earned=0.0,
            possible=0.0,
            last_modified=self.agg_modified,
        )
        BlockCompletion.objects.create(
            user=user,
            context_key=self.course_key,
            block_key=self.course_key.make_usage_key('html',
                                                     'course-other-html4'),
            completion=1.0,
            modified=now(),
        )
        self.updater = AggregationUpdater(user, self.course_key,
                                          mock.MagicMock())
示例#4
0
 def _get_updater(self):
     """
     Return a fresh instance of an AggregationUpdater.
     """
     return AggregationUpdater(self.user, self.course_key, mock.MagicMock())
示例#5
0
 def aggregate_course(self, user, course_key):
     updater = AggregationUpdater(user=user, course_key=course_key, modulestore=self.store)
     updater.update(force=True)