diff --git a/xblocks_contrib/video/tests/test_video.py b/xblocks_contrib/video/tests/test_video.py index 761a6038..97ce4fe6 100644 --- a/xblocks_contrib/video/tests/test_video.py +++ b/xblocks_contrib/video/tests/test_video.py @@ -311,6 +311,38 @@ def test_parse_xml(self): }, ) + @patch("xblocks_contrib.video.video.VideoBlock.import_video_info_into_val") + def test_parse_xml_new_runtime_keeps_edx_video_id(self, mock_import_into_val): + """ + In the new (content libraries v2) runtime, ``parse_xml_new_runtime`` must + preserve ``edx_video_id`` from the OLX and must NOT import ```` + data into VAL (there is no course to associate the video with). + + Regression test: nulling ``edx_video_id`` here caused library videos to + render "No playable video source" and the ID to vanish from the editor + after save. Videos already present in VAL must keep resolving. + """ + runtime = DummyRuntime(load_error_blocks=True) + edx_video_id = "8e92a901-88cb-4e0c-9999-000000000000" + xml_data = f""" + + """ + node = etree.fromstring(xml_data) + keys = ScopeIds("user", "video", "def_id", "usage_id") + + block = VideoBlock.parse_xml_new_runtime(node, runtime, keys) + + # The fix: edx_video_id survives so videos already in VAL keep working. + assert block.edx_video_id == edx_video_id + # And, unlike the course path (.parse_xml), the new runtime deliberately + # does not push encodings into VAL. + mock_import_into_val.assert_not_called() + @XBlockAside.register_temp_plugin(AsideTestType, "test_aside") @patch("xblocks_contrib.video.video.VideoBlock.load_file") @patch("xblocks_contrib.video.video.is_pointer_tag") diff --git a/xblocks_contrib/video/video.py b/xblocks_contrib/video/video.py index 257d1d39..e4c424a2 100644 --- a/xblocks_contrib/video/video.py +++ b/xblocks_contrib/video/video.py @@ -606,8 +606,11 @@ def parse_xml_new_runtime(cls, node, runtime, keys): if key not in cls.fields: # pylint: disable=unsupported-membership-test continue # parse_video_xml returns some old non-fields like 'source' setattr(video_block, key, cls.fields[key].from_json(val)) - # Don't use VAL in the new runtime: - video_block.edx_video_id = None + # Note: unlike .parse_xml(), we do not import data into VAL here + # (there is no course to associate the video with), but we deliberately keep + # edx_video_id so that videos already present in VAL on this instance keep + # working in content libraries. Nulling it out caused "No playable video + # source" and the ID vanishing from the editor after save. return video_block @classmethod