From 1a3f21080e27efad494f5f63db94852251fcc4d3 Mon Sep 17 00:00:00 2001 From: Feanil Patel <feanil@edx.org> Date: Thu, 7 Nov 2019 10:22:17 -0500 Subject: [PATCH] The type of the attrib object wasn't actually a dict. It was an internal class that we can't easily compare to. So I'm opting to just make the xml output be more consistent and ordered. I was hoping to avoid this since the order shouldn't matter but the juggling we have to do to validate the unorderd data is more complication than it's worth. --- common/lib/xmodule/xmodule/tests/test_video.py | 15 +-------------- .../xmodule/xmodule/video_module/video_module.py | 2 +- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/common/lib/xmodule/xmodule/tests/test_video.py b/common/lib/xmodule/xmodule/tests/test_video.py index 99b95b6fa88..2246cb6106e 100644 --- a/common/lib/xmodule/xmodule/tests/test_video.py +++ b/common/lib/xmodule/xmodule/tests/test_video.py @@ -222,21 +222,8 @@ class VideoBlockTestBase(unittest.TestCase): for attr in ['tag', 'attrib', 'text', 'tail']: expected_attr = getattr(expected, attr) actual_attr = getattr(xml, attr) - - # This is to deal with a special issue in the video descriptor xml output. - # The value of the transcript attribute of the video tag is a serialized - # json string. This can have comparison problems in python3 where the order - # of the dictionary output is not gauranteed to be the same. So the strings - # don't match equally. We convert the parsed json instead so that the - # comparison can be correct. - if isinstance(expected_attr, dict) and \ - isinstance(actual_attr, dict) and \ - 'transcripts' in expected_attr and \ - 'transcripts' in actual_attr: - expected_attr['transcripts'] = json.loads(expected_attr['transcripts']) - actual_attr['transcripts'] = json.loads(actual_attr['transcripts']) - self.assertEqual(expected_attr, actual_attr) + self.assertEqual(get_child_tags(expected), get_child_tags(xml)) for left, right in zip(expected, xml): self.assertXmlEqual(left, right) diff --git a/common/lib/xmodule/xmodule/video_module/video_module.py b/common/lib/xmodule/xmodule/video_module/video_module.py index f3a6f12374f..f2d70dc56a4 100644 --- a/common/lib/xmodule/xmodule/video_module/video_module.py +++ b/common/lib/xmodule/xmodule/video_module/video_module.py @@ -745,7 +745,7 @@ class VideoBlock( xml.set('sub', '') # Update `transcripts` attribute in the xml - xml.set('transcripts', json.dumps(transcripts)) + xml.set('transcripts', json.dumps(transcripts, sort_keys=True)) except edxval_api.ValVideoNotFoundError: pass -- GitLab