From 60d71ce581d1a47edcfc9393d60beeeda2fd797d Mon Sep 17 00:00:00 2001 From: Alex Dusenbery Date: Wed, 28 Mar 2018 16:35:00 -0400 Subject: [PATCH] EDUCATOR-2553 | Bump edx-completion to 0.1.4; Add feature-gating tests for completion. --- .../completion_integration/test_models.py | 2 +- .../completion_integration/test_waffle.py | 79 +++++++++++++++++++ requirements/edx/base.txt | 2 +- 3 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 openedx/tests/completion_integration/test_waffle.py diff --git a/openedx/tests/completion_integration/test_models.py b/openedx/tests/completion_integration/test_models.py index e1aa973705..f6e1624d66 100644 --- a/openedx/tests/completion_integration/test_models.py +++ b/openedx/tests/completion_integration/test_models.py @@ -2,7 +2,7 @@ Test models, managers, and validators. """ -from __future__ import absolute_import, division, print_function, unicode_literals +from __future__ import absolute_import, division, unicode_literals from completion import models, waffle from completion.test_utils import CompletionWaffleTestMixin, submit_completions_for_testing diff --git a/openedx/tests/completion_integration/test_waffle.py b/openedx/tests/completion_integration/test_waffle.py new file mode 100644 index 0000000000..963009896a --- /dev/null +++ b/openedx/tests/completion_integration/test_waffle.py @@ -0,0 +1,79 @@ +""" +Tests waffle mechanics and feature-gating for block completion features. +""" + +from __future__ import absolute_import, unicode_literals + +from completion import waffle +import ddt +from django.test import TestCase +import mock +from opaque_keys.edx.keys import CourseKey + +from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory, SiteConfigurationFactory +from openedx.core.djangoapps.waffle_utils.testutils import override_waffle_flag +from openedx.core.djangolib.testing.utils import skip_unless_lms + + +@skip_unless_lms +@ddt.ddt +class FeatureGatingTests(TestCase): + """ + Tests the logic of the completion feature-gating functions in the LMS. + """ + def setUp(self): + self.site = SiteFactory.create() + self.site_patcher = mock.patch('completion.waffle.get_current_site') + mocked_current_site = self.site_patcher.start() + mocked_current_site.return_value = self.site + + self.course_key = CourseKey.from_string('course-v1:edX+DemoX+Demo_Course') + + def tearDown(self): + self.site_patcher.stop() + + def _make_site_config(self, enable_feature): + site_config = SiteConfigurationFactory.create(site=self.site) + site_config.values[waffle.ENABLE_SITE_VISUAL_PROGRESS] = enable_feature + site_config.save() + + def test_site_disables_visual_progress_no_config(self): + assert waffle.site_disables_visual_progress() is False + + @ddt.data(True, False) + def test_site_disables_visual_progress_with_config(self, config_value): + self._make_site_config(config_value) + assert (not config_value) == waffle.site_disables_visual_progress() + + def test_visual_progress_gating_tracking_disabled(self): + with waffle.waffle().override(waffle.ENABLE_COMPLETION_TRACKING, False): + assert waffle.visual_progress_enabled(self.course_key) is False + + def test_visual_progress_gating_site_disabled(self): + self._make_site_config(False) + assert waffle.visual_progress_enabled(self.course_key) is False + + def test_visual_progress_gating_course_disabled(self): + self._make_site_config(True) + with waffle.waffle().override(waffle.ENABLE_COMPLETION_TRACKING, True): + with waffle.waffle().override(waffle.ENABLE_VISUAL_PROGRESS, False): + with override_waffle_flag(waffle.waffle_flag(), active=False): + assert waffle.visual_progress_enabled(self.course_key) is False + + def test_visual_progress_happy_path_no_site_config(self): + with waffle.waffle().override(waffle.ENABLE_COMPLETION_TRACKING, True): + with waffle.waffle().override(waffle.ENABLE_VISUAL_PROGRESS, True): + assert waffle.visual_progress_enabled(self.course_key) is True + + def test_visual_progress_happy_path_with_site_config(self): + self._make_site_config(True) + with waffle.waffle().override(waffle.ENABLE_COMPLETION_TRACKING, True): + with waffle.waffle().override(waffle.ENABLE_VISUAL_PROGRESS, True): + assert waffle.visual_progress_enabled(self.course_key) is True + + def test_visual_progress_happy_path_visual_switch_disabled(self): + self._make_site_config(True) + with waffle.waffle().override(waffle.ENABLE_COMPLETION_TRACKING, True): + with waffle.waffle().override(waffle.ENABLE_VISUAL_PROGRESS, False): + with override_waffle_flag(waffle.waffle_flag(), active=True): + assert waffle.visual_progress_enabled(self.course_key) is True diff --git a/requirements/edx/base.txt b/requirements/edx/base.txt index 076de35d33..88bdee2d0a 100644 --- a/requirements/edx/base.txt +++ b/requirements/edx/base.txt @@ -54,7 +54,7 @@ edx-lint==0.5.4 git+https://github.com/cpennington/pylint-django@fix-field-inference-during-monkey-patching#egg=pylint-django==0.0 enum34==1.1.6 -edx-completion==0.1.1 +edx-completion==0.1.4 edx-django-oauth2-provider==1.2.5 edx-django-sites-extensions==2.3.1 edx-enterprise==0.67.0