From 537e81dba023f576732a42a7f9f4f8c6541afbbd Mon Sep 17 00:00:00 2001 From: "M. Tayyab Tahir Qureshi" Date: Mon, 13 Oct 2025 16:39:36 +0500 Subject: [PATCH] fix: fix test cases --- .github/workflows/unit-tests.yml | 1 + .../courseware/tests/test_video_mongo.py | 23 ++++++++++--------- lms/djangoapps/courseware/views/views.py | 3 ++- .../core/djangoapps/video_config/services.py | 2 -- .../split_mongo/caching_descriptor_system.py | 3 +++ xmodule/tests/__init__.py | 4 +++- xmodule/video_block/video_block.py | 5 +--- 7 files changed, 22 insertions(+), 19 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 05e5f47d1aae..efb555a75679 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -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" diff --git a/lms/djangoapps/courseware/tests/test_video_mongo.py b/lms/djangoapps/courseware/tests/test_video_mongo.py index 851cdd213507..acead91cea9c 100644 --- a/lms/djangoapps/courseware/tests/test_video_mongo.py +++ b/lms/djangoapps/courseware/tests/test_video_mongo.py @@ -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 @@ -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 @@ -277,12 +278,12 @@ 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 @@ -290,13 +291,13 @@ def test_is_public_sharing_disabled_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.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 @@ -304,12 +305,12 @@ def test_is_public_sharing_enabled_per_video(self, mock_override_value, mock_cou # 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() @@ -317,7 +318,7 @@ def test_is_public_sharing_course_not_found(self, mock_get_course): # 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) @@ -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 ): diff --git a/lms/djangoapps/courseware/views/views.py b/lms/djangoapps/courseware/views/views.py index 2c89800d82b6..f199245e7af9 100644 --- a/lms/djangoapps/courseware/views/views.py +++ b/lms/djangoapps/courseware/views/views.py @@ -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 @@ -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 diff --git a/openedx/core/djangoapps/video_config/services.py b/openedx/core/djangoapps/video_config/services.py index dec1544f8289..d7c533b33c17 100644 --- a/openedx/core/djangoapps/video_config/services.py +++ b/openedx/core/djangoapps/video_config/services.py @@ -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 diff --git a/xmodule/modulestore/split_mongo/caching_descriptor_system.py b/xmodule/modulestore/split_mongo/caching_descriptor_system.py index a83fec32bac0..78a53f9aa031 100644 --- a/xmodule/modulestore/split_mongo/caching_descriptor_system.py +++ b/xmodule/modulestore/split_mongo/caching_descriptor_system.py @@ -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__) @@ -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): diff --git a/xmodule/tests/__init__.py b/xmodule/tests/__init__.py index 786836c050b5..2d1ccdc12698 100644 --- a/xmodule/tests/__init__.py +++ b/xmodule/tests/__init__.py @@ -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 @@ -242,6 +243,7 @@ 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'), @@ -249,7 +251,7 @@ def get_test_descriptor_system(render_template=None, **kwargs): 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: [] diff --git a/xmodule/video_block/video_block.py b/xmodule/video_block/video_block.py index d1dfef89911f..81a1041f3813 100644 --- a/xmodule/video_block/video_block.py +++ b/xmodule/video_block/video_block.py @@ -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 @@ -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 @@ -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,