Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cms/djangoapps/contentstore/tests/test_contentstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from opaque_keys.edx.keys import AssetKey, CourseKey, UsageKey
from opaque_keys.edx.locations import CourseLocator
from path import Path as path
from xblocks_contrib.video import VideoBlock

from cms.djangoapps.contentstore import toggles
from cms.djangoapps.contentstore.config import waffle
Expand Down Expand Up @@ -58,7 +59,6 @@
from xmodule.modulestore.xml_exporter import export_course_to_xml
from xmodule.modulestore.xml_importer import import_course_from_xml, perform_xlint
from xmodule.seq_block import SequenceBlock
from xmodule.video_block import VideoBlock

TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE)
TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex # noqa: UP031
Expand Down
4 changes: 2 additions & 2 deletions cms/djangoapps/contentstore/views/tests/test_course_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def test_reindex_json_responses(self):
course_id=str(self.course.id))
self.assertEqual(response['total'], 1) # noqa: PT009

@mock.patch('xmodule.video_block.VideoBlock.index_dictionary')
@mock.patch('xblocks_contrib.video.VideoBlock.index_dictionary')
def test_reindex_video_error_json_responses(self, mock_index_dictionary):
"""
Test json response with mocked error data for video
Expand Down Expand Up @@ -465,7 +465,7 @@ def test_indexing_responses(self):
course_id=str(self.course.id))
self.assertEqual(response['total'], 1) # noqa: PT009

@mock.patch('xmodule.video_block.VideoBlock.index_dictionary')
@mock.patch('xblocks_contrib.video.VideoBlock.index_dictionary')
def test_indexing_video_error_responses(self, mock_index_dictionary):
"""
Test do_course_reindex response with mocked error data for video
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from edxval.api import create_video
from opaque_keys.edx.keys import UsageKey
from organizations.tests.factories import OrganizationFactory
from xblocks_contrib.video import VideoBlock # pylint: disable=wrong-import-order

from cms.djangoapps.contentstore.tests.utils import CourseTestCase, setup_caption_responses
from openedx.core.djangoapps.content_libraries import api as lib_api
Expand All @@ -32,7 +33,6 @@
from xmodule.contentstore.django import contentstore # pylint: disable=wrong-import-order
from xmodule.exceptions import NotFoundError # pylint: disable=wrong-import-order
from xmodule.modulestore.django import modulestore # pylint: disable=wrong-import-order
from xmodule.video_block import VideoBlock # pylint: disable=wrong-import-order

TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE)
TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex # noqa: UP031
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/course_api/blocks/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def setUp(self):
self.request = RequestFactory().get("/dummy")
self.request.user = self.user

@patch('xmodule.video_block.VideoBlock.student_view_data')
@patch('xblocks_contrib.video.VideoBlock.student_view_data')
def test_video_urls_rewrite(self, video_data_patch):
"""
Verify the video blocks returned have their URL re-written for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def collect_and_transform(self):

@mock.patch('lms.djangoapps.course_blocks.usage_info.CourseUsageInfo')
@mock.patch('openedx.core.djangoapps.waffle_utils.CourseWaffleFlag.is_enabled')
@mock.patch('xmodule.video_block.VideoBlock.student_view_data')
@mock.patch('xblocks_contrib.video.VideoBlock.student_view_data')
def test_write_for_deprecated_youtube_flag_on(self, mock_video_data, deprecate_youtube_flag, usage_info):
"""
Test that video stream priority is written correctly with
Expand Down Expand Up @@ -129,7 +129,7 @@ def test_write_for_deprecated_youtube_flag_on(self, mock_video_data, deprecate_y

@mock.patch('lms.djangoapps.course_blocks.usage_info.CourseUsageInfo')
@mock.patch('openedx.core.djangoapps.waffle_utils.CourseWaffleFlag.is_enabled')
@mock.patch('xmodule.video_block.VideoBlock.student_view_data')
@mock.patch('xblocks_contrib.video.VideoBlock.student_view_data')
def test_write_for_deprecated_youtube_flag_off(self, mock_video_data, deprecate_youtube_flag, usage_info):
"""
Test that video stream priority is written correctly with
Expand Down Expand Up @@ -188,7 +188,7 @@ def test_write_for_deprecated_youtube_flag_off(self, mock_video_data, deprecate_
else:
assert post_transform_data[video_format] == fetched_stream_priority

@mock.patch('xmodule.video_block.VideoBlock.student_view_data')
@mock.patch('xblocks_contrib.video.VideoBlock.student_view_data')
def test_no_priority_for_web_only_videos(self, mock_video_data):
"""
Verify no write attempt is made for the videos
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def collect_and_transform(self):
block_structure=self.block_structure,
)

@mock.patch('xmodule.video_block.VideoBlock.student_view_data')
@mock.patch('xblocks_contrib.video.VideoBlock.student_view_data')
def test_rewrite_for_encoded_videos(self, mock_video_data):
"""
Test that video URLs for videos with available encodings
Expand Down Expand Up @@ -95,7 +95,7 @@ def test_rewrite_for_encoded_videos(self, mock_video_data):
for video_format, video_url in post_transform_data.items():
assert pre_transform_data[video_format] != video_url

@mock.patch('xmodule.video_block.VideoBlock.student_view_data')
@mock.patch('xblocks_contrib.video.VideoBlock.student_view_data')
def test_no_rewrite_for_third_party_vendor(self, mock_video_data):
"""
Test that video URLs aren't re-written for the videos
Expand Down Expand Up @@ -125,7 +125,7 @@ def test_no_rewrite_for_third_party_vendor(self, mock_video_data):
for video_format, video_url in post_transform_data.items():
assert pre_transform_data[video_format] == video_url

@mock.patch('xmodule.video_block.VideoBlock.student_view_data')
@mock.patch('xblocks_contrib.video.VideoBlock.student_view_data')
def test_no_rewrite_for_web_only_videos(self, mock_video_data):
"""
Verify no rewrite attempt is made for the videos
Expand Down
32 changes: 31 additions & 1 deletion lms/djangoapps/course_api/blocks/transformers/video_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,44 @@
Video block URL Transformer
"""

import logging
from urllib.parse import urlparse

from django.conf import settings
from django.core.exceptions import ValidationError
from django.core.validators import URLValidator

from openedx.core.djangoapps.content.block_structure.transformer import BlockStructureTransformer
from xmodule.video_block.video_utils import rewrite_video_url # pylint: disable=wrong-import-order

from .student_view import StudentViewTransformer

log = logging.getLogger(__name__)


def rewrite_video_url(cdn_base_url, original_video_url):
"""
Returns a re-written video URL for cases when an alternate source
has been configured and is selected using factors like user location.

:param cdn_base_url: The scheme, hostname, port and any relevant path prefix for the alternate CDN.
:param original_video_url: The canonical source for this video.
:return: The re-written URL, or None if the result is not a valid URL.
"""
if (not cdn_base_url) or (not original_video_url):
return None

parsed = urlparse(original_video_url)
rewritten_url = cdn_base_url.rstrip("/") + "/" + parsed.path.lstrip("/")
validator = URLValidator()

try:
validator(rewritten_url)
return rewritten_url
except ValidationError:
log.warning("Invalid CDN rewrite URL encountered, %s", rewritten_url)

return None


class VideoBlockURLTransformer(BlockStructureTransformer):
"""
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/courseware/tests/test_block_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
from xblocks_contrib.problem.capa.tests.response_xml_factory import (
OptionResponseXMLFactory, # pylint: disable=reimported
)
from xblocks_contrib.video import VideoBlock # pylint: disable=wrong-import-order

from common.djangoapps.course_modes.models import CourseMode # pylint: disable=reimported
from common.djangoapps.student.models import CourseEnrollment, anonymous_id_for_user
Expand Down Expand Up @@ -114,7 +115,6 @@
)
from xmodule.modulestore.tests.test_asides import AsideTestType # pylint: disable=wrong-import-order
from xmodule.services import RebindUserServiceError
from xmodule.video_block import VideoBlock # pylint: disable=wrong-import-order
from xmodule.x_module import STUDENT_VIEW, ModuleStoreRuntime # pylint: disable=wrong-import-order

TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
Expand Down
Loading
Loading