first round of self review and code review
This commit is contained in:
@@ -338,6 +338,8 @@ def add_course_content_milestone(course_id, content_id, relationship, milestone)
|
||||
def get_course_content_milestones(course_id, content_id, relationship, user_id=None):
|
||||
"""
|
||||
Client API operation adapter/wrapper
|
||||
Uses the request cache to store all of a user's
|
||||
milestones
|
||||
"""
|
||||
if not settings.FEATURES.get('MILESTONES_APP', False):
|
||||
return []
|
||||
@@ -347,26 +349,16 @@ def get_course_content_milestones(course_id, content_id, relationship, user_id=N
|
||||
|
||||
request_cache_dict = request_cache.get_cache(REQUEST_CACHE_NAME)
|
||||
if user_id not in request_cache_dict:
|
||||
request_cache_dict[user_id] = milestones_api.get_course_content_milestones(
|
||||
request_cache_dict[user_id] = {}
|
||||
|
||||
if relationship not in request_cache_dict[user_id]:
|
||||
request_cache_dict[user_id]['requires'] = milestones_api.get_course_content_milestones(
|
||||
course_key=course_id,
|
||||
relationship=relationship,
|
||||
user={"id": user_id}
|
||||
)
|
||||
milestones_for_content = []
|
||||
if relationship == "requires":
|
||||
for milestone in request_cache_dict[user_id]:
|
||||
if milestone["content_id"] == content_id and milestone["requirements"]:
|
||||
milestones_for_content.append(milestone)
|
||||
if relationship == "fulfills":
|
||||
for milestone in request_cache_dict[user_id]:
|
||||
if milestone["namespace"].contains(content_id) and milestone["requirements"]:
|
||||
milestones_for_content.append(milestone)
|
||||
|
||||
return milestones_api.get_course_content_milestones(
|
||||
course_id,
|
||||
content_id,
|
||||
relationship,
|
||||
user={"id": user_id}
|
||||
)
|
||||
return [m for m in request_cache_dict[user_id][relationship] if m['content_id'] == content_id]
|
||||
|
||||
|
||||
def remove_course_content_user_milestones(course_key, content_key, user, relationship):
|
||||
|
||||
@@ -10,6 +10,7 @@ from lms.djangoapps.course_blocks.transformers.tests.helpers import CourseStruct
|
||||
from milestones.tests.utils import MilestonesTestCaseMixin
|
||||
from opaque_keys.edx.keys import UsageKey
|
||||
from openedx.core.lib.gating import api as gating_api
|
||||
from request_cache.middleware import RequestCache
|
||||
from student.tests.factories import CourseEnrollmentFactory
|
||||
|
||||
from ..milestones import MilestonesTransformer
|
||||
@@ -160,6 +161,9 @@ class MilestonesTransformerTestCase(CourseStructureTestCase, MilestonesTestCaseM
|
||||
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)
|
||||
|
||||
# We clear the request cache to simulate a new request in the LMS.
|
||||
RequestCache.clear_request_cache()
|
||||
|
||||
# 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)):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user