Commit d9e0ba45 by Sanford Student

first round of self review and code review

parent 7d690dde
...@@ -338,6 +338,8 @@ def add_course_content_milestone(course_id, content_id, relationship, milestone) ...@@ -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): def get_course_content_milestones(course_id, content_id, relationship, user_id=None):
""" """
Client API operation adapter/wrapper 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): if not settings.FEATURES.get('MILESTONES_APP', False):
return [] return []
...@@ -347,26 +349,16 @@ def get_course_content_milestones(course_id, content_id, relationship, user_id=N ...@@ -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) request_cache_dict = request_cache.get_cache(REQUEST_CACHE_NAME)
if user_id not in request_cache_dict: 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, course_key=course_id,
relationship=relationship,
user={"id": user_id} user={"id": user_id}
) )
milestones_for_content = []
if relationship == "requires": return [m for m in request_cache_dict[user_id][relationship] if m['content_id'] == content_id]
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}
)
def remove_course_content_user_milestones(course_key, content_key, user, relationship): 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 ...@@ -10,6 +10,7 @@ from lms.djangoapps.course_blocks.transformers.tests.helpers import CourseStruct
from milestones.tests.utils import MilestonesTestCaseMixin from milestones.tests.utils import MilestonesTestCaseMixin
from opaque_keys.edx.keys import UsageKey from opaque_keys.edx.keys import UsageKey
from openedx.core.lib.gating import api as gating_api from openedx.core.lib.gating import api as gating_api
from request_cache.middleware import RequestCache
from student.tests.factories import CourseEnrollmentFactory from student.tests.factories import CourseEnrollmentFactory
from ..milestones import MilestonesTransformer from ..milestones import MilestonesTransformer
...@@ -160,6 +161,9 @@ class MilestonesTransformerTestCase(CourseStructureTestCase, MilestonesTestCaseM ...@@ -160,6 +161,9 @@ class MilestonesTransformerTestCase(CourseStructureTestCase, MilestonesTestCaseM
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) 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%) # 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)):
......
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