From 48f6febf1c5c47182db5f1572f40aa4b001562f1 Mon Sep 17 00:00:00 2001 From: farhan Date: Tue, 3 Feb 2026 12:31:18 +0500 Subject: [PATCH 1/2] chore: Original test cases code copeid from edx-platform * It has been placed as first commit for the east of code review, so the code reviewer could see the change differences easily --- xblocks_contrib/video/tests/test_video.py | 1221 +++++++++++++++++++++ 1 file changed, 1221 insertions(+) create mode 100644 xblocks_contrib/video/tests/test_video.py diff --git a/xblocks_contrib/video/tests/test_video.py b/xblocks_contrib/video/tests/test_video.py new file mode 100644 index 0000000..14288a4 --- /dev/null +++ b/xblocks_contrib/video/tests/test_video.py @@ -0,0 +1,1221 @@ +# This test case has been migrated from edx-platform/xmodule/tests/test_video.py + +# pylint: disable=protected-access +"""Test for Video XBlock functional logic. +These test data read from xml, not from mongo. + +We have a ModuleStoreTestCase class defined in +xmodule/modulestore/tests/django_utils.py. You can +search for usages of this in the cms and lms tests for examples. You use +this so that it will do things like point the modulestore setting to mongo, +flush the contentstore before and after, load the templates, etc. +You can then use the CourseFactory and BlockFactory as defined +in xmodule/modulestore/tests/factories.py to create +the course, section, subsection, unit, etc. +""" + + +import datetime +import json +import shutil +import unittest +from tempfile import mkdtemp +from uuid import uuid4 +from unittest.mock import ANY, MagicMock, Mock, patch + +import pytest +import ddt +from django.conf import settings +from django.test import TestCase +from django.test.utils import override_settings +from fs.osfs import OSFS +from lxml import etree +from opaque_keys.edx.keys import CourseKey +from opaque_keys.edx.locator import CourseLocator +from xblock.field_data import DictFieldData +from xblock.fields import ScopeIds + +from xmodule.tests import get_test_descriptor_system +from xmodule.validation import StudioValidationMessage +from xmodule.video_block import EXPORT_IMPORT_STATIC_DIR, VideoBlock, create_youtube_string +from openedx.core.djangoapps.video_config.transcripts_utils import save_to_store +from xblock.core import XBlockAside +from xmodule.modulestore.tests.test_asides import AsideTestType + +from .test_import import DummyModuleStoreRuntime + +SRT_FILEDATA = ''' +0 +00:00:00,270 --> 00:00:02,720 +sprechen sie deutsch? + +1 +00:00:02,720 --> 00:00:05,430 +Ja, ich spreche Deutsch +''' + +CRO_SRT_FILEDATA = ''' +0 +00:00:00,270 --> 00:00:02,720 +Dobar dan! + +1 +00:00:02,720 --> 00:00:05,430 +Kako ste danas? +''' + +YOUTUBE_SUBTITLES = ( + "Sample trascript line 1. " + "Sample trascript line 2. " + "Sample trascript line 3." +) + +MOCKED_YOUTUBE_TRANSCRIPT_API_RESPONSE = ''' + + Sample trascript line 1. + Sample trascript line 2. + Sample trascript line 3. + +''' + +ALL_LANGUAGES = ( + ["en", "English"], + ["eo", "Esperanto"], + ["ur", "Urdu"] +) + +if settings.USE_EXTRACTED_VIDEO_BLOCK: + get_available_transcript_languages_path = ( + 'xblocks_contrib.video.video_transcripts_utils.get_available_transcript_languages' + ) +else: + get_available_transcript_languages_path = ( + 'openedx.core.djangoapps.video_config.transcripts_utils.get_available_transcript_languages' + ) + + +def instantiate_block(**field_data): + """ + Instantiate block with most properties. + """ + if field_data.get('data', None): + field_data = VideoBlock.parse_video_xml(field_data['data']) + system = get_test_descriptor_system() + course_key = CourseLocator('org', 'course', 'run') + usage_key = course_key.make_usage_key('video', 'SampleProblem') + return system.construct_xblock_from_class( + VideoBlock, + scope_ids=ScopeIds(None, None, usage_key, usage_key), + field_data=DictFieldData(field_data), + ) + + +# Because of the way xmodule.video_block.video_block imports edxval.api, we +# must mock the entire module, which requires making mock exception classes. + +class _MockValVideoNotFoundError(Exception): + """Mock ValVideoNotFoundError exception""" + pass # lint-amnesty, pylint: disable=unnecessary-pass + + +class _MockValCannotCreateError(Exception): + """Mock ValCannotCreateError exception""" + pass # lint-amnesty, pylint: disable=unnecessary-pass + + +class VideoBlockTest(unittest.TestCase): + """Logic tests for Video XBlock.""" + + raw_field_data = { + 'data': '