Commit 660bc8f4 by Nimisha Asthagiri

Enable Persistent Grades in unit tests

parent 2251097c
......@@ -3,6 +3,7 @@ Models for configuration of the feature flags
controlling persistent grades.
"""
from config_models.models import ConfigurationModel
from django.conf import settings
from django.db.models import BooleanField
from xmodule_django.models import CourseKeyField
......@@ -29,6 +30,8 @@ class PersistentGradesEnabledFlag(ConfigurationModel):
If the flag is enabled and no course ID is given,
we return True since the global setting is enabled.
"""
if settings.FEATURES.get('PERSISTENT_GRADES_ENABLED_FOR_ALL_TESTS'):
return True
if not PersistentGradesEnabledFlag.is_enabled():
return False
elif not PersistentGradesEnabledFlag.current().enabled_for_all_courses and course_id:
......
......@@ -3,6 +3,9 @@ Tests for the models that control the
persistent grading feature.
"""
import ddt
from django.conf import settings
import itertools
from mock import patch
from django.test import TestCase
from opaque_keys.edx.locator import CourseLocator
......@@ -10,6 +13,7 @@ from lms.djangoapps.grades.config.models import PersistentGradesEnabledFlag
from lms.djangoapps.grades.config.tests.utils import persistent_grades_feature_flags
@patch.dict(settings.FEATURES, {'PERSISTENT_GRADES_ENABLED_FOR_ALL_TESTS': False})
@ddt.ddt
class PersistentGradesFeatureFlagTests(TestCase):
"""
......@@ -21,16 +25,11 @@ class PersistentGradesFeatureFlagTests(TestCase):
self.course_id_1 = CourseLocator(org="edx", course="course", run="run")
self.course_id_2 = CourseLocator(org="edx", course="course2", run="run")
@ddt.data(
(True, True, True),
(True, True, False),
(True, False, True),
(True, False, False),
(False, True, True),
(False, False, True),
(False, True, False),
(False, False, False),
)
@ddt.data(*itertools.product(
(True, False),
(True, False),
(True, False),
))
@ddt.unpack
def test_persistent_grades_feature_flags(self, global_flag, enabled_for_all_courses, enabled_for_course_1):
with persistent_grades_feature_flags(
......
......@@ -3,6 +3,7 @@ Test saved subsection grade functionality.
"""
import ddt
from django.conf import settings
from mock import patch
from capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory
......@@ -71,6 +72,7 @@ class TestCourseGradeFactory(GradeTestBase):
Test that CourseGrades are calculated properly
"""
@patch.dict(settings.FEATURES, {'PERSISTENT_GRADES_ENABLED_FOR_ALL_TESTS': False})
@ddt.data(
(True, True),
(True, False),
......@@ -107,44 +109,39 @@ class SubsectionGradeFactoryTest(GradeTestBase):
"""
Tests to ensure that a persistent subsection grade is created, saved, then fetched on re-request.
"""
with persistent_grades_feature_flags(
global_flag=True,
enabled_for_all_courses=False,
course_id=self.course.id,
enabled_for_course=True
):
with patch(
'lms.djangoapps.grades.new.subsection_grade.SubsectionGradeFactory._save_grade',
wraps=self.subsection_grade_factory._save_grade # pylint: disable=protected-access
) as mock_save_grades:
with patch(
'lms.djangoapps.grades.new.subsection_grade.SubsectionGradeFactory._save_grade',
wraps=self.subsection_grade_factory._save_grade # pylint: disable=protected-access
) as mock_save_grades:
with patch(
'lms.djangoapps.grades.new.subsection_grade.SubsectionGradeFactory._get_saved_grade',
wraps=self.subsection_grade_factory._get_saved_grade # pylint: disable=protected-access
) as mock_get_saved_grade:
with self.assertNumQueries(22):
grade_a = self.subsection_grade_factory.create(
self.sequence,
self.course_structure,
self.course
)
self.assertTrue(mock_get_saved_grade.called)
self.assertTrue(mock_save_grades.called)
mock_get_saved_grade.reset_mock()
mock_save_grades.reset_mock()
with self.assertNumQueries(4):
grade_b = self.subsection_grade_factory.create(
self.sequence,
self.course_structure,
self.course
)
self.assertTrue(mock_get_saved_grade.called)
self.assertFalse(mock_save_grades.called)
'lms.djangoapps.grades.new.subsection_grade.SubsectionGradeFactory._get_saved_grade',
wraps=self.subsection_grade_factory._get_saved_grade # pylint: disable=protected-access
) as mock_get_saved_grade:
with self.assertNumQueries(19):
grade_a = self.subsection_grade_factory.create(
self.sequence,
self.course_structure,
self.course
)
self.assertTrue(mock_get_saved_grade.called)
self.assertTrue(mock_save_grades.called)
mock_get_saved_grade.reset_mock()
mock_save_grades.reset_mock()
with self.assertNumQueries(3):
grade_b = self.subsection_grade_factory.create(
self.sequence,
self.course_structure,
self.course
)
self.assertTrue(mock_get_saved_grade.called)
self.assertFalse(mock_save_grades.called)
self.assertEqual(grade_a.url_name, grade_b.url_name)
self.assertEqual(grade_a.all_total, grade_b.all_total)
@patch.dict(settings.FEATURES, {'PERSISTENT_GRADES_ENABLED_FOR_ALL_TESTS': False})
@ddt.data(
(True, True),
(True, False),
......
......@@ -3,6 +3,7 @@ Tests for the score change signals defined in the courseware models module.
"""
import ddt
from django.conf import settings
from django.test import TestCase
from mock import patch, MagicMock
from unittest import skip
......@@ -169,6 +170,7 @@ class SubmissionSignalRelayTest(TestCase):
self.signal_mock.assert_not_called()
@patch.dict(settings.FEATURES, {'PERSISTENT_GRADES_ENABLED_FOR_ALL_TESTS': False})
@ddt.ddt
class ScoreChangedUpdatesSubsectionGradeTest(ModuleStoreTestCase):
"""
......
......@@ -298,6 +298,9 @@ OIDC_COURSE_HANDLER_CACHE_TIMEOUT = 0
FEATURES['ENABLE_MOBILE_REST_API'] = True
FEATURES['ENABLE_VIDEO_ABSTRACTION_LAYER_API'] = True
########################### Grades #################################
FEATURES['PERSISTENT_GRADES_ENABLED_FOR_ALL_TESTS'] = True
###################### Payment ##############################3
# Enable fake payment processing page
FEATURES['ENABLE_PAYMENT_FAKE'] = True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment