From 2472bbe4688753bce0b4000c11088f9f6ae9b026 Mon Sep 17 00:00:00 2001 From: farhan Date: Fri, 13 Feb 2026 18:50:39 +0500 Subject: [PATCH] chore: Move VideoConfigService tests near inside its app --- .../video_config/tests/test_services.py | 81 +++++++++++++++++++ xmodule/tests/test_video.py | 43 ---------- 2 files changed, 81 insertions(+), 43 deletions(-) create mode 100644 openedx/core/djangoapps/video_config/tests/test_services.py diff --git a/openedx/core/djangoapps/video_config/tests/test_services.py b/openedx/core/djangoapps/video_config/tests/test_services.py new file mode 100644 index 000000000000..56317c795d8d --- /dev/null +++ b/openedx/core/djangoapps/video_config/tests/test_services.py @@ -0,0 +1,81 @@ +""" +Tests for VideoConfigService. +""" + +from unittest.mock import patch + +from django.conf import settings +from opaque_keys.edx.locator import CourseLocator +from xblock.field_data import DictFieldData +from xblock.fields import ScopeIds + +from openedx.core.djangoapps.video_config.services import VideoConfigService +from xmodule.tests import get_test_descriptor_system +from xmodule.video_block import VideoBlock + + +def _instantiate_video_block(**field_data): + """Instantiate a video block with the given field data (e.g. data=xml_string).""" + 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), + ) + + +def test_video_with_multiple_transcripts_translation_retrieval(): + """ + Test translation retrieval of a video block with + multiple transcripts uploaded by a user. + """ + xml_data_transcripts = ''' + + ''' + + block = _instantiate_video_block(data=xml_data_transcripts) + video_config_service = block.runtime.service(block, 'video_config') + assert isinstance(video_config_service, VideoConfigService) + translations = video_config_service.available_translations( + block, block.get_transcripts_info() + ) + assert sorted(translations) == sorted(['hr', 'ge']) + + +def test_video_with_no_transcripts_translation_retrieval(): + """ + Test translation retrieval of a video block with + no transcripts uploaded by a user- ie, that retrieval + does not throw an exception. + """ + block = _instantiate_video_block(data=None) + video_config_service = block.runtime.service(block, 'video_config') + assert isinstance(video_config_service, VideoConfigService) + translations_with_fallback = video_config_service.available_translations( + block, block.get_transcripts_info() + ) + assert translations_with_fallback == ['en'] + + with patch.dict(settings.FEATURES, FALLBACK_TO_ENGLISH_TRANSCRIPTS=False): + # Some organizations don't have English transcripts for all videos + # This feature makes it configurable + translations_no_fallback = video_config_service.available_translations( + block, block.get_transcripts_info() + ) + assert translations_no_fallback == [] diff --git a/xmodule/tests/test_video.py b/xmodule/tests/test_video.py index aa03c15851cb..e6bfbc516888 100644 --- a/xmodule/tests/test_video.py +++ b/xmodule/tests/test_video.py @@ -1080,49 +1080,6 @@ def test_video_with_multiple_transcripts_index_dictionary(self): 'transcript_ge': 'sprechen sie deutsch? Ja, ich spreche Deutsch', 'transcript_hr': 'Dobar dan! Kako ste danas?'}, 'content_type': 'Video'} - def test_video_with_multiple_transcripts_translation_retrieval(self): - """ - Test translation retrieval of a video block with - multiple transcripts uploaded by a user. - """ - xml_data_transcripts = ''' - - ''' - - block = instantiate_block(data=xml_data_transcripts) - video_config_service = block.runtime.service(block, 'video_config') - translations = video_config_service.available_translations(block, block.get_transcripts_info()) - assert sorted(translations) == sorted(['hr', 'ge']) - - def test_video_with_no_transcripts_translation_retrieval(self): - """ - Test translation retrieval of a video block with - no transcripts uploaded by a user- ie, that retrieval - does not throw an exception. - """ - block = instantiate_block(data=None) - video_config_service = block.runtime.service(block, 'video_config') - translations_with_fallback = video_config_service.available_translations(block, block.get_transcripts_info()) - assert translations_with_fallback == ['en'] - - with patch.dict(settings.FEATURES, FALLBACK_TO_ENGLISH_TRANSCRIPTS=False): - # Some organizations don't have English transcripts for all videos - # This feature makes it configurable - translations_no_fallback = video_config_service.available_translations(block, block.get_transcripts_info()) - assert translations_no_fallback == [] - @override_settings(ALL_LANGUAGES=ALL_LANGUAGES) def test_video_with_language_do_not_have_transcripts_translation(self): """