def test_blocks_to_mark_complete_on_view(self): completable_block_1 = XBlock(Mock(), scope_ids=Mock(spec=ScopeIds)) completable_block_1.location = UsageKey.from_string( "i4x://edX/100/a/1").replace(course_key=self.course_key) completable_block_2 = XBlock(Mock(), scope_ids=Mock(spec=ScopeIds)) completable_block_2.location = UsageKey.from_string( "i4x://edX/100/a/2").replace(course_key=self.course_key) aggregator_block = XBlock(Mock(), scope_ids=Mock(spec=ScopeIds)) aggregator_block.location = UsageKey.from_string( "i4x://edX/100/a/3").replace(course_key=self.course_key) aggregator_block.completion_mode = XBlockCompletionMode.AGGREGATOR self.assertSetEqual( self.completion_service.blocks_to_mark_complete_on_view({}), set()) self.assertSetEqual( self.completion_service.blocks_to_mark_complete_on_view( {aggregator_block}), set()) self.assertSetEqual( self.completion_service.blocks_to_mark_complete_on_view( {completable_block_1, completable_block_2, aggregator_block}), {completable_block_1, completable_block_2}) BlockCompletion.objects.submit_completion( user=self.user, course_key=self.course_key, block_key=completable_block_2.location, completion=1.0) self.assertSetEqual( self.completion_service.blocks_to_mark_complete_on_view( {completable_block_1, completable_block_2, aggregator_block}), {completable_block_1}) BlockCompletion.objects.submit_completion( user=self.user, course_key=self.course_key, block_key=completable_block_1.location, completion=1.0) self.assertSetEqual( self.completion_service.blocks_to_mark_complete_on_view( {completable_block_1, completable_block_2, aggregator_block}), set())
def test_submit_completion(self): completable_block = XBlock(Mock(), scope_ids=Mock(spec=ScopeIds)) completable_block.location = UsageKey.from_string( "i4x://edX/100/a/1").replace(course_key=self.course_key) service = CompletionService(self.user, self.course_key) service.submit_completion(completable_block.location, 0.75) self.assertEqual( BlockCompletion.objects.get( block_key=completable_block.location).completion, 0.75)
def test_submit_group_completion_by_user_ids(self): third_user = UserFactory.create() completable_block = XBlock(Mock(), scope_ids=Mock(spec=ScopeIds)) completable_block.location = UsageKey.from_string("i4x://edX/100/a/1").replace(course_key=self.course_key) service = CompletionService(self.user, self.course_key) service.submit_group_completion( block_key=completable_block.location, completion=0.25, user_ids=[self.other_user.id, third_user.id], ) completions = list(BlockCompletion.objects.filter(block_key=completable_block.location)) self.assertEqual(len(completions), 2) self.assertTrue(all(bc.completion == 0.25 for bc in completions)) self.assertEqual({bc.user for bc in completions}, {self.other_user, third_user})