fix: review changes
This commit is contained in:
@@ -319,6 +319,11 @@ def _import_xml_node_to_parent(
|
||||
parent_key = parent_xblock.scope_ids.usage_id
|
||||
block_type = node.tag
|
||||
|
||||
# Modulestore's IdGenerator here is SplitMongoIdManager which is assigned
|
||||
# by CachingDescriptorSystem Runtime and since we need our custom ImportIdGenerator
|
||||
# here we are temporaraliy swtiching it.
|
||||
original_id_generator = runtime.id_generator
|
||||
|
||||
# Generate the new ID:
|
||||
runtime.id_generator = ImportIdGenerator(parent_key.context_key)
|
||||
def_id = runtime.id_generator.create_definition(block_type, slug_hint)
|
||||
@@ -360,6 +365,10 @@ def _import_xml_node_to_parent(
|
||||
node_without_children = etree.Element(node.tag, **node.attrib)
|
||||
temp_xblock = xblock_class.parse_xml(node_without_children, runtime, keys)
|
||||
child_nodes = list(node)
|
||||
|
||||
# Restore the original id_generator
|
||||
runtime.id_generator = original_id_generator
|
||||
|
||||
if xblock_class.has_children and temp_xblock.children:
|
||||
raise NotImplementedError("We don't yet support pasting XBlocks with children")
|
||||
temp_xblock.parent = parent_key
|
||||
|
||||
@@ -2025,9 +2025,8 @@ class VideoBlockTest(TestCase, VideoBlockTestBase):
|
||||
val_transcript_provider=val_transcript_provider
|
||||
)
|
||||
xml_object = etree.fromstring(xml_data)
|
||||
id_generator = Mock()
|
||||
id_generator.target_course_id = "test_course_id"
|
||||
module_system.id_generator = id_generator
|
||||
module_system.id_generator.target_course_id = "test_course_id"
|
||||
|
||||
video = self.block.parse_xml(xml_object, module_system, None)
|
||||
|
||||
assert video.edx_video_id == 'test_edx_video_id'
|
||||
@@ -2035,7 +2034,7 @@ class VideoBlockTest(TestCase, VideoBlockTestBase):
|
||||
assert video_data['client_video_id'] == 'test_client_video_id'
|
||||
assert video_data['duration'] == 111.0
|
||||
assert video_data['status'] == 'imported'
|
||||
assert video_data['courses'] == [{id_generator.target_course_id: None}]
|
||||
assert video_data['courses'] == [{module_system.id_generator.target_course_id: None}]
|
||||
assert video_data['encoded_videos'][0]['profile'] == 'mobile'
|
||||
assert video_data['encoded_videos'][0]['url'] == 'http://example.com/video'
|
||||
assert video_data['encoded_videos'][0]['file_size'] == 222
|
||||
|
||||
@@ -50,6 +50,7 @@ class DummySystem(ImportSystem): # lint-amnesty, pylint: disable=abstract-metho
|
||||
mixins=(InheritanceMixin, XModuleMixin),
|
||||
services={'field-data': KvsFieldData(DictKeyValueStore())},
|
||||
)
|
||||
self.id_generator = Mock()
|
||||
|
||||
|
||||
class BaseCourseTestCase(TestCase):
|
||||
|
||||
@@ -62,8 +62,7 @@ class PollBlockTest(unittest.TestCase):
|
||||
unescaped characters.
|
||||
"""
|
||||
module_system = DummySystem(load_error_blocks=True)
|
||||
id_generator = Mock()
|
||||
id_generator.target_course_id = self.xblock.course_id
|
||||
module_system.id_generator.target_course_id = self.xblock.course_id
|
||||
sample_poll_xml = '''
|
||||
<poll_question display_name="Poll Question">
|
||||
<p>How old are you?</p>
|
||||
@@ -72,7 +71,6 @@ class PollBlockTest(unittest.TestCase):
|
||||
'''
|
||||
node = etree.fromstring(sample_poll_xml)
|
||||
|
||||
module_system.id_generator = id_generator
|
||||
output = PollBlock.parse_xml(node, module_system, self.scope_ids)
|
||||
# Update the answer with invalid character.
|
||||
invalid_characters_poll_answer = output.answers[0]
|
||||
|
||||
@@ -344,10 +344,8 @@ class VideoBlockImportTestCase(TestCase):
|
||||
</video>
|
||||
'''
|
||||
xml_object = etree.fromstring(xml_data)
|
||||
id_generator = Mock()
|
||||
id_generator.target_course_id = course_id
|
||||
module_system.id_generator.target_course_id = course_id
|
||||
|
||||
module_system.id_generator = id_generator
|
||||
output = VideoBlock.parse_xml(xml_object, module_system, None)
|
||||
self.assert_attributes_equal(output, {
|
||||
'youtube_id_0_75': 'izygArpw-Qo',
|
||||
@@ -644,9 +642,7 @@ class VideoBlockImportTestCase(TestCase):
|
||||
edx_video_id=edx_video_id
|
||||
)
|
||||
xml_object = etree.fromstring(xml_data)
|
||||
id_generator = Mock()
|
||||
id_generator.target_course_id = 'test_course_id'
|
||||
module_system.id_generator = id_generator
|
||||
module_system.id_generator.target_course_id = 'test_course_id'
|
||||
video = VideoBlock.parse_xml(xml_object, module_system, None)
|
||||
|
||||
self.assert_attributes_equal(video, {'edx_video_id': edx_video_id})
|
||||
|
||||
Reference in New Issue
Block a user