Deprecate WaffleSwitch.override* methods

This allows us to get rid of the custom WaffleSwitch and
WaffleSwitchNamespace classes from waffle_utils in favour of
edx_toggles.toggles classes.
This commit is contained in:
Régis Behmo
2020-10-23 13:06:12 +02:00
parent 2307dff4c9
commit 3b127f8c92
26 changed files with 159 additions and 203 deletions

View File

@@ -4,7 +4,12 @@ waffle switches for the Grades app.
"""
from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag, WaffleFlagNamespace, WaffleSwitchNamespace
from openedx.core.djangoapps.waffle_utils import (
CourseWaffleFlag,
WaffleFlagNamespace,
WaffleSwitch,
WaffleSwitchNamespace
)
# Namespace
WAFFLE_NAMESPACE = u'grades'
@@ -81,6 +86,16 @@ def waffle():
return WaffleSwitchNamespace(name=WAFFLE_NAMESPACE, log_prefix=u'Grades: ')
def waffle_switch(name):
"""
Return the corresponding namespaced waffle switch.
WARNING: do not replicate this pattern. Instead of declaring waffle switch names as strings, you should create
WaffleSwitch objects as top-level constants.
"""
return WaffleSwitch(waffle(), name, module_name=__name__)
def waffle_flags():
"""
Returns the namespaced, cached, audited Waffle flags dictionary for Grades.

View File

@@ -4,13 +4,14 @@ from crum import set_current_request
from django.conf import settings
from mock import patch
from edx_toggles.toggles.testutils import override_waffle_switch
from openedx.core.djangolib.testing.utils import get_mock_request
from student.models import CourseEnrollment
from student.tests.factories import UserFactory
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from ..config.waffle import ASSUME_ZERO_GRADE_IF_ABSENT, waffle
from ..config.waffle import ASSUME_ZERO_GRADE_IF_ABSENT, waffle_switch
from ..course_data import CourseData
from ..course_grade import ZeroCourseGrade
from ..course_grade_factory import CourseGradeFactory
@@ -31,7 +32,7 @@ class ZeroGradeTest(GradeTestBase):
"""
Creates a ZeroCourseGrade and ensures it's empty.
"""
with waffle().override(ASSUME_ZERO_GRADE_IF_ABSENT, active=assume_zero_enabled):
with override_waffle_switch(waffle_switch(ASSUME_ZERO_GRADE_IF_ABSENT), active=assume_zero_enabled):
course_data = CourseData(self.request.user, structure=self.course_structure)
chapter_grades = ZeroCourseGrade(self.request.user, course_data).chapter_grades
for chapter in chapter_grades:
@@ -46,7 +47,7 @@ class ZeroGradeTest(GradeTestBase):
"""
Creates a zero course grade and ensures that null scores aren't included in the section problem scores.
"""
with waffle().override(ASSUME_ZERO_GRADE_IF_ABSENT, active=assume_zero_enabled):
with override_waffle_switch(waffle_switch(ASSUME_ZERO_GRADE_IF_ABSENT), active=assume_zero_enabled):
with patch('lms.djangoapps.grades.subsection_grade.get_score', return_value=None):
course_data = CourseData(self.request.user, structure=self.course_structure)
chapter_grades = ZeroCourseGrade(self.request.user, course_data).chapter_grades

View File

@@ -9,7 +9,7 @@ import ddt
from django.conf import settings
from mock import patch
from six import text_type
from edx_toggles.toggles.testutils import override_waffle_switch
from lms.djangoapps.courseware.access import has_access
from lms.djangoapps.grades.config.tests.utils import persistent_grades_feature_flags
from openedx.core.djangoapps.content.block_structure.factory import BlockStructureFactory
@@ -17,7 +17,7 @@ from student.tests.factories import UserFactory
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from ..config.waffle import ASSUME_ZERO_GRADE_IF_ABSENT, waffle
from ..config.waffle import ASSUME_ZERO_GRADE_IF_ABSENT, waffle_switch
from ..course_grade import CourseGrade, ZeroCourseGrade
from ..course_grade_factory import CourseGradeFactory
from ..subsection_grade import ReadSubsectionGrade, ZeroSubsectionGrade
@@ -132,7 +132,7 @@ class TestCourseGradeFactory(GradeTestBase):
@ddt.data(*itertools.product((True, False), (True, False)))
@ddt.unpack
def test_read_zero(self, assume_zero_enabled, create_if_needed):
with waffle().override(ASSUME_ZERO_GRADE_IF_ABSENT, active=assume_zero_enabled):
with override_waffle_switch(waffle_switch(ASSUME_ZERO_GRADE_IF_ABSENT), active=assume_zero_enabled):
grade_factory = CourseGradeFactory()
course_grade = grade_factory.read(self.request.user, self.course, create_if_needed=create_if_needed)
if create_if_needed or assume_zero_enabled: