From c7a8ddedead3c88d0c4b3e1b54c025f5bb895653 Mon Sep 17 00:00:00 2001 From: Hammad Ahmad Waqas Date: Tue, 2 Oct 2018 14:08:27 +0500 Subject: [PATCH] excluding html blocks form adding in computable blocks for completion --- openedx/core/lib/gating/api.py | 3 +- openedx/core/lib/gating/tests/test_api.py | 43 +++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/openedx/core/lib/gating/api.py b/openedx/core/lib/gating/api.py index c4bc6ab7c5..cc413192e1 100644 --- a/openedx/core/lib/gating/api.py +++ b/openedx/core/lib/gating/api.py @@ -470,7 +470,8 @@ def get_subsection_completion_percentage(subsection_usage_key, user): block, 'completion_mode' ) - if completion_mode not in (CompletionMode.AGGREGATOR, CompletionMode.EXCLUDED): + if completion_mode not in (CompletionMode.AGGREGATOR, CompletionMode.EXCLUDED) \ + and not block.block_type == 'html': completable_blocks.append(block) if not completable_blocks: diff --git a/openedx/core/lib/gating/tests/test_api.py b/openedx/core/lib/gating/tests/test_api.py index 122f0e8202..bac3a1ac86 100644 --- a/openedx/core/lib/gating/tests/test_api.py +++ b/openedx/core/lib/gating/tests/test_api.py @@ -3,6 +3,7 @@ Tests for the gating API """ import unittest +from completion.models import BlockCompletion from mock import patch, Mock from ddt import ddt, data, unpack from django.conf import settings @@ -60,6 +61,13 @@ class TestGatingApi(ModuleStoreTestCase, MilestonesTestCaseMixin): display_name='untitled sequential 2' ) + # create vertical + self.vertical = ItemFactory.create( + parent_location=self.seq1.location, + category='vertical', + display_name='untitled vertical 1' + ) + self.generic_milestone = { 'name': 'Test generic milestone', 'namespace': unicode(self.seq1.location), @@ -221,6 +229,41 @@ class TestGatingApi(ModuleStoreTestCase, MilestonesTestCaseMixin): gating_api.is_gate_fulfilled(self.course.id, self.seq1.location, student.id), is_gate_fulfilled ) + @data( + (1, 1, 100), + (0, 0, 0), + (1, 0, 100), + (0, 1, 0), + ) + @unpack + def test_get_subsection_completion_percentage(self, user_problem_completion, user_html_completion, + expected_completion_percentage): + """ + Test if gating_api.get_subsection_completion_percentage returns expected completion percentage + + Note: + html blocks are ignored in computation of completion_percentage,so it should not affect result. + + """ + student = UserFactory(is_staff=False) + problem_block = ItemFactory.create( + parent_location=self.vertical.location, + category='problem', + display_name='some problem' + ) + html_block = ItemFactory.create( + parent_location=self.vertical.location, + category='html', + display_name='some html block' + ) + with patch.object(BlockCompletion, 'get_course_completions') as course_block_completions_mock: + course_block_completions_mock.return_value = { + problem_block.location: user_problem_completion, + html_block.location: user_html_completion, + } + completion_percentage = gating_api.get_subsection_completion_percentage(self.seq1.location, student) + self.assertEqual(completion_percentage, expected_completion_percentage) + @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') def test_compute_is_prereq_met(self): """