Skip to content
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
name: ${{ matrix.shard_name }}(py=${{ matrix.python-version }},dj=${{ matrix.django-version }},mongo=${{ matrix.mongo-version }})
runs-on: ${{ matrix.os-version }}
strategy:
fail-fast: false
matrix:
python-version:
- "3.11"
Expand Down
23 changes: 12 additions & 11 deletions lms/djangoapps/courseware/tests/test_video_mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
from common.djangoapps.xblock_django.constants import ATTR_KEY_REQUEST_COUNTRY_CODE
from lms.djangoapps.courseware.tests.helpers import get_context_dict_from_string
from openedx.core.djangoapps.video_config.toggles import PUBLIC_VIDEO_SHARE
from openedx.core.djangoapps.video_config.utils import VideoSharingUtils
from openedx.core.djangoapps.video_pipeline.config.waffle import DEPRECATE_YOUTUBE
from openedx.core.djangoapps.waffle_utils.models import WaffleFlagCourseOverrideModel
from openedx.core.djangolib.testing.utils import CacheIsolationTestCase
Expand Down Expand Up @@ -261,14 +262,14 @@ def test_is_public_sharing_enabled(self, feature_enabled):
"""Test public video url."""
assert self.block.public_access is True
with self.mock_feature_toggle(enabled=feature_enabled):
assert self.block.is_public_sharing_enabled() == feature_enabled
assert VideoSharingUtils.is_public_sharing_enabled(self.block) == feature_enabled

def test_is_public_sharing_enabled__not_public(self):
self.block.public_access = False
with self.mock_feature_toggle():
assert not self.block.is_public_sharing_enabled()
assert not VideoSharingUtils.is_public_sharing_enabled(self.block)

@patch('xmodule.video_block.video_block.VideoBlock.get_course_video_sharing_override')
@patch('openedx.core.djangoapps.video_config.utils.VideoSharingUtils.get_course_video_sharing_override')
def test_is_public_sharing_enabled_by_course_override(self, mock_course_sharing_override):

# Given a course overrides all videos to be shared
Expand All @@ -277,47 +278,47 @@ def test_is_public_sharing_enabled_by_course_override(self, mock_course_sharing_

# When I try to determine if public sharing is enabled
with self.mock_feature_toggle():
is_public_sharing_enabled = self.block.is_public_sharing_enabled()
is_public_sharing_enabled = VideoSharingUtils.is_public_sharing_enabled(self.block)

# Then I will get that course value
self.assertTrue(is_public_sharing_enabled)

@patch('xmodule.video_block.video_block.VideoBlock.get_course_video_sharing_override')
@patch('openedx.core.djangoapps.video_config.utils.VideoSharingUtils.get_course_video_sharing_override')
def test_is_public_sharing_disabled_by_course_override(self, mock_course_sharing_override):
# Given a course overrides no videos to be shared
mock_course_sharing_override.return_value = COURSE_VIDEO_SHARING_NONE
self.block.public_access = 'some-arbitrary-value'

# When I try to determine if public sharing is enabled
with self.mock_feature_toggle():
is_public_sharing_enabled = self.block.is_public_sharing_enabled()
is_public_sharing_enabled = VideoSharingUtils.is_public_sharing_enabled(self.block)

# Then I will get that course value
self.assertFalse(is_public_sharing_enabled)

@ddt.data(COURSE_VIDEO_SHARING_PER_VIDEO, None)
@patch('xmodule.video_block.video_block.VideoBlock.get_course_video_sharing_override')
@patch('openedx.core.djangoapps.video_config.utils.VideoSharingUtils.get_course_video_sharing_override')
def test_is_public_sharing_enabled_per_video(self, mock_override_value, mock_course_sharing_override):
# Given a course does not override per-video settings
mock_course_sharing_override.return_value = mock_override_value
self.block.public_access = 'some-arbitrary-value'

# When I try to determine if public sharing is enabled
with self.mock_feature_toggle():
is_public_sharing_enabled = self.block.is_public_sharing_enabled()
is_public_sharing_enabled = VideoSharingUtils.is_public_sharing_enabled(self.block)

# I will get the per-video value
self.assertEqual(self.block.public_access, is_public_sharing_enabled)

@patch('xmodule.video_block.video_block.get_course_by_id')
@patch('openedx.core.lib.courses.get_course_by_id')
def test_is_public_sharing_course_not_found(self, mock_get_course):
# Given a course does not override per-video settings
mock_get_course.side_effect = Http404()
self.block.public_access = 'some-arbitrary-value'

# When I try to determine if public sharing is enabled
with self.mock_feature_toggle():
is_public_sharing_enabled = self.block.is_public_sharing_enabled()
is_public_sharing_enabled = VideoSharingUtils.is_public_sharing_enabled(self.block)

# I will fall-back to per-video values
self.assertEqual(self.block.public_access, is_public_sharing_enabled)
Expand All @@ -326,7 +327,7 @@ def test_is_public_sharing_course_not_found(self, mock_get_course):
def test_context(self, is_public_sharing_enabled):
with self.mock_feature_toggle():
with patch.object(
self.block,
VideoSharingUtils,
'is_public_sharing_enabled',
return_value=is_public_sharing_enabled
):
Expand Down
3 changes: 2 additions & 1 deletion lms/djangoapps/courseware/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.djangoapps.util.user_messages import PageLevelMessages
from openedx.core.djangoapps.video_config.toggles import PUBLIC_VIDEO_SHARE
from openedx.core.djangoapps.video_config.utils import VideoSharingUtils
from openedx.core.djangoapps.zendesk_proxy.utils import create_zendesk_ticket
from openedx.core.djangolib.markup import HTML, Text
from openedx.core.lib.courses import get_course_by_id
Expand Down Expand Up @@ -1869,7 +1870,7 @@ def get_course_and_video_block(self, usage_key_string):
)

# Block must be marked as public to be viewed
if not video_block.is_public_sharing_enabled():
if not VideoSharingUtils.is_public_sharing_enabled(video_block):
raise Http404("Video not found.")

return course, video_block
Expand Down
2 changes: 0 additions & 2 deletions openedx/core/djangoapps/video_config/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
for the extracted video block in xblocks-contrib repository.
"""

from django.conf import settings

import logging

from opaque_keys.edx.keys import CourseKey, UsageKey
Expand Down
3 changes: 3 additions & 0 deletions xmodule/modulestore/split_mongo/caching_descriptor_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from xmodule.modulestore.split_mongo.split_mongo_kvs import SplitMongoKVS
from xmodule.util.misc import get_library_or_course_attribute
from xmodule.x_module import XModuleMixin
from openedx.core.djangoapps.video_config.services import VideoConfigService

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -242,6 +243,8 @@ def service(self, block, service_name):
self.block_field_datas[block] = None
raise
return self.block_field_datas[block]
elif service_name == 'video_config':
return VideoConfigService()
return super().service(block, service_name)

def _init_field_data_for_block(self, block):
Expand Down
4 changes: 3 additions & 1 deletion xmodule/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from xmodule.tests.helpers import StubReplaceURLService, mock_render_template, StubMakoService, StubUserService
from xmodule.util.sandboxing import SandboxService
from xmodule.x_module import DoNothingCache, XModuleMixin
from openedx.core.djangoapps.video_config.services import VideoConfigService
from openedx.core.lib.cache_utils import CacheService


Expand Down Expand Up @@ -242,14 +243,15 @@ def get_test_descriptor_system(render_template=None, **kwargs):
Construct a test DescriptorSystem instance.
"""
field_data = DictFieldData({})
video_config = VideoConfigService()

descriptor_system = TestDescriptorSystem(
load_item=Mock(name='get_test_descriptor_system.load_item'),
resources_fs=Mock(name='get_test_descriptor_system.resources_fs'),
error_tracker=Mock(name='get_test_descriptor_system.error_tracker'),
render_template=render_template or mock_render_template,
mixins=(InheritanceMixin, XModuleMixin),
services={'field-data': field_data},
services={'field-data': field_data, 'video_config': video_config},
**kwargs
)
descriptor_system.get_asides = lambda block: []
Expand Down
5 changes: 1 addition & 4 deletions xmodule/video_block/video_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from edx_django_utils.cache import RequestCache
from lxml import etree
from opaque_keys.edx.locator import AssetLocator
from organizations.api import get_course_organization
from web_fragments.fragment import Fragment
from xblock.completable import XBlockCompletionMode
from xblock.core import XBlock
Expand All @@ -33,10 +32,9 @@

from common.djangoapps.xblock_django.constants import ATTR_KEY_REQUEST_COUNTRY_CODE, ATTR_KEY_USER_ID
from openedx.core.djangoapps.video_config.models import HLSPlaybackEnabledFlag, CourseYoutubeBlockedFlag
from openedx.core.djangoapps.video_config.toggles import PUBLIC_VIDEO_SHARE, TRANSCRIPT_FEEDBACK
from openedx.core.djangoapps.video_config.toggles import TRANSCRIPT_FEEDBACK
from openedx.core.djangoapps.video_pipeline.config.waffle import DEPRECATE_YOUTUBE
from openedx.core.lib.cache_utils import request_cached
from openedx.core.lib.courses import get_course_by_id
from openedx.core.lib.license import LicenseMixin
from xmodule.contentstore.content import StaticContent
from xmodule.editing_block import EditingMixin
Expand All @@ -54,7 +52,6 @@
)
from xmodule.xml_block import XmlMixin, deserialize_field, is_pointer_tag, name_to_pathname
from .bumper_utils import bumperize
from .sharing_sites import sharing_sites_info_for_video
from .transcripts_utils import (
Transcript,
VideoTranscriptsMixin,
Expand Down
Loading