refactor: replace usages of XModuleMixin.system with XBlock.runtime

This commit is contained in:
0x29a
2023-01-09 11:44:24 +01:00
committed by Agrendalath
parent fd191db332
commit 3a1011bed8
24 changed files with 47 additions and 47 deletions

View File

@@ -1015,10 +1015,10 @@ class MiscCourseTests(ContentStoreTestCase):
course = self.store.get_course(self.course.id, depth=2, lazy=False)
# make sure we pre-fetched a known sequential which should be at depth=2
self.assertIn(BlockKey.from_usage_key(self.seq_loc), course.system.module_data)
self.assertIn(BlockKey.from_usage_key(self.seq_loc), course.runtime.module_data)
# make sure we don't have a specific vertical which should be at depth=3
self.assertNotIn(BlockKey.from_usage_key(self.vert_loc), course.system.module_data)
self.assertNotIn(BlockKey.from_usage_key(self.vert_loc), course.runtime.module_data)
# Now, test with the branch set to draft. No extra round trips b/c it doesn't go deep enough to get
# beyond direct only categories

View File

@@ -90,7 +90,7 @@ class TemplateTests(ModuleStoreTestCase):
)
test_chapter = self.store.create_xblock(
test_course.system, test_course.id, 'chapter', fields={'display_name': 'chapter n'},
test_course.runtime, test_course.id, 'chapter', fields={'display_name': 'chapter n'},
parent_xblock=test_course
)
self.assertIsInstance(test_chapter, SequenceBlock)
@@ -100,7 +100,7 @@ class TemplateTests(ModuleStoreTestCase):
# test w/ a definition (e.g., a problem)
test_def_content = '<problem>boo</problem>'
test_problem = self.store.create_xblock(
test_course.system, test_course.id, 'problem', fields={'data': test_def_content},
test_course.runtime, test_course.id, 'problem', fields={'data': test_def_content},
parent_xblock=test_chapter
)
self.assertIsInstance(test_problem, ProblemBlock)

View File

@@ -731,7 +731,7 @@ def get_course_syllabus_section(course, section_key):
if section_key in ['syllabus', 'guest_syllabus']:
try:
filesys = course.system.resources_fs
filesys = course.runtime.resources_fs
# first look for a run-specific version
dirs = [path("syllabus") / course.url_name, path("syllabus")]
filepath = find_file(filesys, dirs, section_key + ".html")

View File

@@ -2108,7 +2108,7 @@ class TestXBlockRuntimeEvent(TestSubmittingProblems):
def set_block_grade_using_publish(self, grade_dict):
"""Publish the user's grade, takes grade_dict as input"""
block = self.get_block_for_user(self.student_user)
block.system.publish(block, 'grade', grade_dict)
block.runtime.publish(block, 'grade', grade_dict)
return block
def test_xblock_runtime_publish(self):
@@ -2121,7 +2121,7 @@ class TestXBlockRuntimeEvent(TestSubmittingProblems):
def test_xblock_runtime_publish_delete(self):
"""Test deleting the grade using the publish mechanism"""
block = self.set_block_grade_using_publish(self.grade_dict)
block.system.publish(block, 'grade', self.delete_dict)
block.runtime.publish(block, 'grade', self.delete_dict)
student_module = StudentModule.objects.get(student=self.student_user, module_state_key=self.problem.location)
assert student_module.grade is None
assert student_module.max_grade is None
@@ -2185,7 +2185,7 @@ class TestRebindBlock(TestSubmittingProblems):
# Bind the block to another student, which will remove "correct_map"
# from the block's _field_data_cache and _dirty_fields.
user2 = UserFactory.create()
block.bind_for_student(block.system, user2.id)
block.bind_for_student(block.runtime, user2.id)
# XBlock's save method assumes that if a field is in _dirty_fields,
# then it's also in _field_data_cache. If this assumption
@@ -2194,7 +2194,7 @@ class TestRebindBlock(TestSubmittingProblems):
# _field_data cache, but not _dirty_fields, when we bound
# this block to the second student. (TNL-2640)
user3 = UserFactory.create()
block.bind_for_student(block.system, user3.id)
block.bind_for_student(block.runtime, user3.id)
def test_rebind_noauth_block_to_user_not_anonymous(self):
"""
@@ -2220,7 +2220,7 @@ class TestRebindBlock(TestSubmittingProblems):
user2.id = 2
block.runtime.service(block, 'rebind_user').rebind_noauth_module_to_user(block, user2)
assert block
assert block.system.anonymous_student_id == anonymous_id_for_user(user2, self.course.id)
assert block.runtime.anonymous_student_id == anonymous_id_for_user(user2, self.course.id)
assert block.scope_ids.user_id == user2.id
assert block.scope_ids.user_id == user2.id

View File

@@ -384,7 +384,7 @@ def answer_entrance_exam_problem(course, request, problem, user=None, value=1, m
problem.scope_ids.usage_id,
field_data_cache,
)
block.system.publish(problem, 'grade', grade_dict)
block.runtime.publish(problem, 'grade', grade_dict)
def add_entrance_exam_milestone(course, entrance_exam):

View File

@@ -1944,7 +1944,7 @@ class ProgressPageShowCorrectnessTests(ProgressPageBaseTests):
# Submit the given score/max_score to the problem xmodule
grade_dict = {'value': value, 'max_value': max_value, 'user_id': self.user.id}
block.system.publish(self.problem, 'grade', grade_dict)
block.runtime.publish(self.problem, 'grade', grade_dict)
def assert_progress_page_show_grades(self, response, show_correctness, due_date, graded,
show_grades, score, max_score, avg): # lint-amnesty, pylint: disable=unused-argument

View File

@@ -85,4 +85,4 @@ def answer_problem(course, request, problem, score=1, max_value=1):
problem.scope_ids.usage_id,
field_data_cache,
)
block.system.publish(problem, 'grade', grade_dict)
block.runtime.publish(problem, 'grade', grade_dict)

View File

@@ -662,11 +662,11 @@ def _section_send_email(course, access):
with patch.object(course.runtime, 'applicable_aside_types', null_applicable_aside_types):
# This HtmlBlock is only being used to generate a nice text editor.
html_block = HtmlBlock(
course.system,
course.runtime,
DictFieldData({'data': ''}),
ScopeIds(None, None, None, course_key.make_usage_key('html', 'fake'))
)
fragment = course.system.render(html_block, 'studio_view')
fragment = course.runtime.render(html_block, 'studio_view')
fragment = wrap_xblock(
'LmsRuntime', html_block, 'studio_view', fragment, None,
extra_data={"course-id": str(course_key)},

View File

@@ -111,7 +111,7 @@ def apply_wrappers_to_content(content, block, request):
Returns: A piece of html content containing the original content updated by each wrapper.
"""
content = block.system.service(block, "replace_urls").replace_urls(content)
content = block.runtime.service(block, "replace_urls").replace_urls(content)
return make_static_urls_absolute(request, content)

View File

@@ -70,7 +70,7 @@ def get_ordered_updates(request, course):
reverse=True
)
for update in ordered_updates:
update['content'] = info_block.system.service(info_block, "replace_urls").replace_urls(update['content'])
update['content'] = info_block.runtime.service(info_block, "replace_urls").replace_urls(update['content'])
return ordered_updates

View File

@@ -78,6 +78,6 @@ class CourseUpdatesFragmentView(EdxFragmentView):
"""
info_block = get_course_info_section_block(request, request.user, course, 'updates')
info_block = getattr(info_block, '_xmodule', info_block)
return info_block.system.service(
return info_block.runtime.service(
info_block, "replace_urls"
).replace_urls(info_block.data) if info_block else ''

View File

@@ -318,7 +318,7 @@ class ConditionalBlock(
Returns a list of bound XBlocks instances upon which XBlock depends.
"""
return [
self.system.get_block_for_descriptor(descriptor) for descriptor in self.get_required_block_descriptors()
self.runtime.get_block_for_descriptor(descriptor) for descriptor in self.get_required_block_descriptors()
]
def get_required_block_descriptors(self):
@@ -333,7 +333,7 @@ class ConditionalBlock(
except ItemNotFoundError:
msg = "Invalid module by location."
log.exception(msg)
self.system.error_tracker(msg)
self.runtime.error_tracker(msg)
return descriptors

View File

@@ -1056,10 +1056,10 @@ class CourseBlock(
# NOTE (THK): This is a last-minute addition for Fall 2012 launch to dynamically
# disable the syllabus content for courses that do not provide a syllabus
if self.system.resources_fs is None:
if self.runtime.resources_fs is None:
self.syllabus_present = False
else:
self.syllabus_present = self.system.resources_fs.exists(path('syllabus'))
self.syllabus_present = self.runtime.resources_fs.exists(path('syllabus'))
self._grading_policy = {}
self.set_grading_policy(self.grading_policy)

View File

@@ -67,7 +67,7 @@ class MakoTemplateBlockBase:
"""
# pylint: disable=no-member
fragment = Fragment(
self.system.render_template(self.mako_template, self.get_context())
self.runtime.render_template(self.mako_template, self.get_context())
)
shim_xmodule_js(fragment, self.js_module_name)
return fragment

View File

@@ -2191,7 +2191,7 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase):
if xblock.has_children:
for child in xblock.children:
if isinstance(child.block_id, LocalId):
child_block = xblock.system.get_block(child)
child_block = xblock.runtime.get_block(child)
is_updated = self._persist_subdag(course_key, child_block, user_id, structure_blocks, new_id) or is_updated # lint-amnesty, pylint: disable=line-too-long
children.append(BlockKey.from_usage_key(child_block.location))
else:

View File

@@ -2460,7 +2460,7 @@ class TestMixedModuleStore(CommonMixedModuleStoreSetup):
# verify store used for creating a course
course = self.store.create_course("org", "course{}".format(uuid4().hex[:5]), "run", self.user_id)
assert course.system.modulestore.get_modulestore_type() == store_type
assert course.runtime.modulestore.get_modulestore_type() == store_type
@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
def test_default_store(self, default_ms):

View File

@@ -704,7 +704,7 @@ class SplitModuleCourseTests(SplitModuleTest):
locator = CourseLocator(org='testx', course='GreekHero', run="run", branch=BRANCH_NAME_DRAFT)
course = modulestore().get_course(locator)
block_map = modulestore().cache_items(
course.system, [BlockKey.from_usage_key(child) for child in course.children], course.id, depth=3
course.runtime, [BlockKey.from_usage_key(child) for child in course.children], course.id, depth=3
)
assert BlockKey('chapter', 'chapter1') in block_map
assert BlockKey('problem', 'problem3_2') in block_map
@@ -719,14 +719,14 @@ class SplitModuleCourseTests(SplitModuleTest):
master_branch=ModuleStoreEnum.BranchName.draft
)
test_chapter = modulestore().create_xblock(
test_course.system, test_course.id, 'chapter', fields={'display_name': 'chapter n'},
test_course.runtime, test_course.id, 'chapter', fields={'display_name': 'chapter n'},
parent_xblock=test_course
)
assert test_chapter.display_name == 'chapter n'
test_def_content = '<problem>boo</problem>'
# create child
new_block = modulestore().create_xblock(
test_course.system, test_course.id,
test_course.runtime, test_course.id,
'problem',
fields={
'data': test_def_content,

View File

@@ -71,8 +71,8 @@ class RandomizeBlock(
if self.choice is None:
# choose one based on the system seed, or randomly if that's not available
if num_choices > 0:
if self.system.seed is not None:
self.choice = self.system.seed % num_choices
if self.runtime.seed is not None:
self.choice = self.runtime.seed % num_choices
else:
self.choice = random.randrange(0, num_choices)

View File

@@ -306,10 +306,10 @@ class SequenceBlock(
# and needs to be read here after the ModuleSystem has been set on the XBlock.
super().bind_for_student(xmodule_runtime, user_id, wrappers)
# If position is specified in system, then use that instead.
position = getattr(self.system, 'position', None)
position = getattr(self.runtime, 'position', None)
if position is not None:
assert isinstance(position, int)
self.position = self.system.position
self.position = self.runtime.position
def get_progress(self):
''' Return the total progress, adding total done and total available.

View File

@@ -192,7 +192,7 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method
Return the user bound child block for the partition or None.
"""
if self.child_descriptor is not None:
return self.system.get_block_for_descriptor(self.child_descriptor)
return self.runtime.get_block_for_descriptor(self.child_descriptor)
else:
return None
@@ -272,7 +272,7 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method
for child_location in self.children: # pylint: disable=no-member
child_descriptor = self.get_child_descriptor_by_location(child_location)
child = self.system.get_block_for_descriptor(child_descriptor)
child = self.runtime.get_block_for_descriptor(child_descriptor)
rendered_child = child.render(STUDENT_VIEW, context)
fragment.add_fragment_resources(rendered_child)
group_name, updated_group_id = self.get_data_for_vertical(child)
@@ -347,7 +347,7 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method
"""
html = ""
for active_child_descriptor in children:
active_child = self.system.get_block_for_descriptor(active_child_descriptor)
active_child = self.runtime.get_block_for_descriptor(active_child_descriptor)
rendered_child = active_child.render(StudioEditableBlock.get_preview_view_name(active_child), context)
if active_child.category == 'vertical':
group_name, group_id = self.get_data_for_vertical(active_child)
@@ -381,7 +381,7 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method
# raise error instead? In fact, could complain on descriptor load...
return Fragment(content="<div>Nothing here. Move along.</div>")
if self.system.user_is_staff:
if self.runtime.user_is_staff:
return self._staff_view(context)
else:
child_fragment = self.child.render(STUDENT_VIEW, context)
@@ -704,15 +704,15 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method
if changed:
# user.id - to be fixed by Publishing team
self.system.modulestore.update_item(self, None)
self.runtime.modulestore.update_item(self, None)
return Response()
@property
def group_configuration_url(self): # lint-amnesty, pylint: disable=missing-function-docstring
assert hasattr(self.system, 'modulestore') and hasattr(self.system.modulestore, 'get_course'), \
assert hasattr(self.runtime, 'modulestore') and hasattr(self.runtime.modulestore, 'get_course'), \
"modulestore has to be available"
course_block = self.system.modulestore.get_course(self.location.course_key)
course_block = self.runtime.modulestore.get_course(self.location.course_key)
group_configuration_url = None
if 'split_test' in course_block.advanced_modules:
user_partition = self.get_selected_partition()
@@ -732,9 +732,9 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method
A mutable modulestore is needed to call this method (will need to update after mixed
modulestore work, currently relies on mongo's create_item method).
"""
assert hasattr(self.system, 'modulestore') and hasattr(self.system.modulestore, 'create_item'), \
assert hasattr(self.runtime, 'modulestore') and hasattr(self.runtime.modulestore, 'create_item'), \
"editor_saved should only be called when a mutable modulestore is available"
modulestore = self.system.modulestore
modulestore = self.runtime.modulestore
dest_usage_key = self.location.replace(category="vertical", name=uuid4().hex)
metadata = {'display_name': DEFAULT_GROUP_NAME.format(group_id=group.id)}
modulestore.create_item(
@@ -744,7 +744,7 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method
block_id=dest_usage_key.block_id,
definition_data=None,
metadata=metadata,
runtime=self.system,
runtime=self.runtime,
)
self.children.append(dest_usage_key) # pylint: disable=no-member
self.group_id_to_child[str(group.id)] = dest_usage_key

View File

@@ -118,7 +118,7 @@ class CustomTagBlock(CustomTagTemplateBlock): # pylint: disable=abstract-method
@property
def rendered_html(self):
return self.render_template(self.system, self.data)
return self.render_template(self.runtime, self.data)
def student_view(self, _context):
"""

View File

@@ -1734,7 +1734,7 @@ class ProblemBlockTest(unittest.TestCase): # lint-amnesty, pylint: disable=miss
error_msg = "Superterrible error happened: ☠"
block.lcp.get_html = Mock(side_effect=Exception(error_msg))
block.system.is_author_mode = True
block.runtime.is_author_mode = True
# Try to render the block with the author mode turned on
html = block.get_problem_html()

View File

@@ -124,7 +124,7 @@ class SplitTestBlockTest(XModuleXmlImportTest, PartitionTestCase):
# view, since mock services exist and the rendering code will not short-circuit.
mocked_modulestore = Mock()
mocked_modulestore.get_course.return_value = self.course
self.split_test_block.system.modulestore = mocked_modulestore
self.split_test_block.runtime.modulestore = mocked_modulestore
@ddt.ddt
@@ -239,7 +239,7 @@ class SplitTestBlockStudioTest(SplitTestBlockTest):
mocked_course = Mock(advanced_modules=['split_test'])
mocked_modulestore = Mock()
mocked_modulestore.get_course.return_value = mocked_course
self.split_test_block.system.modulestore = mocked_modulestore
self.split_test_block.runtime.modulestore = mocked_modulestore
self.split_test_block.user_partitions = [
UserPartition(0, 'first_partition', 'First Partition', [Group("0", 'alpha'), Group("1", 'beta')])

View File

@@ -54,7 +54,7 @@ def is_bumper_enabled(video):
video.bumper_do_not_show_again,
(bumper_last_view_date and bumper_last_view_date + timedelta(seconds=periodicity) > utc_now)
])
is_studio = getattr(video.system, "is_author_mode", False)
is_studio = getattr(video.runtime, "is_author_mode", False)
return bool(
not is_studio and
settings.FEATURES.get('ENABLE_VIDEO_BUMPER') and