# 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 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 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"] ) 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': '