Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions xmodule/tests/test_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
from xmodule.validation import StudioValidationMessage
from xmodule.video_block import EXPORT_IMPORT_STATIC_DIR, VideoBlock, create_youtube_string
from xmodule.video_block.transcripts_utils import save_to_store
from xblock.core import XBlockAside
from xmodule.modulestore.tests.test_asides import AsideTestType

from .test_import import DummySystem

Expand Down Expand Up @@ -316,6 +318,36 @@ def test_parse_xml(self):
'transcripts': {'uk': 'ukrainian_translation.srt', 'de': 'german_translation.srt'},
})

@XBlockAside.register_temp_plugin(AsideTestType, "test_aside")
@patch('xmodule.video_block.video_block.VideoBlock.load_file')
@patch('xmodule.video_block.video_block.is_pointer_tag')
@ddt.data(True, False)
def test_parse_xml_with_asides(self, video_xml_has_aside, mock_is_pointer_tag, mock_load_file):
"""Test that `parse_xml` parses asides from the video xml"""
runtime = DummySystem(load_error_blocks=True)
if video_xml_has_aside:
xml_data = '''
<video url_name="a16643fa63234fef8f6ebbc1902e2253">
<test_aside xblock-family="xblock_asides.v1" data_field="aside parsed"/>
</video>
'''
else:
xml_data = '''
<video url_name="a16643fa63234fef8f6ebbc1902e2253">
</video>
'''
mock_is_pointer_tag.return_value = True
xml_object = etree.fromstring(xml_data)
mock_load_file.return_value = xml_object
output = VideoBlock.parse_xml(xml_object, runtime, None)
aside = runtime.get_aside_of_type(output, "test_aside")
if video_xml_has_aside:
assert aside.content == "default_content"
assert aside.data_field == "aside parsed"
else:
assert aside.content == "default_content"
assert aside.data_field == "default_data"

@ddt.data(
('course-v1:test_org+test_course+test_run',
'/asset-v1:test_org+test_course+test_run+type@asset+block@test.png'),
Expand Down
6 changes: 5 additions & 1 deletion xmodule/video_block/video_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,10 +752,11 @@ def parse_xml(cls, node, runtime, _keys):
block_type = 'video'
definition_id = runtime.id_generator.create_definition(block_type, url_name)
usage_id = runtime.id_generator.create_usage(definition_id)
aside_children = []
if is_pointer_tag(node):
filepath = cls._format_filepath(node.tag, name_to_pathname(url_name))
node = cls.load_file(filepath, runtime.resources_fs, usage_id)
runtime.parse_asides(node, definition_id, usage_id, runtime.id_generator)
aside_children = runtime.parse_asides(node, definition_id, usage_id, runtime.id_generator)
field_data = cls.parse_video_xml(node, runtime.id_generator)
kvs = InheritanceKeyValueStore(initial_values=field_data)
field_data = KvsFieldData(kvs)
Expand All @@ -775,6 +776,9 @@ def parse_xml(cls, node, runtime, _keys):
getattr(runtime.id_generator, 'target_course_id', None)
)

if aside_children:
cls.add_applicable_asides_to_block(video, runtime, aside_children)

return video

def definition_to_xml(self, resource_fs): # lint-amnesty, pylint: disable=too-many-statements
Expand Down
17 changes: 12 additions & 5 deletions xmodule/xml_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,21 @@ def parse_xml(cls, node, runtime, keys): # pylint: disable=too-many-statements
)

if aside_children:
asides_tags = [x.tag for x in aside_children]
asides = runtime.get_asides(xblock)
for asd in asides:
if asd.scope_ids.block_type in asides_tags:
xblock.add_aside(asd)
cls.add_applicable_asides_to_block(xblock, runtime, aside_children)

return xblock

@classmethod
def add_applicable_asides_to_block(cls, block, runtime, aside_children):
"""
Add asides to the block. Moved this out of the parse_xml method to use it in the VideoBlock.parse_xml
"""
asides_tags = [aside_child.tag for aside_child in aside_children]
asides = runtime.get_asides(block)
for aside in asides:
if aside.scope_ids.block_type in asides_tags:
block.add_aside(aside)

@classmethod
def parse_xml_new_runtime(cls, node, runtime, keys):
"""
Expand Down