refactor: deprecate course_id from ModuleSystem

This attribute is already deprecated for XBlocks in favour of directly
retrieving it like `block.scope_ids.usage_id.context_key`.

This commit also removes some redundant logging code which was omitted in the
Datadog removal in #19420.
This commit is contained in:
Agrendalath
2022-07-07 22:07:04 +02:00
parent c2ac3d83c3
commit dd97c74fde
11 changed files with 44 additions and 64 deletions

View File

@@ -683,7 +683,6 @@ def get_module_system_for_user(
get_module=inner_get_module,
user=user,
publish=publish,
course_id=course_id,
# TODO: When we merge the descriptor and module systems, we can stop reaching into the mixologist (cpennington)
mixins=descriptor.runtime.mixologist._mixins, # pylint: disable=protected-access
wrappers=block_wrappers,

View File

@@ -2706,15 +2706,22 @@ class LmsModuleSystemShimTest(SharedModuleStoreTestCase):
def test_replace_urls(self):
html = '<a href="/static/id">'
assert self.runtime.replace_urls(html) == \
static_replace.replace_static_urls(html, course_id=self.runtime.course_id)
static_replace.replace_static_urls(html, course_id=self.course.id)
def test_replace_course_urls(self):
html = '<a href="/course/id">'
assert self.runtime.replace_course_urls(html) == \
static_replace.replace_course_urls(html, course_key=self.runtime.course_id)
static_replace.replace_course_urls(html, course_key=self.course.id)
def test_replace_jump_to_id_urls(self):
html = '<a href="/jump_to_id/id">'
jump_to_id_base_url = reverse('jump_to_id', kwargs={'course_id': str(self.runtime.course_id), 'module_id': ''})
jump_to_id_base_url = reverse('jump_to_id', kwargs={'course_id': str(self.course.id), 'module_id': ''})
assert self.runtime.replace_jump_to_id_urls(html) == \
static_replace.replace_jump_to_id_urls(html, self.runtime.course_id, jump_to_id_base_url)
static_replace.replace_jump_to_id_urls(html, self.course.id, jump_to_id_base_url)
@XBlock.register_temp_plugin(PureXBlockWithChildren, identifier='xblock')
def test_course_id(self):
descriptor = ItemFactory(category="pure", parent=self.course)
block = render.get_module(self.user, Mock(), descriptor.location, None)
assert str(block.runtime.course_id) == self.COURSE_ID

View File

@@ -69,10 +69,10 @@ def update_exam_completion_task(user_identifier: str, content_id: str, completio
# Now evil modulestore magic to inflate our descriptor with user state and
# permissions checks.
field_data_cache = FieldDataCache.cache_for_descriptor_descendents(
root_descriptor.course_id, user, root_descriptor, read_only=True,
root_descriptor.scope_ids.usage_id.context_key, user, root_descriptor, read_only=True,
)
root_module = get_module_for_descriptor(
user, request, root_descriptor, field_data_cache, root_descriptor.course_id,
user, request, root_descriptor, field_data_cache, root_descriptor.scope_ids.usage_id.context_key,
)
if not root_module:
err_msg = err_msg_prefix + 'Module unable to be created from descriptor!'

View File

@@ -51,7 +51,7 @@ def handler_url(block, handler_name, suffix='', query='', thirdparty=False):
view_name = 'xblock_handler_noauth'
url = reverse(view_name, kwargs={
'course_id': str(block.location.course_key),
'course_id': str(block.scope_ids.usage_id.context_key),
'usage_id': quote_slashes(str(block.scope_ids.usage_id)),
'handler': handler_name,
'suffix': suffix,

View File

@@ -26,6 +26,14 @@ from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, p
class BlockMock(Mock):
"""Mock class that we fill with our "handler" methods."""
scope_ids = ScopeIds(
None,
None,
None,
BlockUsageLocator(
CourseLocator(org="mockx", course="100", run="2015"), block_type='mock_type', block_id="mock_id"
),
)
def handler(self, _context):
"""
@@ -45,20 +53,13 @@ class BlockMock(Mock):
"""
pass # lint-amnesty, pylint: disable=unnecessary-pass
@property
def location(self):
"""Create a functional BlockUsageLocator for testing URL generation."""
course_key = CourseLocator(org="mockx", course="100", run="2015")
return BlockUsageLocator(course_key, block_type='mock_type', block_id="mock_id")
class TestHandlerUrl(TestCase):
"""Test the LMS handler_url"""
def setUp(self):
super().setUp()
self.block = BlockMock(name='block', scope_ids=ScopeIds(None, None, None, 'dummy'))
self.course_key = CourseLocator("org", "course", "run")
self.block = BlockMock(name='block')
self.runtime = LmsModuleSystem(
track_function=Mock(),
get_module=Mock(),