Skip to content

Commit bf1cc9b

Browse files
committed
fix: udpate test cases to fix for the extracted video block
1 parent 1d51a34 commit bf1cc9b

4 files changed

Lines changed: 53 additions & 20 deletions

File tree

lms/djangoapps/courseware/tests/test_video_handlers.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pytest
1111
import ddt
1212
import freezegun
13+
from django.conf import settings
1314
from django.core.files.base import ContentFile
1415
from django.utils.timezone import now
1516
from django.test import RequestFactory
@@ -48,6 +49,13 @@
4849
Привіт, edX вітає вас.
4950
""")
5051

52+
if settings.USE_EXTRACTED_VIDEO_BLOCK:
53+
path_video_handlers = 'xblocks_contrib.video.video_handlers'
54+
path_transcripts_utils = 'xblocks_contrib.video.video_transcripts_utils'
55+
else:
56+
path_video_handlers = 'xmodule.video_block.video_handlers'
57+
path_transcripts_utils = 'openedx.core.djangoapps.video_config.transcripts_utils'
58+
5159

5260
def _create_srt_file(content=None):
5361
"""
@@ -206,10 +214,17 @@ def test_handle_ajax(self):
206214
{'demoo�': 'sample'}
207215
]
208216
for sample in data:
209-
response = self.clients[self.users[0].username].post(
210-
self.get_url('save_user_state'),
211-
sample,
212-
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
217+
if settings.USE_EXTRACTED_VIDEO_BLOCK:
218+
handler_url = self.get_url('save_user_state', handler_name='ajax_handler')
219+
response = self.clients[self.users[0].username].post(
220+
handler_url,
221+
sample,
222+
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
223+
else:
224+
response = self.clients[self.users[0].username].post(
225+
self.get_url('save_user_state'),
226+
sample,
227+
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
213228
assert response.status_code == 200
214229

215230
assert self.block.speed is None
@@ -320,7 +335,7 @@ def test_multiple_available_translations(self, mock_get_video_transcript_content
320335
assert sorted(json.loads(response.body.decode('utf-8'))) == sorted(['en', 'uk'])
321336

322337
@patch('openedx.core.djangoapps.video_config.transcripts_utils.get_video_transcript_content')
323-
@patch('openedx.core.djangoapps.video_config.transcripts_utils.get_available_transcript_languages')
338+
@patch(f'{path_transcripts_utils}.get_available_transcript_languages')
324339
@ddt.data(
325340
(
326341
['en', 'uk', 'ro'],
@@ -504,7 +519,7 @@ def test_download_transcript_not_exist(self):
504519
assert response.status == '404 Not Found'
505520

506521
@patch(
507-
'xmodule.video_block.video_handlers.get_transcript',
522+
f'{path_video_handlers}.get_transcript',
508523
return_value=('Subs!', 'test_filename.srt', 'application/x-subrip; charset=utf-8')
509524
)
510525
def test_download_srt_exist(self, __):
@@ -515,7 +530,7 @@ def test_download_srt_exist(self, __):
515530
assert response.headers['Content-Language'] == 'en'
516531

517532
@patch(
518-
'xmodule.video_block.video_handlers.get_transcript',
533+
f'{path_video_handlers}.get_transcript',
519534
return_value=('Subs!', 'txt', 'text/plain; charset=utf-8')
520535
)
521536
def test_download_txt_exist(self, __):

lms/djangoapps/courseware/tests/test_video_mongo.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
from xmodule.tests.helpers import mock_render_template, override_descriptor_system # pylint: disable=unused-import
5050
from xmodule.tests.test_import import DummyModuleStoreRuntime
5151
from xmodule.tests.test_video import VideoBlockTestBase
52-
from xmodule.video_block import VideoBlock, bumper_utils, video_utils
52+
from xmodule.video_block import VideoBlock, video_utils
5353
from openedx.core.djangoapps.video_config.transcripts_utils import Transcript, save_to_store, subs_filename
5454
from xmodule.video_block.video_block import EXPORT_IMPORT_COURSE_DIR, EXPORT_IMPORT_STATIC_DIR
5555
from xmodule.x_module import PUBLIC_VIEW, STUDENT_VIEW
@@ -66,6 +66,13 @@
6666
from .test_video_xml import SOURCE_XML, PUBLIC_SOURCE_XML
6767
from common.test.utils import assert_dict_contains_subset
6868

69+
if settings.USE_EXTRACTED_VIDEO_BLOCK:
70+
from xblocks_contrib.video import bumper_utils
71+
bumper_utils_path = 'xblocks_contrib.video.bumper_utils'
72+
else:
73+
from xmodule.video_block import bumper_utils
74+
bumper_utils_path = 'xmodule.video_block.bumper_utils'
75+
6976
TRANSCRIPT_FILE_SRT_DATA = """
7077
1
7178
00:00:14,370 --> 00:00:16,530
@@ -930,7 +937,7 @@ def helper_get_html_with_edx_video_id(self, data):
930937

931938
# pylint: disable=invalid-name
932939
@patch('xblock.utils.resources.ResourceLoader.render_django_template', side_effect=mock_render_template)
933-
@patch('xmodule.video_block.video_block.rewrite_video_url')
940+
@patch(f'{VideoBlock.__module__}.rewrite_video_url')
934941
def test_get_html_cdn_source(self, mocked_get_video, mock_render_django_template):
935942
"""
936943
Test if sources got from CDN
@@ -2323,7 +2330,7 @@ class TestVideoWithBumper(TestVideo): # pylint: disable=test-inherits-tests
23232330
# Use temporary FEATURES in this test without affecting the original
23242331
FEATURES = dict(settings.FEATURES)
23252332

2326-
@patch('xmodule.video_block.bumper_utils.get_bumper_settings')
2333+
@patch(f'{bumper_utils_path}.get_bumper_settings')
23272334
def test_is_bumper_enabled(self, get_bumper_settings):
23282335
"""
23292336
Check that bumper is (not)shown if ENABLE_VIDEO_BUMPER is (False)True
@@ -2348,8 +2355,8 @@ def test_is_bumper_enabled(self, get_bumper_settings):
23482355
assert not bumper_utils.is_bumper_enabled(self.block)
23492356

23502357
@patch('xblock.utils.resources.ResourceLoader.render_django_template', side_effect=mock_render_template)
2351-
@patch('xmodule.video_block.bumper_utils.is_bumper_enabled')
2352-
@patch('xmodule.video_block.bumper_utils.get_bumper_settings')
2358+
@patch(f'{bumper_utils_path}.is_bumper_enabled')
2359+
@patch(f'{bumper_utils_path}.get_bumper_settings')
23532360
@patch('edxval.api.get_urls_for_profiles')
23542361
def test_bumper_metadata(
23552362
self, get_url_for_profiles, get_bumper_settings, is_bumper_enabled, mock_render_django_template

xmodule/modulestore/tests/test_api.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ def test_get_root_module_name():
2626
Ensure the module name function works with different xblocks.
2727
"""
2828
assert get_root_module_name(LtiConsumerXBlock) == 'lti_consumer'
29-
assert get_root_module_name(VideoBlock) == 'xmodule'
29+
if settings.USE_EXTRACTED_VIDEO_BLOCK:
30+
assert get_root_module_name(VideoBlock) == 'xblocks_contrib'
31+
else:
32+
assert get_root_module_name(VideoBlock) == 'xmodule'
3033
assert get_root_module_name(DoneXBlock) == 'done'
3134

3235

xmodule/tests/test_video.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@
8282
["ur", "Urdu"]
8383
)
8484

85+
if settings.USE_EXTRACTED_VIDEO_BLOCK:
86+
get_available_transcript_languages_path = (
87+
'xblocks_contrib.video.video_transcripts_utils.get_available_transcript_languages'
88+
)
89+
else:
90+
get_available_transcript_languages_path = (
91+
'openedx.core.djangoapps.video_config.transcripts_utils.get_available_transcript_languages'
92+
)
93+
8594

8695
def instantiate_block(**field_data):
8796
"""
@@ -320,7 +329,7 @@ def test_parse_xml(self):
320329

321330
@XBlockAside.register_temp_plugin(AsideTestType, "test_aside")
322331
@patch('xmodule.video_block.video_block.VideoBlock.load_file')
323-
@patch('xmodule.video_block.video_block.is_pointer_tag')
332+
@patch(f'{VideoBlock.__module__}.is_pointer_tag')
324333
@ddt.data(True, False)
325334
def test_parse_xml_with_asides(self, video_xml_has_aside, mock_is_pointer_tag, mock_load_file):
326335
"""Test that `parse_xml` parses asides from the video xml"""
@@ -642,7 +651,7 @@ def test_import_with_float_times(self):
642651
'data': ''
643652
})
644653

645-
@patch('xmodule.video_block.video_block.edxval_api')
654+
@patch(f'{VideoBlock.__module__}.edxval_api')
646655
def test_import_val_data(self, mock_val_api):
647656
"""
648657
Test that `parse_xml` works method works as expected.
@@ -687,7 +696,7 @@ def mock_val_import(xml, edx_video_id, resource_fs, static_dir, external_transcr
687696
course_id='test_course_id'
688697
)
689698

690-
@patch('xmodule.video_block.video_block.edxval_api')
699+
@patch(f'{VideoBlock.__module__}.edxval_api')
691700
def test_import_val_data_invalid(self, mock_val_api):
692701
mock_val_api.ValCannotCreateError = _MockValCannotCreateError
693702
mock_val_api.import_from_xml = Mock(side_effect=mock_val_api.ValCannotCreateError)
@@ -715,7 +724,7 @@ def setUp(self):
715724
self.file_system = OSFS(self.temp_dir)
716725
self.addCleanup(shutil.rmtree, self.temp_dir)
717726

718-
@patch('xmodule.video_block.video_block.edxval_api')
727+
@patch(f'{VideoBlock.__module__}.edxval_api')
719728
def test_export_to_xml(self, mock_val_api):
720729
"""
721730
Test that we write the correct XML on export.
@@ -815,7 +824,7 @@ def test_export_to_xml_without_video_id(self):
815824
expected = etree.XML(xml_string, parser=parser)
816825
self.assertXmlEqual(expected, xml)
817826

818-
@patch('xmodule.video_block.video_block.edxval_api')
827+
@patch(f'{VideoBlock.__module__}.edxval_api')
819828
def test_export_to_xml_val_error(self, mock_val_api):
820829
# Export should succeed without VAL data if video does not exist
821830
mock_val_api.ValVideoNotFoundError = _MockValVideoNotFoundError
@@ -948,8 +957,7 @@ def test_student_view_data(self, field_data, expected_student_view_data):
948957
'openedx.core.djangoapps.video_config.services.VideoConfigService.is_hls_playback_enabled',
949958
Mock(return_value=True)
950959
)
951-
@patch('openedx.core.djangoapps.video_config.transcripts_utils.get_available_transcript_languages',
952-
Mock(return_value=['es']))
960+
@patch(get_available_transcript_languages_path, Mock(return_value=['es']))
953961
@patch('edxval.api.get_video_info_for_course_and_profiles', Mock(return_value={}))
954962
@patch('openedx.core.djangoapps.video_config.transcripts_utils.get_video_transcript_content')
955963
@patch('edxval.api.get_video_info')

0 commit comments

Comments
 (0)