From 1b60dea806e642de33c76d4de87d164df951f2c8 Mon Sep 17 00:00:00 2001 From: Bill Filler Date: Thu, 15 Nov 2018 16:21:52 -0500 Subject: [PATCH] modify completion percentage calculation to account for single component that is excluded/ignored --- openedx/core/lib/gating/api.py | 4 ++- openedx/core/lib/gating/tests/test_api.py | 40 +++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/openedx/core/lib/gating/api.py b/openedx/core/lib/gating/api.py index cc413192e1..7033998a1a 100644 --- a/openedx/core/lib/gating/api.py +++ b/openedx/core/lib/gating/api.py @@ -470,12 +470,14 @@ def get_subsection_completion_percentage(subsection_usage_key, user): block, 'completion_mode' ) + # always exclude html blocks (in addition to EXCLUDED blocks) for gating calculations + # See https://openedx.atlassian.net/browse/WL-1798 if completion_mode not in (CompletionMode.AGGREGATOR, CompletionMode.EXCLUDED) \ and not block.block_type == 'html': completable_blocks.append(block) if not completable_blocks: - return 0 + return 100 subsection_completion_total = 0 course_block_completions = BlockCompletion.get_course_completions(user, subsection_usage_key.course_key) for block in completable_blocks: diff --git a/openedx/core/lib/gating/tests/test_api.py b/openedx/core/lib/gating/tests/test_api.py index de49828280..66c8e7aea1 100644 --- a/openedx/core/lib/gating/tests/test_api.py +++ b/openedx/core/lib/gating/tests/test_api.py @@ -265,6 +265,46 @@ class TestGatingApi(ModuleStoreTestCase, MilestonesTestCaseMixin): completion_percentage = gating_api.get_subsection_completion_percentage(self.seq1.location, student) self.assertEqual(completion_percentage, expected_completion_percentage) + @data( + ('discussion', None, 100), + ('html', None, 100), + ('html', 1, 100), + ('problem', 1, 100), + ('problem', 0, 0), + ('openassessment', 1, 100), + ('openassessment', 0, 0), + ) + @unpack + @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') + def test_get_subsection_completion_percentage_single_component( + self, + component_type, + completed, + expected_completion_percentage + ): + """ + Test if gating_api.get_subsection_completion_percentage returns expected completion percentage + when only a single component in a vertical/unit + + Note: + html blocks and discussion blocks are ignored in calculations so should always return + 100% complete + """ + student = UserFactory(is_staff=False) + + component = ItemFactory.create( + parent_location=self.vertical.location, + category=component_type, + display_name='{} block'.format(component_type) + ) + + with patch.object(BlockCompletion, 'get_course_completions') as course_block_completions_mock: + course_block_completions_mock.return_value = { + component.location: completed, + } + 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): """