Commit 8acd1bb1 by sanfordstudent Committed by GitHub

Merge pull request #13090 from edx/sstudent/TNL-5071

adding request cache for milestones
parents a1e93f61 f02889e8
...@@ -158,7 +158,12 @@ class MilestonesTransformerTestCase(CourseStructureTestCase, MilestonesTestCaseM ...@@ -158,7 +158,12 @@ class MilestonesTransformerTestCase(CourseStructureTestCase, MilestonesTestCaseM
""" """
self.course.enable_subsection_gating = True self.course.enable_subsection_gating = True
self.setup_gated_section(self.blocks[gated_block_ref], self.blocks[gating_block_ref]) self.setup_gated_section(self.blocks[gated_block_ref], self.blocks[gating_block_ref])
self.get_blocks_and_check_against_expected(self.user, expected_blocks_before_completion)
with self.assertNumQueries(3):
self.get_blocks_and_check_against_expected(self.user, expected_blocks_before_completion)
# clear the request cache to simulate a new request
self.clear_caches()
# mock the api that the lms gating api calls to get the score for each block to always return 1 (ie 100%) # mock the api that the lms gating api calls to get the score for each block to always return 1 (ie 100%)
with patch('gating.api.get_module_score', Mock(return_value=1)): with patch('gating.api.get_module_score', Mock(return_value=1)):
...@@ -169,8 +174,8 @@ class MilestonesTransformerTestCase(CourseStructureTestCase, MilestonesTestCaseM ...@@ -169,8 +174,8 @@ class MilestonesTransformerTestCase(CourseStructureTestCase, MilestonesTestCaseM
self.course, self.course,
UsageKey.from_string(unicode(self.blocks[gating_block_child].location)), UsageKey.from_string(unicode(self.blocks[gating_block_child].location)),
self.user.id) self.user.id)
with self.assertNumQueries(2):
self.get_blocks_and_check_against_expected(self.user, self.ALL_BLOCKS_EXCEPT_SPECIAL) self.get_blocks_and_check_against_expected(self.user, self.ALL_BLOCKS_EXCEPT_SPECIAL)
def test_staff_access(self): def test_staff_access(self):
""" """
......
...@@ -7,10 +7,9 @@ import json ...@@ -7,10 +7,9 @@ import json
from collections import defaultdict from collections import defaultdict
from django.contrib.auth.models import User from django.contrib.auth.models import User
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from milestones import api as milestones_api
from openedx.core.lib.gating import api as gating_api from openedx.core.lib.gating import api as gating_api
from lms.djangoapps.grades.module_grades import get_module_score from lms.djangoapps.grades.module_grades import get_module_score
from util import milestones_helpers
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -81,6 +80,6 @@ def evaluate_prerequisite(course, prereq_content_key, user_id): ...@@ -81,6 +80,6 @@ def evaluate_prerequisite(course, prereq_content_key, user_id):
) )
if score >= min_score: if score >= min_score:
milestones_api.add_user_milestone({'id': user_id}, prereq_milestone) milestones_helpers.add_user_milestone({'id': user_id}, prereq_milestone)
else: else:
milestones_api.remove_user_milestone({'id': user_id}, prereq_milestone) milestones_helpers.remove_user_milestone({'id': user_id}, prereq_milestone)
...@@ -9,7 +9,6 @@ from opaque_keys.edx.keys import UsageKey ...@@ -9,7 +9,6 @@ from opaque_keys.edx.keys import UsageKey
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from openedx.core.lib.gating.exceptions import GatingValidationError from openedx.core.lib.gating.exceptions import GatingValidationError
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
# This is used to namespace gating-specific milestones # This is used to namespace gating-specific milestones
......
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