Skip to content

Commit ee35515

Browse files
authored
test: Move VideoConfigService related tests near inside its app (#38008)
1 parent 873f42a commit ee35515

2 files changed

Lines changed: 85 additions & 43 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
"""
2+
Tests for VideoConfigService.
3+
"""
4+
5+
import unittest
6+
from unittest.mock import patch
7+
8+
from django.conf import settings
9+
from opaque_keys.edx.locator import CourseLocator
10+
from xblock.field_data import DictFieldData
11+
from xblock.fields import ScopeIds
12+
13+
from openedx.core.djangoapps.video_config.services import VideoConfigService
14+
from xmodule.tests import get_test_descriptor_system
15+
from xmodule.video_block import VideoBlock
16+
17+
18+
class VideoConfigServiceTestCase(unittest.TestCase):
19+
"""
20+
Unit tests for the VideoConfigService class.
21+
"""
22+
23+
def instantiate_video_block(self, **field_data):
24+
"""Instantiate a video block with the given field data (e.g. data=xml_string)."""
25+
if field_data.get('data', None):
26+
field_data = VideoBlock.parse_video_xml(field_data['data'])
27+
system = get_test_descriptor_system()
28+
course_key = CourseLocator('org', 'course', 'run')
29+
usage_key = course_key.make_usage_key('video', 'SampleProblem')
30+
return system.construct_xblock_from_class(
31+
VideoBlock,
32+
scope_ids=ScopeIds(None, None, usage_key, usage_key),
33+
field_data=DictFieldData(field_data),
34+
)
35+
36+
def test_video_with_multiple_transcripts_translation_retrieval(self):
37+
"""
38+
Test translation retrieval of a video block with
39+
multiple transcripts uploaded by a user.
40+
"""
41+
xml_data_transcripts = '''
42+
<video display_name="Test Video"
43+
youtube="1.0:p2Q6BrNhdh8,0.75:izygArpw-Qo,1.25:1EeWXzPdhSA,1.5:rABDYkeK0x8"
44+
show_captions="false"
45+
download_track="false"
46+
start_time="00:00:01"
47+
download_video="false"
48+
end_time="00:01:00">
49+
<source src="http://www.example.com/source.mp4"/>
50+
<track src="http://www.example.com/track"/>
51+
<handout src="http://www.example.com/handout"/>
52+
<transcript language="ge" src="subs_grmtran1.srt" />
53+
<transcript language="hr" src="subs_croatian1.srt" />
54+
</video>
55+
'''
56+
57+
block = self.instantiate_video_block(data=xml_data_transcripts)
58+
video_config_service = block.runtime.service(block, 'video_config')
59+
assert isinstance(video_config_service, VideoConfigService)
60+
translations = video_config_service.available_translations(
61+
block, block.get_transcripts_info()
62+
)
63+
assert sorted(translations) == sorted(['hr', 'ge'])
64+
65+
def test_video_with_no_transcripts_translation_retrieval(self):
66+
"""
67+
Test translation retrieval of a video block with
68+
no transcripts uploaded by a user- ie, that retrieval
69+
does not throw an exception.
70+
"""
71+
block = self.instantiate_video_block(data=None)
72+
video_config_service = block.runtime.service(block, 'video_config')
73+
assert isinstance(video_config_service, VideoConfigService)
74+
translations_with_fallback = video_config_service.available_translations(
75+
block, block.get_transcripts_info()
76+
)
77+
assert translations_with_fallback == ['en']
78+
79+
with patch.dict(settings.FEATURES, FALLBACK_TO_ENGLISH_TRANSCRIPTS=False):
80+
# Some organizations don't have English transcripts for all videos
81+
# This feature makes it configurable
82+
translations_no_fallback = video_config_service.available_translations(
83+
block, block.get_transcripts_info()
84+
)
85+
assert translations_no_fallback == []

xmodule/tests/test_video.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,49 +1080,6 @@ def test_video_with_multiple_transcripts_index_dictionary(self):
10801080
'transcript_ge': 'sprechen sie deutsch? Ja, ich spreche Deutsch',
10811081
'transcript_hr': 'Dobar dan! Kako ste danas?'}, 'content_type': 'Video'}
10821082

1083-
def test_video_with_multiple_transcripts_translation_retrieval(self):
1084-
"""
1085-
Test translation retrieval of a video block with
1086-
multiple transcripts uploaded by a user.
1087-
"""
1088-
xml_data_transcripts = '''
1089-
<video display_name="Test Video"
1090-
youtube="1.0:p2Q6BrNhdh8,0.75:izygArpw-Qo,1.25:1EeWXzPdhSA,1.5:rABDYkeK0x8"
1091-
show_captions="false"
1092-
download_track="false"
1093-
start_time="00:00:01"
1094-
download_video="false"
1095-
end_time="00:01:00">
1096-
<source src="http://www.example.com/source.mp4"/>
1097-
<track src="http://www.example.com/track"/>
1098-
<handout src="http://www.example.com/handout"/>
1099-
<transcript language="ge" src="subs_grmtran1.srt" />
1100-
<transcript language="hr" src="subs_croatian1.srt" />
1101-
</video>
1102-
'''
1103-
1104-
block = instantiate_block(data=xml_data_transcripts)
1105-
video_config_service = block.runtime.service(block, 'video_config')
1106-
translations = video_config_service.available_translations(block, block.get_transcripts_info())
1107-
assert sorted(translations) == sorted(['hr', 'ge'])
1108-
1109-
def test_video_with_no_transcripts_translation_retrieval(self):
1110-
"""
1111-
Test translation retrieval of a video block with
1112-
no transcripts uploaded by a user- ie, that retrieval
1113-
does not throw an exception.
1114-
"""
1115-
block = instantiate_block(data=None)
1116-
video_config_service = block.runtime.service(block, 'video_config')
1117-
translations_with_fallback = video_config_service.available_translations(block, block.get_transcripts_info())
1118-
assert translations_with_fallback == ['en']
1119-
1120-
with patch.dict(settings.FEATURES, FALLBACK_TO_ENGLISH_TRANSCRIPTS=False):
1121-
# Some organizations don't have English transcripts for all videos
1122-
# This feature makes it configurable
1123-
translations_no_fallback = video_config_service.available_translations(block, block.get_transcripts_info())
1124-
assert translations_no_fallback == []
1125-
11261083
@override_settings(ALL_LANGUAGES=ALL_LANGUAGES)
11271084
def test_video_with_language_do_not_have_transcripts_translation(self):
11281085
"""

0 commit comments

Comments
 (0)