diff --git a/cms/djangoapps/cms_user_tasks/tests.py b/cms/djangoapps/cms_user_tasks/tests.py index 9e4f91cb4979..fd75dfa34230 100644 --- a/cms/djangoapps/cms_user_tasks/tests.py +++ b/cms/djangoapps/cms_user_tasks/tests.py @@ -4,7 +4,6 @@ import json import logging from unittest import mock -from unittest.mock import patch from uuid import uuid4 import botocore @@ -254,7 +253,7 @@ def test_email_sent_with_olx_validations_with_config_enabled(self): *self.olx_validations['warnings'] ] - with patch.dict(settings.FEATURES, ENABLE_COURSE_OLX_VALIDATION=True): + with override_settings(ENABLE_COURSE_OLX_VALIDATION=True): user_task_stopped.send(sender=UserTaskStatus, status=self.status) msg = mail.outbox[0] @@ -277,12 +276,12 @@ def test_email_sent_with_olx_validations_with_default_config(self): msg = mail.outbox[0] # Verify olx validation is not enabled out of the box. - self.assertFalse(settings.FEATURES.get('ENABLE_COURSE_OLX_VALIDATION')) # noqa: PT009 + self.assertFalse(getattr(settings, 'ENABLE_COURSE_OLX_VALIDATION', False)) # noqa: PT009 self.assertEqual(len(mail.outbox), 1) # noqa: PT009 self.assert_msg_subject(msg) self.assert_msg_body_fragments(msg, body_fragments) - @patch.dict(settings.FEATURES, ENABLE_COURSE_OLX_VALIDATION=True) + @override_settings(ENABLE_COURSE_OLX_VALIDATION=True) @override_waffle_flag(BYPASS_OLX_FAILURE, active=True) def test_email_sent_with_olx_validations_with_bypass_flag(self): """ diff --git a/cms/djangoapps/contentstore/api/tests/test_validation.py b/cms/djangoapps/contentstore/api/tests/test_validation.py index a34faf516219..579f72c4e5f7 100644 --- a/cms/djangoapps/contentstore/api/tests/test_validation.py +++ b/cms/djangoapps/contentstore/api/tests/test_validation.py @@ -7,7 +7,6 @@ import ddt import factory -from django.conf import settings from django.contrib.auth import get_user_model from django.test.utils import override_settings from django.urls import reverse @@ -106,8 +105,7 @@ def test_student_fails(self): ) @ddt.unpack def test_staff_succeeds(self, certs_html_view, with_modes): - features = dict(settings.FEATURES, CERTIFICATES_HTML_VIEW=certs_html_view) - with override_settings(FEATURES=features): + with override_settings(CERTIFICATES_HTML_VIEW=certs_html_view): if with_modes: CourseModeFactory.create_batch( 2, diff --git a/cms/djangoapps/contentstore/exams.py b/cms/djangoapps/contentstore/exams.py index 384dd1041e7a..55b4be8fc07d 100644 --- a/cms/djangoapps/contentstore/exams.py +++ b/cms/djangoapps/contentstore/exams.py @@ -27,7 +27,7 @@ def register_exams(course_key): Likewise, if formerly registered exams are not included in the payload they will be marked inactive by the exam service. """ - if not settings.FEATURES.get('ENABLE_SPECIAL_EXAMS') or not exams_ida_enabled(course_key): + if not getattr(settings, 'ENABLE_SPECIAL_EXAMS', False) or not exams_ida_enabled(course_key): # if feature is not enabled then do a quick exit return diff --git a/cms/djangoapps/contentstore/proctoring.py b/cms/djangoapps/contentstore/proctoring.py index 7e00327eeea7..a2249df4efc4 100644 --- a/cms/djangoapps/contentstore/proctoring.py +++ b/cms/djangoapps/contentstore/proctoring.py @@ -35,7 +35,7 @@ def register_special_exams(course_key): subsystem. Likewise, if formerly registered exams are unmarked, then those registered exams are marked as inactive """ - if not settings.FEATURES.get('ENABLE_SPECIAL_EXAMS'): + if not getattr(settings, 'ENABLE_SPECIAL_EXAMS', False): # if feature is not enabled then do a quick exit return diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/home.py b/cms/djangoapps/contentstore/rest_api/v1/views/home.py index bbc68fd2031f..59038fa3af3d 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/home.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/home.py @@ -90,7 +90,7 @@ def get(self, request: Request): ), 'studio_name': settings.STUDIO_NAME, 'studio_short_name': settings.STUDIO_SHORT_NAME, - 'studio_request_email': settings.FEATURES.get('STUDIO_REQUEST_EMAIL', ''), + 'studio_request_email': getattr(settings, 'STUDIO_REQUEST_EMAIL', ''), 'tech_support_email': settings.TECH_SUPPORT_EMAIL, 'platform_name': settings.PLATFORM_NAME, 'user_is_active': request.user.is_active, diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/settings.py b/cms/djangoapps/contentstore/rest_api/v1/views/settings.py index d5f24fe81ddb..4e639a735fb6 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/settings.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/settings.py @@ -117,7 +117,7 @@ def get(self, request: Request, course_id: str): 'course_display_name': course_block.display_name, 'course_display_name_with_default': course_block.display_name_with_default, 'platform_name': settings.PLATFORM_NAME, - 'licensing_enabled': settings.FEATURES.get("LICENSING", False), + 'licensing_enabled': getattr(settings, 'LICENSING', False), }) serializer = CourseSettingsSerializer(settings_context) diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_proctoring.py b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_proctoring.py index 6d84fad453d0..c5e579dea18d 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_proctoring.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_proctoring.py @@ -4,7 +4,6 @@ from unittest.mock import patch import ddt -from django.conf import settings from django.test.utils import override_settings from django.urls import reverse from edx_toggles.toggles.testutils import override_waffle_flag @@ -272,9 +271,7 @@ def test_update_exam_settings_excluded_field(self): ) def test_update_exam_settings_invalid_value(self): self.client.login(username=self.global_staff.username, password=self.password) - PROCTORED_EXAMS_ENABLED_FEATURES = settings.FEATURES - PROCTORED_EXAMS_ENABLED_FEATURES["ENABLE_PROCTORED_EXAMS"] = True - with override_settings(FEATURES=PROCTORED_EXAMS_ENABLED_FEATURES): + with override_settings(ENABLE_PROCTORED_EXAMS=True): data = self.get_request_data( enable_proctored_exams=True, proctoring_provider="notvalidprovider", @@ -366,42 +363,38 @@ def test_nonadmin_with_zendesk_ticket( @override_waffle_flag(EXAMS_IDA, active=True) def test_200_for_lti_provider(self): self.client.login(username=self.global_staff.username, password=self.password) - PROCTORED_EXAMS_ENABLED_FEATURES = settings.FEATURES - PROCTORED_EXAMS_ENABLED_FEATURES["ENABLE_PROCTORED_EXAMS"] = True - with override_settings(FEATURES=PROCTORED_EXAMS_ENABLED_FEATURES): + with override_settings(ENABLE_PROCTORED_EXAMS=True): data = self.get_request_data( enable_proctored_exams=True, proctoring_provider="lti_external", ) response = self.make_request(data=data) - # response is correct - assert response.status_code == status.HTTP_200_OK - - self.assertDictEqual( # noqa: PT009 - response.data, - { - "proctored_exam_settings": { - "enable_proctored_exams": True, - "allow_proctoring_opt_out": True, - "proctoring_provider": "lti_external", - "proctoring_escalation_email": None, - "create_zendesk_tickets": True, - } - }, - ) + # response is correct + assert response.status_code == status.HTTP_200_OK + + self.assertDictEqual( # noqa: PT009 + response.data, + { + "proctored_exam_settings": { + "enable_proctored_exams": True, + "allow_proctoring_opt_out": True, + "proctoring_provider": "lti_external", + "proctoring_escalation_email": None, + "create_zendesk_tickets": True, + } + }, + ) - # course settings have been updated - updated = modulestore().get_item(self.course.location) - assert updated.enable_proctored_exams is True - assert updated.proctoring_provider == "lti_external" + # course settings have been updated + updated = modulestore().get_item(self.course.location) + assert updated.enable_proctored_exams is True + assert updated.proctoring_provider == "lti_external" @override_waffle_flag(EXAMS_IDA, active=False) def test_400_for_disabled_lti(self): self.client.login(username=self.global_staff.username, password=self.password) - PROCTORED_EXAMS_ENABLED_FEATURES = settings.FEATURES - PROCTORED_EXAMS_ENABLED_FEATURES["ENABLE_PROCTORED_EXAMS"] = True - with override_settings(FEATURES=PROCTORED_EXAMS_ENABLED_FEATURES): + with override_settings(ENABLE_PROCTORED_EXAMS=True): data = self.get_request_data( enable_proctored_exams=True, proctoring_provider="lti_external", diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index 4561926c1b8d..d09a40ba71ef 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -1333,50 +1333,50 @@ def test_create_course_with_bad_organization(self): self.course_data['org'] = 'University of California, Berkeley' self.assert_course_creation_failed(r"(?s)Unable to create course 'Robot Super Course'.*") + @override_settings(DISABLE_COURSE_CREATION=True) def test_create_course_with_course_creation_disabled_staff(self): """Test new course creation -- course creation disabled, but staff access.""" - with mock.patch.dict('django.conf.settings.FEATURES', {'DISABLE_COURSE_CREATION': True}): - self.assert_created_course() + self.assert_created_course() + @override_settings(DISABLE_COURSE_CREATION=True) def test_create_course_with_course_creation_disabled_not_staff(self): """Test new course creation -- error path for course creation disabled, not staff access.""" - with mock.patch.dict('django.conf.settings.FEATURES', {'DISABLE_COURSE_CREATION': True}): - self.user.is_staff = False - self.user.save() - self.assert_course_permission_denied() + self.user.is_staff = False + self.user.save() + self.assert_course_permission_denied() + @override_settings(ENABLE_CREATOR_GROUP=True) def test_create_course_no_course_creators_staff(self): """Test new course creation -- course creation group enabled, staff, group is empty.""" - with mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_CREATOR_GROUP': True}): - self.assert_created_course() + self.assert_created_course() + @override_settings(ENABLE_CREATOR_GROUP=True) def test_create_course_no_course_creators_not_staff(self): """Test new course creation -- error path for course creator group enabled, not staff, group is empty.""" - with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}): - self.user.is_staff = False - self.user.save() - self.assert_course_permission_denied() + self.user.is_staff = False + self.user.save() + self.assert_course_permission_denied() + @override_settings(ENABLE_CREATOR_GROUP=True) def test_create_course_with_course_creator(self): """Test new course creation -- use course creator group""" - with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}): - auth.add_users(self.user, CourseCreatorRole(), self.user) - self.assert_created_course() + auth.add_users(self.user, CourseCreatorRole(), self.user) + self.assert_created_course() + @override_settings(ALLOW_UNICODE_COURSE_ID=False) def test_create_course_with_unicode_in_id_disabled(self): """ Test new course creation with feature setting: ALLOW_UNICODE_COURSE_ID disabled. """ - with mock.patch.dict('django.conf.settings.FEATURES', {'ALLOW_UNICODE_COURSE_ID': False}): - error_message = "Special characters not allowed in organization, course number, and course run." - self.course_data['org'] = '��������������' - self.assert_create_course_failed(error_message) + error_message = "Special characters not allowed in organization, course number, and course run." + self.course_data['org'] = '��������������' + self.assert_create_course_failed(error_message) - self.course_data['number'] = '��chantillon' - self.assert_create_course_failed(error_message) + self.course_data['number'] = '��chantillon' + self.assert_create_course_failed(error_message) - self.course_data['run'] = '����������' - self.assert_create_course_failed(error_message) + self.course_data['run'] = '����������' + self.assert_create_course_failed(error_message) def assert_course_permission_denied(self): """ @@ -2014,13 +2014,13 @@ def test_rerun_course_fail_duplicate_course(self): # Verify that the existing course continues to be in the course listing self.assertInCourseListing(existent_course_key) + @override_settings(ENABLE_CREATOR_GROUP=True) def test_rerun_with_permission_denied(self): - with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}): - source_course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split) - auth.add_users(self.user, CourseCreatorRole(), self.user) - self.user.is_staff = False - self.user.save() - self.post_rerun_request(source_course.id, response_code=403, expect_error=True) + source_course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split) + auth.add_users(self.user, CourseCreatorRole(), self.user) + self.user.is_staff = False + self.user.save() + self.post_rerun_request(source_course.id, response_code=403, expect_error=True) def test_rerun_error(self): error_message = "Mock Error Message" diff --git a/cms/djangoapps/contentstore/tests/test_course_create_rerun.py b/cms/djangoapps/contentstore/tests/test_course_create_rerun.py index fbcf56067ac1..fbd3e0df8126 100644 --- a/cms/djangoapps/contentstore/tests/test_course_create_rerun.py +++ b/cms/djangoapps/contentstore/tests/test_course_create_rerun.py @@ -195,7 +195,7 @@ def test_course_creation_for_known_organization(self, organizations_autocreate): self.assertEqual(len(course_orgs), 1) # noqa: PT009 self.assertEqual(course_orgs[0]['short_name'], 'orgX') # noqa: PT009 - @override_settings(FEATURES={'ENABLE_CREATOR_GROUP': True}) + @override_settings(ENABLE_CREATOR_GROUP=True) def test_course_creation_when_user_not_in_org(self): """ Tests course creation when user doesn't have the required role. @@ -208,7 +208,7 @@ def test_course_creation_when_user_not_in_org(self): }) self.assertEqual(response.status_code, 403) # noqa: PT009 - @override_settings(FEATURES={'ENABLE_CREATOR_GROUP': True}) + @override_settings(ENABLE_CREATOR_GROUP=True) @mock.patch( 'cms.djangoapps.course_creators.admin.render_to_string', mock.Mock(side_effect=mock_render_to_string, autospec=True) @@ -235,7 +235,7 @@ def test_course_creation_when_user_in_org_with_creator_role(self): }) self.assertEqual(response.status_code, 200) # noqa: PT009 - @override_settings(FEATURES={'ENABLE_CREATOR_GROUP': True}) + @override_settings(ENABLE_CREATOR_GROUP=True) @mock.patch( 'cms.djangoapps.course_creators.admin.render_to_string', mock.Mock(side_effect=mock_render_to_string, autospec=True) @@ -262,7 +262,7 @@ def test_course_creation_with_all_org_checked(self): }) self.assertEqual(response.status_code, 200) # noqa: PT009 - @override_settings(FEATURES={'ENABLE_CREATOR_GROUP': True}) + @override_settings(ENABLE_CREATOR_GROUP=True) @mock.patch( 'cms.djangoapps.course_creators.admin.render_to_string', mock.Mock(side_effect=mock_render_to_string, autospec=True) @@ -291,7 +291,7 @@ def test_course_creation_with_permission_for_specific_organization(self): }) self.assertEqual(response.status_code, 200) # noqa: PT009 - @override_settings(FEATURES={'ENABLE_CREATOR_GROUP': True}) + @override_settings(ENABLE_CREATOR_GROUP=True) @mock.patch( 'cms.djangoapps.course_creators.admin.render_to_string', mock.Mock(side_effect=mock_render_to_string, autospec=True) @@ -420,7 +420,7 @@ def setUp(self): # ------------------------------------------------------------ # CREATE COURSE -- Non-staff users and existing Organization # ------------------------------------------------------------ - @override_settings(FEATURES={"DISABLE_COURSE_CREATION": False}) + @override_settings(DISABLE_COURSE_CREATION=False) def test_create_course_unauthorized(self): """ User without role cannot create course. @@ -435,7 +435,7 @@ def test_create_course_unauthorized(self): assert response.status_code == 403 - @override_settings(FEATURES={"DISABLE_COURSE_CREATION": False}) + @override_settings(DISABLE_COURSE_CREATION=False) def test_create_course_unauthorized_with_role(self): """ User with role but without required permission cannot create course. @@ -477,7 +477,7 @@ def test_create_course_staff(self): # ------------------------------------------------------------ # FEATURE FLAG # ------------------------------------------------------------ - @override_settings(FEATURES={"DISABLE_COURSE_CREATION": True}) + @override_settings(DISABLE_COURSE_CREATION=True) def test_create_course_disabled_by_flag(self): """ Even authorized users cannot create course if feature flag is off. diff --git a/cms/djangoapps/contentstore/tests/test_course_settings.py b/cms/djangoapps/contentstore/tests/test_course_settings.py index 720a021ecb3f..5bece89466fa 100644 --- a/cms/djangoapps/contentstore/tests/test_course_settings.py +++ b/cms/djangoapps/contentstore/tests/test_course_settings.py @@ -337,7 +337,7 @@ def test_invalid_pre_requisite_course(self): response = self.client.ajax_post(url, course_detail_json) self.assertEqual(400, response.status_code) # noqa: PT009 - @unittest.skipUnless(settings.FEATURES.get('ENTRANCE_EXAMS', False), True) + @unittest.skipUnless(getattr(settings, 'ENTRANCE_EXAMS', False), True) def test_entrance_exam_created_updated_and_deleted_successfully(self): """ This tests both of the entrance exam settings and the `any_unfulfilled_milestones` helper. @@ -396,7 +396,7 @@ def test_entrance_exam_created_updated_and_deleted_successfully(self): self.assertFalse(milestones_helpers.any_unfulfilled_milestones(self.course.id, self.user.id), # noqa: PT009 msg='The entrance exam should not be required anymore') - @unittest.skipUnless(settings.FEATURES.get('ENTRANCE_EXAMS', False), True) + @unittest.skipUnless(getattr(settings, 'ENTRANCE_EXAMS', False), True) def test_entrance_exam_store_default_min_score(self): """ test that creating an entrance exam should store the default value, if key missing in json request @@ -435,7 +435,7 @@ def test_entrance_exam_store_default_min_score(self): self.assertTrue(course.entrance_exam_enabled) # noqa: PT009 self.assertEqual(course.entrance_exam_minimum_score_pct, .5) # noqa: PT009 - @unittest.skipUnless(settings.FEATURES.get('ENTRANCE_EXAMS', False), True) + @unittest.skipUnless(getattr(settings, 'ENTRANCE_EXAMS', False), True) @mock.patch.dict("django.conf.settings.FEATURES", {'ENABLE_PREREQUISITE_COURSES': True}) def test_entrance_after_changing_other_setting(self): """ diff --git a/cms/djangoapps/contentstore/tests/test_exams.py b/cms/djangoapps/contentstore/tests/test_exams.py index 6974c234c019..6a300a9f542e 100644 --- a/cms/djangoapps/contentstore/tests/test_exams.py +++ b/cms/djangoapps/contentstore/tests/test_exams.py @@ -7,6 +7,7 @@ import ddt from django.conf import settings +from django.test.utils import override_settings from edx_toggles.toggles.testutils import override_waffle_flag from freezegun import freeze_time from pytz import utc @@ -19,8 +20,7 @@ @ddt.ddt @override_waffle_flag(EXAMS_IDA, active=True) -@patch.dict('django.conf.settings.FEATURES', {'ENABLE_PROCTORED_EXAMS': True}) -@patch.dict('django.conf.settings.FEATURES', {'ENABLE_SPECIAL_EXAMS': True}) +@override_settings(ENABLE_PROCTORED_EXAMS=True, ENABLE_SPECIAL_EXAMS=True) @patch('cms.djangoapps.contentstore.exams._patch_course_exams') @patch('cms.djangoapps.contentstore.signals.handlers.transaction.on_commit', new=Mock(side_effect=lambda func: func()),) # run right away @@ -160,7 +160,7 @@ def test_dangling_exam(self, mock_patch_course_exams): listen_for_course_publish(self, self.course.id) mock_patch_course_exams.assert_called_once_with([], self.course_key) - @patch.dict('django.conf.settings.FEATURES', {'ENABLE_SPECIAL_EXAMS': False}) + @override_settings(ENABLE_SPECIAL_EXAMS=False) def test_feature_flag_off(self, mock_patch_course_exams): """ Make sure the feature flag is honored diff --git a/cms/djangoapps/contentstore/tests/test_libraries.py b/cms/djangoapps/contentstore/tests/test_libraries.py index 29a194fd017e..9ce85d525d26 100644 --- a/cms/djangoapps/contentstore/tests/test_libraries.py +++ b/cms/djangoapps/contentstore/tests/test_libraries.py @@ -574,12 +574,12 @@ def test_creation(self): # Now check that logged-in users without CourseCreator role cannot create libraries self._login_as_non_staff_user(logout_first=False) - with patch.dict('django.conf.settings.FEATURES', {'ENABLE_CREATOR_GROUP': True}): + with override_settings(ENABLE_CREATOR_GROUP=True): self._assert_cannot_create_library(expected_code=403) # 403 user is not CourseCreator # Now check that logged-in users with CourseCreator role can create libraries add_user_with_status_granted(self.user, self.non_staff_user) - with patch.dict('django.conf.settings.FEATURES', {'ENABLE_CREATOR_GROUP': True}): + with override_settings(ENABLE_CREATOR_GROUP=True): lib_key2 = self._create_library(library="lib2", display_name="Test Library 2") library2 = modulestore().get_library(lib_key2) self.assertIsNotNone(library2) # noqa: PT009 diff --git a/cms/djangoapps/contentstore/tests/test_proctoring.py b/cms/djangoapps/contentstore/tests/test_proctoring.py index 83b46ca2a063..bca0e17bee96 100644 --- a/cms/djangoapps/contentstore/tests/test_proctoring.py +++ b/cms/djangoapps/contentstore/tests/test_proctoring.py @@ -8,6 +8,7 @@ import ddt from django.conf import settings +from django.test import override_settings from edx_proctoring.api import get_all_exams_for_course, get_review_policy_by_exam_id from pytz import UTC @@ -19,7 +20,7 @@ @ddt.ddt -@patch.dict('django.conf.settings.FEATURES', {'ENABLE_SPECIAL_EXAMS': True}) +@override_settings(ENABLE_SPECIAL_EXAMS=True) @patch('cms.djangoapps.contentstore.signals.handlers.transaction.on_commit', new=Mock(side_effect=lambda func: func()),) # run right away class TestProctoredExams(ModuleStoreTestCase): @@ -220,7 +221,7 @@ def test_dangling_exam(self): exam = exams[0] self.assertEqual(exam['is_active'], False) # noqa: PT009 - @patch.dict('django.conf.settings.FEATURES', {'ENABLE_SPECIAL_EXAMS': False}) + @override_settings(ENABLE_SPECIAL_EXAMS=False) def test_feature_flag_off(self): """ Make sure the feature flag is honored diff --git a/cms/djangoapps/contentstore/tests/test_utils.py b/cms/djangoapps/contentstore/tests/test_utils.py index e04cabd226a4..dc402c2eb605 100644 --- a/cms/djangoapps/contentstore/tests/test_utils.py +++ b/cms/djangoapps/contentstore/tests/test_utils.py @@ -6,7 +6,6 @@ from uuid import uuid4 import ddt -from django.conf import settings from django.test import TestCase from django.test.utils import override_settings from opaque_keys.edx.keys import CourseKey @@ -641,7 +640,7 @@ def _get_partition_info(self, schemes=None): return utils.get_user_partition_info(self.block, schemes=schemes) -@patch.dict(settings.FEATURES, ENABLE_COURSE_OLX_VALIDATION=True) +@override_settings(ENABLE_COURSE_OLX_VALIDATION=True) @mock.patch('olxcleaner.validate') @ddt.ddt class ValidateCourseOlxTests(CourseTestCase): @@ -668,7 +667,7 @@ def test_config_settings_enabled(self, mock_olxcleaner_validate): """ Tests olx validation with config setting is disabled. """ - with patch.dict(settings.FEATURES, ENABLE_COURSE_OLX_VALIDATION=False): + with override_settings(ENABLE_COURSE_OLX_VALIDATION=False): self.assertTrue(validate_course_olx(self.course.id, self.toy_course_path, self.status)) # noqa: PT009 self.assertFalse(mock_olxcleaner_validate.called) # noqa: PT009 @@ -676,7 +675,7 @@ def test_config_settings_disabled(self, mock_olxcleaner_validate): """ Tests olx validation with config setting is enabled. """ - with patch.dict(settings.FEATURES, ENABLE_COURSE_OLX_VALIDATION=True): + with override_settings(ENABLE_COURSE_OLX_VALIDATION=True): self.assertTrue(validate_course_olx(self.course.id, self.toy_course_path, self.status)) # noqa: PT009 self.assertTrue(mock_olxcleaner_validate.called) # noqa: PT009 diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index 4c284fb07efb..4f8d42e76d29 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -538,7 +538,7 @@ def course_import_olx_validation_is_enabled(): """ Check if course olx validation is enabled on course import. """ - return settings.FEATURES.get('ENABLE_COURSE_OLX_VALIDATION', False) + return getattr(settings, 'ENABLE_COURSE_OLX_VALIDATION', False) # pylint: disable=invalid-name @@ -1586,7 +1586,7 @@ def get_library_context(request, request_is_json=False): 'user': request.user, 'request_course_creator_url': reverse('request_course_creator'), 'course_creator_status': _get_course_creator_status(request.user), - 'allow_unicode_course_id': settings.FEATURES.get('ALLOW_UNICODE_COURSE_ID', False), + 'allow_unicode_course_id': getattr(settings, 'ALLOW_UNICODE_COURSE_ID', False), 'archived_courses': True, 'allow_course_reruns': settings.FEATURES.get('ALLOW_COURSE_RERUNS', True), 'rerun_creator_status': GlobalStaff().has_user(request.user), @@ -1717,7 +1717,7 @@ def get_home_context(request, no_course=False): 'request_course_creator_url': reverse('request_course_creator'), 'course_creator_status': _get_course_creator_status(user), 'rerun_creator_status': GlobalStaff().has_user(user), - 'allow_unicode_course_id': settings.FEATURES.get('ALLOW_UNICODE_COURSE_ID', False), + 'allow_unicode_course_id': getattr(settings, 'ALLOW_UNICODE_COURSE_ID', False), 'allow_course_reruns': settings.FEATURES.get('ALLOW_COURSE_RERUNS', True), 'active_tab': 'courses', 'allowed_organizations': get_allowed_organizations(user), @@ -1742,7 +1742,7 @@ def get_course_rerun_context(course_key, course_block, user): 'display_name': course_block.display_name, 'user': user, 'course_creator_status': _get_course_creator_status(user), - 'allow_unicode_course_id': settings.FEATURES.get('ALLOW_UNICODE_COURSE_ID', False) + 'allow_unicode_course_id': getattr(settings, 'ALLOW_UNICODE_COURSE_ID', False) } return course_rerun_context diff --git a/cms/djangoapps/contentstore/views/certificate_manager.py b/cms/djangoapps/contentstore/views/certificate_manager.py index 0c36762f8967..af068dbd6b52 100644 --- a/cms/djangoapps/contentstore/views/certificate_manager.py +++ b/cms/djangoapps/contentstore/views/certificate_manager.py @@ -121,7 +121,7 @@ def is_activated(course): """ is_active = False certificates = [] - if settings.FEATURES.get('CERTIFICATES_HTML_VIEW', False): + if getattr(settings, 'CERTIFICATES_HTML_VIEW', False): certificates = CertificateManager.get_certificates(course) # we are assuming only one certificate in certificates collection. for certificate in certificates: diff --git a/cms/djangoapps/contentstore/views/course.py b/cms/djangoapps/contentstore/views/course.py index d3da7b9ec064..cd17c122697f 100644 --- a/cms/djangoapps/contentstore/views/course.py +++ b/cms/djangoapps/contentstore/views/course.py @@ -1173,7 +1173,7 @@ def _create_or_rerun_course(request): raise PermissionDenied() # allow/disable unicode characters in course_id according to settings - if not settings.FEATURES.get('ALLOW_UNICODE_COURSE_ID'): + if not getattr(settings, 'ALLOW_UNICODE_COURSE_ID', False): if _has_non_ascii_characters(org) or _has_non_ascii_characters(course) or _has_non_ascii_characters(run): return JsonResponse( {'error': _('Special characters not allowed in organization, course number, and course run.')}, @@ -2091,9 +2091,9 @@ def _get_course_creator_status(user): if user.is_staff: course_creator_status = 'granted' - elif settings.FEATURES.get('DISABLE_COURSE_CREATION', False): + elif getattr(settings, 'DISABLE_COURSE_CREATION', False): course_creator_status = 'disallowed_for_this_site' - elif settings.FEATURES.get('ENABLE_CREATOR_GROUP', False): + elif getattr(settings, 'ENABLE_CREATOR_GROUP', False): course_creator_status = get_course_creator_status(user) if course_creator_status is None: # User not grandfathered in as an existing user, has not previously visited the dashboard page. @@ -2110,7 +2110,7 @@ def get_allowed_organizations(user): """ Helper method for returning the list of organizations for which the user is allowed to create courses. """ - if settings.FEATURES.get('ENABLE_CREATOR_GROUP', False): + if getattr(settings, 'ENABLE_CREATOR_GROUP', False): return get_organizations(user) else: return [] @@ -2130,7 +2130,7 @@ def get_allowed_organizations_for_libraries(user): # This allows people in the course creator group for an org to create # libraries, which mimics course behavior. - if settings.FEATURES.get('ENABLE_CREATOR_GROUP', False): + if getattr(settings, 'ENABLE_CREATOR_GROUP', False): organizations_set.update(get_organizations(user)) return sorted(organizations_set) @@ -2140,7 +2140,7 @@ def user_can_create_organizations(user): """ Returns True if the user can create organizations. """ - return user.is_staff or not settings.FEATURES.get('ENABLE_CREATOR_GROUP', False) + return user.is_staff or not getattr(settings, 'ENABLE_CREATOR_GROUP', False) def get_organizations_for_non_course_creators(user): diff --git a/cms/djangoapps/contentstore/views/library.py b/cms/djangoapps/contentstore/views/library.py index ecce6b1378ff..d2dce63f75d7 100644 --- a/cms/djangoapps/contentstore/views/library.py +++ b/cms/djangoapps/contentstore/views/library.py @@ -67,7 +67,7 @@ def _user_can_create_library_for_org(user, org=None): return False elif user.is_staff: return True - elif settings.FEATURES.get('ENABLE_CREATOR_GROUP', False): + elif getattr(settings, 'ENABLE_CREATOR_GROUP', False): is_course_creator = get_course_creator_status(user) == 'granted' if is_course_creator: return True @@ -88,7 +88,7 @@ def _user_can_create_library_for_org(user, org=None): else: # EDUCATOR-1924: DISABLE_LIBRARY_CREATION overrides DISABLE_COURSE_CREATION, if present. disable_library_creation = settings.FEATURES.get('DISABLE_LIBRARY_CREATION', None) - disable_course_creation = settings.FEATURES.get('DISABLE_COURSE_CREATION', False) + disable_course_creation = getattr(settings, 'DISABLE_COURSE_CREATION', False) if disable_library_creation is not None: return not disable_library_creation else: diff --git a/cms/djangoapps/contentstore/views/preview.py b/cms/djangoapps/contentstore/views/preview.py index 5e5892fef46b..a30a0ed4686a 100644 --- a/cms/djangoapps/contentstore/views/preview.py +++ b/cms/djangoapps/contentstore/views/preview.py @@ -186,7 +186,7 @@ def _prepare_runtime_for_preview(request, block): ] mako_service = MakoService(namespace_prefix='lms.') - if settings.FEATURES.get("LICENSING", False): + if getattr(settings, 'LICENSING', False): # stick the license wrapper in front wrappers.insert(0, partial(wrap_with_license, mako_service=mako_service)) diff --git a/cms/djangoapps/contentstore/views/tests/test_assets.py b/cms/djangoapps/contentstore/views/tests/test_assets.py index 513a39fe82ab..1df352b70893 100644 --- a/cms/djangoapps/contentstore/views/tests/test_assets.py +++ b/cms/djangoapps/contentstore/views/tests/test_assets.py @@ -38,11 +38,7 @@ MAX_FILE_SIZE = settings.MAX_ASSET_UPLOAD_FILE_SIZE_IN_MB * 1000 ** 2 -FEATURES_WITH_CERTS_ENABLED = settings.FEATURES.copy() -FEATURES_WITH_CERTS_ENABLED['CERTIFICATES_HTML_VIEW'] = True - - -@override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) +@override_settings(CERTIFICATES_HTML_VIEW=True) class AssetsTestCase(CourseTestCase): """ Parent class for all asset tests. diff --git a/cms/djangoapps/contentstore/views/tests/test_block.py b/cms/djangoapps/contentstore/views/tests/test_block.py index d5441ac8bca7..79acf882d523 100644 --- a/cms/djangoapps/contentstore/views/tests/test_block.py +++ b/cms/djangoapps/contentstore/views/tests/test_block.py @@ -3704,7 +3704,7 @@ def test_non_problem_block_is_unmodified(self): assert 'weight' not in metadata_result -@patch.dict("django.conf.settings.FEATURES", {"ENABLE_SPECIAL_EXAMS": True}) +@override_settings(ENABLE_SPECIAL_EXAMS=True) @ddt.ddt class TestSpecialExamXBlockInfo(ItemTest): """ diff --git a/cms/djangoapps/contentstore/views/tests/test_certificates.py b/cms/djangoapps/contentstore/views/tests/test_certificates.py index 0da1596b3986..64942cf7e7a9 100644 --- a/cms/djangoapps/contentstore/views/tests/test_certificates.py +++ b/cms/djangoapps/contentstore/views/tests/test_certificates.py @@ -7,7 +7,6 @@ import json import ddt -from django.conf import settings from django.test.utils import override_settings from opaque_keys.edx.keys import AssetKey @@ -24,9 +23,6 @@ from ..certificate_manager import CERTIFICATE_SCHEMA_VERSION, CertificateManager -FEATURES_WITH_CERTS_ENABLED = settings.FEATURES.copy() -FEATURES_WITH_CERTS_ENABLED['CERTIFICATES_HTML_VIEW'] = True - CERTIFICATE_JSON = { 'name': 'Test certificate', 'description': 'Test description', @@ -195,7 +191,7 @@ def test_certificate_data_validation(self): @ddt.ddt -@override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) +@override_settings(CERTIFICATES_HTML_VIEW=True) class CertificatesListHandlerTestCase( EventTestMixin, CourseTestCase, HelperMethods, UrlResetMixin ): @@ -350,7 +346,7 @@ def test_assign_unique_identifier_to_certificates(self): @ddt.ddt -@override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) +@override_settings(CERTIFICATES_HTML_VIEW=True) class CertificatesDetailHandlerTestCase( EventTestMixin, CourseTestCase, CertificatesBaseTestCase, HelperMethods, UrlResetMixin ): diff --git a/cms/djangoapps/contentstore/views/tests/test_exam_settings_view.py b/cms/djangoapps/contentstore/views/tests/test_exam_settings_view.py index 6a746b8d67ec..f62abb99eeac 100644 --- a/cms/djangoapps/contentstore/views/tests/test_exam_settings_view.py +++ b/cms/djangoapps/contentstore/views/tests/test_exam_settings_view.py @@ -1,7 +1,6 @@ """ Exam Settings View Tests """ -from django.conf import settings from django.test.utils import override_settings from cms.djangoapps.contentstore.tests.utils import CourseTestCase @@ -10,11 +9,8 @@ @override_settings( - FEATURES={ - **settings.FEATURES, - "CERTIFICATES_HTML_VIEW": True, - "ENABLE_PROCTORED_EXAMS": True, - }, + CERTIFICATES_HTML_VIEW=True, + ENABLE_PROCTORED_EXAMS=True, ) @override_settings(COURSE_AUTHORING_MICROFRONTEND_URL='https://mfe.example') class TestExamSettingsView(CourseTestCase, UrlResetMixin): diff --git a/cms/djangoapps/contentstore/views/tests/test_import_export.py b/cms/djangoapps/contentstore/views/tests/test_import_export.py index 8caeb2e84ec1..9f0e7e0a9c35 100644 --- a/cms/djangoapps/contentstore/views/tests/test_import_export.py +++ b/cms/djangoapps/contentstore/views/tests/test_import_export.py @@ -665,7 +665,7 @@ def test_import_failed_with_olx_validations(self, fmt, mocked_report, mocked_sum Mock(), Mock(errors=errors, return_error=Mock(return_value=True)), Mock() ] expected_error_mesg = f'{self.log_prefix} CourseOlx validation failed.' - with patch.dict(settings.FEATURES, ENABLE_COURSE_OLX_VALIDATION=True): + with override_settings(ENABLE_COURSE_OLX_VALIDATION=True): response = self.import_file_in_course(good_file) self.assertEqual(response.status_code, 200) # noqa: PT009 diff --git a/cms/djangoapps/contentstore/views/tests/test_library.py b/cms/djangoapps/contentstore/views/tests/test_library.py index d1c04fec7df0..4e2975f1e86a 100644 --- a/cms/djangoapps/contentstore/views/tests/test_library.py +++ b/cms/djangoapps/contentstore/views/tests/test_library.py @@ -38,7 +38,7 @@ def make_url_for_lib(key): @ddt.ddt -@mock.patch.dict('django.conf.settings.FEATURES', {'DISABLE_COURSE_CREATION': False}) +@override_settings(DISABLE_COURSE_CREATION=False) class UnitTestLibraries(CourseTestCase): """ Unit tests for library views @@ -69,7 +69,7 @@ def test_library_creator_status_with_no_course_creator_role(self): @mock.patch("cms.djangoapps.contentstore.toggles.libraries_v1_enabled", True) def test_library_creator_status_for_enabled_creator_group_setting_for_non_staff_users(self): _, nostaff_user = self.create_non_staff_authed_user_client() - with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}): + with override_settings(ENABLE_CREATOR_GROUP=True): self.assertEqual(user_can_create_library(nostaff_user, None), False) # noqa: PT009 # Global staff can create libraries for any org, even ones that don't exist. @@ -87,14 +87,14 @@ def test_library_creator_status_with_is_staff_user_no_org(self): # When creator groups are enabled, global staff can create libraries in any org @mock.patch("cms.djangoapps.contentstore.toggles.libraries_v1_enabled", True) def test_library_creator_status_for_enabled_creator_group_setting_with_is_staff_user(self): - with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}): + with override_settings(ENABLE_CREATOR_GROUP=True): self.assertEqual(user_can_create_library(self.user, 'RandomOrg'), True) # noqa: PT009 # When creator groups are enabled, course creators can create libraries in any org. @mock.patch("cms.djangoapps.contentstore.toggles.libraries_v1_enabled", True) def test_library_creator_status_with_course_creator_role_for_enabled_creator_group_setting(self): _, nostaff_user = self.create_non_staff_authed_user_client() - with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}): + with override_settings(ENABLE_CREATOR_GROUP=True): grant_course_creator_status(self.user, nostaff_user) self.assertEqual(user_can_create_library(nostaff_user, 'soMeRandOmoRg'), True) # noqa: PT009 @@ -103,7 +103,7 @@ def test_library_creator_status_with_course_creator_role_for_enabled_creator_gro @mock.patch("cms.djangoapps.contentstore.toggles.libraries_v1_enabled", True) def test_library_creator_status_with_course_staff_role_for_enabled_creator_group_setting(self): _, nostaff_user = self.create_non_staff_authed_user_client() - with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}): + with override_settings(ENABLE_CREATOR_GROUP=True): auth.add_users(self.user, CourseStaffRole(self.course.id), nostaff_user) self.assertEqual(user_can_create_library(nostaff_user, self.course.org), True) # noqa: PT009 self.assertEqual(user_can_create_library(nostaff_user, 'SomEOtherOrg'), False) # noqa: PT009 @@ -113,7 +113,7 @@ def test_library_creator_status_with_course_staff_role_for_enabled_creator_group @mock.patch("cms.djangoapps.contentstore.toggles.libraries_v1_enabled", True) def test_library_creator_status_with_course_instructor_role_for_enabled_creator_group_setting(self): _, nostaff_user = self.create_non_staff_authed_user_client() - with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}): + with override_settings(ENABLE_CREATOR_GROUP=True): auth.add_users(self.user, CourseInstructorRole(self.course.id), nostaff_user) self.assertEqual(user_can_create_library(nostaff_user, self.course.org), True) # noqa: PT009 self.assertEqual(user_can_create_library(nostaff_user, 'SomEOtherOrg'), False) # noqa: PT009 @@ -133,16 +133,14 @@ def test_library_creator_status_settings(self, disable_course, disable_library, """ _, nostaff_user = self.create_non_staff_authed_user_client() with mock.patch("cms.djangoapps.contentstore.toggles.libraries_v1_enabled", True): - with mock.patch.dict( - "django.conf.settings.FEATURES", - { - "DISABLE_COURSE_CREATION": disable_course, - "DISABLE_LIBRARY_CREATION": disable_library - } - ): - self.assertEqual(user_can_create_library(nostaff_user, 'SomEOrg'), expected_status) # noqa: PT009 - - @mock.patch.dict('django.conf.settings.FEATURES', {'DISABLE_COURSE_CREATION': True}) + with override_settings(DISABLE_COURSE_CREATION=disable_course): + with mock.patch.dict( + "django.conf.settings.FEATURES", + {"DISABLE_LIBRARY_CREATION": disable_library} + ): + self.assertEqual(user_can_create_library(nostaff_user, 'SomEOrg'), expected_status) # noqa: PT009 + + @override_settings(DISABLE_COURSE_CREATION=True) @mock.patch("cms.djangoapps.contentstore.toggles.libraries_v1_enabled", True) def test_library_creator_status_with_no_course_creator_role_and_disabled_nonstaff_course_creation(self): """ @@ -205,7 +203,7 @@ def test_create_library(self): self.assertEqual(response.status_code, 200) # noqa: PT009 # That's all we check. More detailed tests are in contentstore.tests.test_libraries... - @patch.dict('django.conf.settings.FEATURES', {'ENABLE_CREATOR_GROUP': True}) + @override_settings(ENABLE_CREATOR_GROUP=True) def test_lib_create_permission(self): """ Users who are given course creator roles should be able to create libraries. @@ -219,7 +217,7 @@ def test_lib_create_permission(self): }) self.assertEqual(response.status_code, 200) # noqa: PT009 - @patch.dict('django.conf.settings.FEATURES', {'ENABLE_CREATOR_GROUP': False}) + @override_settings(ENABLE_CREATOR_GROUP=False) def test_lib_create_permission_no_course_creator_role_and_no_course_creator_group(self): """ Users who are not given course creator roles should still be able to create libraries @@ -233,7 +231,7 @@ def test_lib_create_permission_no_course_creator_role_and_no_course_creator_grou }) self.assertEqual(response.status_code, 200) # noqa: PT009 - @patch.dict('django.conf.settings.FEATURES', {'ENABLE_CREATOR_GROUP': True}) + @override_settings(ENABLE_CREATOR_GROUP=True) def test_lib_create_permission_no_course_creator_role_and_no_course_creator_group_and_no_course_staff_role(self): """ Users who are not given course creator roles or course staff role should not be able to create libraries @@ -247,7 +245,7 @@ def test_lib_create_permission_no_course_creator_role_and_no_course_creator_grou }) self.assertEqual(response.status_code, 403) # noqa: PT009 - @patch.dict('django.conf.settings.FEATURES', {'ENABLE_CREATOR_GROUP': True}) + @override_settings(ENABLE_CREATOR_GROUP=True) def test_lib_create_permission_course_staff_role(self): """ Users who are staff on any existing course should able to create libraries @@ -464,14 +462,11 @@ def test_allowed_organizations_for_library(self): 'django.conf.settings.FEATURES', {"ENABLE_ORGANIZATION_STAFF_ACCESS_FOR_CONTENT_LIBRARIES": False} ): - with mock.patch.dict( - 'django.conf.settings.FEATURES', - {"ENABLE_CREATOR_GROUP": False} - ): + with override_settings(ENABLE_CREATOR_GROUP=False): organizations = get_allowed_organizations_for_libraries(self.user) # Assert that the method returned the expected value self.assertEqual(organizations, []) # noqa: PT009 - with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}): + with override_settings(ENABLE_CREATOR_GROUP=True): # Assert that correct org values are returned based on course creator state for course_creator_state in CourseCreator.STATES: course_creator.state = course_creator_state diff --git a/cms/djangoapps/contentstore/views/tests/test_organizations.py b/cms/djangoapps/contentstore/views/tests/test_organizations.py index d88420eac8c2..be9feb2c3000 100644 --- a/cms/djangoapps/contentstore/views/tests/test_organizations.py +++ b/cms/djangoapps/contentstore/views/tests/test_organizations.py @@ -89,44 +89,44 @@ def setUpTestData(cls): ) @override_settings( + ENABLE_CREATOR_GROUP=False, FEATURES={ **settings.FEATURES, 'ENABLE_ORGANIZATION_STAFF_ACCESS_FOR_CONTENT_LIBRARIES': False, - 'ENABLE_CREATOR_GROUP': False, - } + }, ) def test_both_toggles_disabled(self): allowed_orgs = get_allowed_organizations_for_libraries(self.library_author) assert allowed_orgs == [] @override_settings( + ENABLE_CREATOR_GROUP=True, FEATURES={ **settings.FEATURES, 'ENABLE_ORGANIZATION_STAFF_ACCESS_FOR_CONTENT_LIBRARIES': True, - 'ENABLE_CREATOR_GROUP': True, - } + }, ) def test_both_toggles_enabled(self): allowed_orgs = get_allowed_organizations_for_libraries(self.library_author) assert allowed_orgs == ["CreatorOrg", "OrgStaffOrg"] @override_settings( + ENABLE_CREATOR_GROUP=False, FEATURES={ **settings.FEATURES, 'ENABLE_ORGANIZATION_STAFF_ACCESS_FOR_CONTENT_LIBRARIES': True, - 'ENABLE_CREATOR_GROUP': False, - } + }, ) def test_org_staff_enabled(self): allowed_orgs = get_allowed_organizations_for_libraries(self.library_author) assert allowed_orgs == ["OrgStaffOrg"] @override_settings( + ENABLE_CREATOR_GROUP=True, FEATURES={ **settings.FEATURES, 'ENABLE_ORGANIZATION_STAFF_ACCESS_FOR_CONTENT_LIBRARIES': False, - 'ENABLE_CREATOR_GROUP': True, - } + }, ) def test_creator_group_enabled(self): allowed_orgs = get_allowed_organizations_for_libraries(self.library_author) diff --git a/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py b/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py index 4f5e1ccb4244..1ff21c38fb15 100644 --- a/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py +++ b/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py @@ -1385,7 +1385,7 @@ def create_xblock_info( # pylint: disable=too-many-statements ) # update xblock_info with special exam information if the feature flag is enabled - if settings.FEATURES.get("ENABLE_SPECIAL_EXAMS"): + if getattr(settings, 'ENABLE_SPECIAL_EXAMS', False): if xblock.category == "course": xblock_info.update( { diff --git a/cms/djangoapps/course_creators/admin.py b/cms/djangoapps/course_creators/admin.py index aa32d02b2e95..58999d4baf00 100644 --- a/cms/djangoapps/course_creators/admin.py +++ b/cms/djangoapps/course_creators/admin.py @@ -137,7 +137,7 @@ def update_creator_group_callback(sender, **kwargs): # pylint: disable=unused-a def course_creator_notification_context(subject): return { - 'studio_request_email': settings.FEATURES.get('STUDIO_REQUEST_EMAIL', ''), + 'studio_request_email': getattr(settings, 'STUDIO_REQUEST_EMAIL', ''), 'is_secure': (settings.CMS_ROOT_URL or '').split(':')[0].lower() == 'https', 'site': str(get_current_site() or settings.CMS_BASE), 'user_name': subject.username, diff --git a/cms/djangoapps/course_creators/tests/test_admin.py b/cms/djangoapps/course_creators/tests/test_admin.py index 5d0508b5822b..5ed7b87dc95b 100644 --- a/cms/djangoapps/course_creators/tests/test_admin.py +++ b/cms/djangoapps/course_creators/tests/test_admin.py @@ -9,6 +9,7 @@ from django.core import mail from django.http import HttpRequest from django.test import TestCase +from django.test.utils import override_settings from cms.djangoapps.course_creators.admin import CourseCreatorAdmin from cms.djangoapps.course_creators.models import CourseCreator @@ -47,10 +48,6 @@ def setUp(self): self.creator_admin = CourseCreatorAdmin(self.table_entry, AdminSite()) self.studio_request_email = 'mark@marky.mark' - self.enable_creator_group_patch = { - "ENABLE_CREATOR_GROUP": True, - "STUDIO_REQUEST_EMAIL": self.studio_request_email - } self.context = { 'studio_request_email': self.studio_request_email, 'is_secure': False, @@ -59,6 +56,7 @@ def setUp(self): 'user_email': 'test_user+courses@edx.org', } + @override_settings(ENABLE_CREATOR_GROUP=True, STUDIO_REQUEST_EMAIL='mark@marky.mark') @mock.patch('django.contrib.auth.models.User.email_user') def test_change_status(self, email_user): """ @@ -82,25 +80,24 @@ def change_state_and_verify_email(state, is_creator): self.studio_request_email ) - with mock.patch.dict('django.conf.settings.FEATURES', self.enable_creator_group_patch): - - # User is initially unrequested. - self.assertFalse(auth.user_has_role(self.user, CourseCreatorRole())) # noqa: PT009 + # User is initially unrequested. + self.assertFalse(auth.user_has_role(self.user, CourseCreatorRole())) # noqa: PT009 - change_state_and_verify_email(CourseCreator.GRANTED, True) + change_state_and_verify_email(CourseCreator.GRANTED, True) - change_state_and_verify_email(CourseCreator.DENIED, False) + change_state_and_verify_email(CourseCreator.DENIED, False) - change_state_and_verify_email(CourseCreator.GRANTED, True) + change_state_and_verify_email(CourseCreator.GRANTED, True) - change_state_and_verify_email(CourseCreator.PENDING, False) + change_state_and_verify_email(CourseCreator.PENDING, False) - change_state_and_verify_email(CourseCreator.GRANTED, True) + change_state_and_verify_email(CourseCreator.GRANTED, True) - change_state_and_verify_email(CourseCreator.UNREQUESTED, False) + change_state_and_verify_email(CourseCreator.UNREQUESTED, False) - change_state_and_verify_email(CourseCreator.DENIED, False) + change_state_and_verify_email(CourseCreator.DENIED, False) + @override_settings(ENABLE_CREATOR_GROUP=True, STUDIO_REQUEST_EMAIL='mark@marky.mark') def test_mail_admin_on_pending(self): """ Tests that the admin account is notified when a user is in the 'pending' state. @@ -131,18 +128,17 @@ def check_admin_message_state(state, expect_sent_to_admin, expect_sent_to_user): else: self.assertEqual(base_num_emails, len(mail.outbox)) # noqa: PT009 - with mock.patch.dict('django.conf.settings.FEATURES', self.enable_creator_group_patch): - # E-mail message should be sent to admin only when new state is PENDING, regardless of what - # previous state was (unless previous state was already PENDING). - # E-mail message sent to user only on transition into and out of GRANTED state. - check_admin_message_state(CourseCreator.UNREQUESTED, expect_sent_to_admin=False, expect_sent_to_user=False) - check_admin_message_state(CourseCreator.PENDING, expect_sent_to_admin=True, expect_sent_to_user=False) - check_admin_message_state(CourseCreator.GRANTED, expect_sent_to_admin=False, expect_sent_to_user=True) - check_admin_message_state(CourseCreator.DENIED, expect_sent_to_admin=False, expect_sent_to_user=True) - check_admin_message_state(CourseCreator.GRANTED, expect_sent_to_admin=False, expect_sent_to_user=True) - check_admin_message_state(CourseCreator.PENDING, expect_sent_to_admin=True, expect_sent_to_user=True) - check_admin_message_state(CourseCreator.PENDING, expect_sent_to_admin=False, expect_sent_to_user=False) - check_admin_message_state(CourseCreator.DENIED, expect_sent_to_admin=False, expect_sent_to_user=True) + # E-mail message should be sent to admin only when new state is PENDING, regardless of what + # previous state was (unless previous state was already PENDING). + # E-mail message sent to user only on transition into and out of GRANTED state. + check_admin_message_state(CourseCreator.UNREQUESTED, expect_sent_to_admin=False, expect_sent_to_user=False) + check_admin_message_state(CourseCreator.PENDING, expect_sent_to_admin=True, expect_sent_to_user=False) + check_admin_message_state(CourseCreator.GRANTED, expect_sent_to_admin=False, expect_sent_to_user=True) + check_admin_message_state(CourseCreator.DENIED, expect_sent_to_admin=False, expect_sent_to_user=True) + check_admin_message_state(CourseCreator.GRANTED, expect_sent_to_admin=False, expect_sent_to_user=True) + check_admin_message_state(CourseCreator.PENDING, expect_sent_to_admin=True, expect_sent_to_user=True) + check_admin_message_state(CourseCreator.PENDING, expect_sent_to_admin=False, expect_sent_to_user=False) + check_admin_message_state(CourseCreator.DENIED, expect_sent_to_admin=False, expect_sent_to_user=True) def _change_state(self, state): """ Helper method for changing state """ diff --git a/cms/djangoapps/course_creators/tests/test_views.py b/cms/djangoapps/course_creators/tests/test_views.py index 49b7631861dc..d4554263a8bd 100644 --- a/cms/djangoapps/course_creators/tests/test_views.py +++ b/cms/djangoapps/course_creators/tests/test_views.py @@ -3,10 +3,9 @@ """ -from unittest import mock - from django.core.exceptions import PermissionDenied from django.test import TestCase +from django.test.utils import override_settings from django.urls import reverse from cms.djangoapps.course_creators.views import ( @@ -64,35 +63,35 @@ def test_add_unrequested(self): add_user_with_status_granted(self.admin, self.user) self.assertEqual('unrequested', get_course_creator_status(self.user)) # noqa: PT009 + @override_settings(ENABLE_CREATOR_GROUP=True) def test_add_granted(self): - with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}): - # Calling add_user_with_status_granted impacts is_user_in_course_group_role. - self.assertFalse(auth.user_has_role(self.user, CourseCreatorRole())) # noqa: PT009 + # Calling add_user_with_status_granted impacts is_user_in_course_group_role. + self.assertFalse(auth.user_has_role(self.user, CourseCreatorRole())) # noqa: PT009 - add_user_with_status_granted(self.admin, self.user) - self.assertEqual('granted', get_course_creator_status(self.user)) # noqa: PT009 + add_user_with_status_granted(self.admin, self.user) + self.assertEqual('granted', get_course_creator_status(self.user)) # noqa: PT009 - # Calling add again will be a no-op (even if state is different). - add_user_with_status_unrequested(self.user) - self.assertEqual('granted', get_course_creator_status(self.user)) # noqa: PT009 + # Calling add again will be a no-op (even if state is different). + add_user_with_status_unrequested(self.user) + self.assertEqual('granted', get_course_creator_status(self.user)) # noqa: PT009 - self.assertTrue(auth.user_has_role(self.user, CourseCreatorRole())) # noqa: PT009 + self.assertTrue(auth.user_has_role(self.user, CourseCreatorRole())) # noqa: PT009 + @override_settings(ENABLE_CREATOR_GROUP=True) def test_update_creator_group(self): - with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}): - self.assertFalse(auth.user_has_role(self.user, CourseCreatorRole())) # noqa: PT009 - update_course_creator_group(self.admin, self.user, True) - self.assertTrue(auth.user_has_role(self.user, CourseCreatorRole())) # noqa: PT009 - update_course_creator_group(self.admin, self.user, False) - self.assertFalse(auth.user_has_role(self.user, CourseCreatorRole())) # noqa: PT009 + self.assertFalse(auth.user_has_role(self.user, CourseCreatorRole())) # noqa: PT009 + update_course_creator_group(self.admin, self.user, True) + self.assertTrue(auth.user_has_role(self.user, CourseCreatorRole())) # noqa: PT009 + update_course_creator_group(self.admin, self.user, False) + self.assertFalse(auth.user_has_role(self.user, CourseCreatorRole())) # noqa: PT009 + @override_settings(ENABLE_CREATOR_GROUP=True) def test_update_org_content_creator_role(self): - with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}): - self.assertFalse(auth.user_has_role(self.user, OrgContentCreatorRole(self.org))) # noqa: PT009 - update_org_content_creator_role(self.admin, self.user, [self.org]) - self.assertTrue(auth.user_has_role(self.user, OrgContentCreatorRole(self.org))) # noqa: PT009 - update_org_content_creator_role(self.admin, self.user, []) - self.assertFalse(auth.user_has_role(self.user, OrgContentCreatorRole(self.org))) # noqa: PT009 + self.assertFalse(auth.user_has_role(self.user, OrgContentCreatorRole(self.org))) # noqa: PT009 + update_org_content_creator_role(self.admin, self.user, [self.org]) + self.assertTrue(auth.user_has_role(self.user, OrgContentCreatorRole(self.org))) # noqa: PT009 + update_org_content_creator_role(self.admin, self.user, []) + self.assertFalse(auth.user_has_role(self.user, OrgContentCreatorRole(self.org))) # noqa: PT009 def test_user_requested_access(self): add_user_with_status_unrequested(self.user) diff --git a/cms/djangoapps/models/settings/course_metadata.py b/cms/djangoapps/models/settings/course_metadata.py index 8df09f4fe7db..3c5ceb9f43cc 100644 --- a/cms/djangoapps/models/settings/course_metadata.py +++ b/cms/djangoapps/models/settings/course_metadata.py @@ -124,14 +124,14 @@ def get_exclude_list_of_fields(cls, course_key): exclude_list.append('social_sharing_url') # Do not show teams configuration if feature is disabled. - if not settings.FEATURES.get('ENABLE_TEAMS'): + if not getattr(settings, 'ENABLE_TEAMS', False): exclude_list.append('teams_configuration') if not settings.FEATURES.get('ENABLE_VIDEO_BUMPER'): exclude_list.append('video_bumper') # Do not show enable_ccx if feature is not enabled. - if not settings.FEATURES.get('CUSTOM_COURSES_EDX'): + if not getattr(settings, 'CUSTOM_COURSES_EDX', False): exclude_list.append('enable_ccx') exclude_list.append('ccx_connector') diff --git a/cms/urls.py b/cms/urls.py index 7256bf1c5606..39b0c3dc5cf9 100644 --- a/cms/urls.py +++ b/cms/urls.py @@ -265,7 +265,7 @@ contentstore_views.entrance_exam)) # Enable Web/HTML Certificates -if settings.FEATURES.get('CERTIFICATES_HTML_VIEW'): +if getattr(settings, 'CERTIFICATES_HTML_VIEW', False): from cms.djangoapps.contentstore.views.certificates import ( # noqa: I001 - conditional import inside if block CertificateActivationAPIView, CertificateDetailAPIView, diff --git a/common/djangoapps/course_modes/tests/test_views.py b/common/djangoapps/course_modes/tests/test_views.py index d8c5c9641b99..3e59130eae07 100644 --- a/common/djangoapps/course_modes/tests/test_views.py +++ b/common/djangoapps/course_modes/tests/test_views.py @@ -642,7 +642,7 @@ class TrackSelectionEmbargoTest(UrlResetMixin, ModuleStoreTestCase): URLCONF_MODULES = ['openedx.core.djangoapps.embargo'] - @patch.dict(settings.FEATURES, {'EMBARGO': True}) + @override_settings(EMBARGO=True) def setUp(self): super().setUp() @@ -658,7 +658,7 @@ def setUp(self): # Construct the URL for the track selection page self.url = reverse('course_modes_choose', args=[str(self.course.id)]) - @patch.dict(settings.FEATURES, {'EMBARGO': True}) + @override_settings(EMBARGO=True) def test_embargo_restrict(self): with restrict_course(self.course.id) as redirect_url: response = self.client.get(self.url) diff --git a/common/djangoapps/student/auth.py b/common/djangoapps/student/auth.py index f7c3a20e0753..7027470ce992 100644 --- a/common/djangoapps/student/auth.py +++ b/common/djangoapps/student/auth.py @@ -61,10 +61,10 @@ def user_has_role(user, role): # CourseCreator is odd b/c it can be disabled via config if isinstance(role, CourseCreatorRole): # completely shut down course creation setting - if settings.FEATURES.get('DISABLE_COURSE_CREATION', False): + if getattr(settings, 'DISABLE_COURSE_CREATION', False): return False # wide open course creation setting - if not settings.FEATURES.get('ENABLE_CREATOR_GROUP', False): + if not getattr(settings, 'ENABLE_CREATOR_GROUP', False): return True if role.has_user(user): @@ -257,7 +257,7 @@ def _has_content_creator_access(user, org): Returns: bool: True if the user has platform-wide or org-scoped course creation permission. """ - if settings.FEATURES.get("DISABLE_COURSE_CREATION", False): + if getattr(settings, 'DISABLE_COURSE_CREATION', False): return False scope_keys = ( diff --git a/common/djangoapps/student/email_helpers.py b/common/djangoapps/student/email_helpers.py index 7e885b7e0515..dc3d64ec4a1e 100644 --- a/common/djangoapps/student/email_helpers.py +++ b/common/djangoapps/student/email_helpers.py @@ -57,7 +57,7 @@ def generate_proctoring_requirements_email_context(user, course_id): 'course_name': course_block.display_name, 'proctoring_provider': capwords(course_block.proctoring_provider.replace('_', ' ')), 'proctoring_requirements_url': settings.PROCTORING_SETTINGS.get('LINK_URLS', {}).get('faq', ''), - 'idv_required': not settings.FEATURES.get('ENABLE_INTEGRITY_SIGNATURE'), + 'idv_required': not getattr(settings, 'ENABLE_INTEGRITY_SIGNATURE', False), 'id_verification_url': IDVerificationService.get_verify_location(), } diff --git a/common/djangoapps/student/helpers.py b/common/djangoapps/student/helpers.py index 6d3ee2b7cf96..250c44a59200 100644 --- a/common/djangoapps/student/helpers.py +++ b/common/djangoapps/student/helpers.py @@ -122,7 +122,7 @@ def check_verify_status_by_course(user, course_enrollments): status_by_course = {} # If integrity signature is enabled, this is a no-op because IDV is not required - if settings.FEATURES.get('ENABLE_INTEGRITY_SIGNATURE'): + if getattr(settings, 'ENABLE_INTEGRITY_SIGNATURE', False): return status_by_course # Retrieve all verifications for the user, sorted in descending diff --git a/common/djangoapps/student/management/tests/test_recover_account.py b/common/djangoapps/student/management/tests/test_recover_account.py index b0cacdb5d77e..bd1cbf3a8e9b 100644 --- a/common/djangoapps/student/management/tests/test_recover_account.py +++ b/common/djangoapps/student/management/tests/test_recover_account.py @@ -18,8 +18,6 @@ from openedx.core.djangolib.testing.utils import skip_unless_lms LOGGER_NAME = 'common.djangoapps.student.management.commands.recover_account' -FEATURES_WITH_AUTHN_MFE_ENABLED = settings.FEATURES.copy() -FEATURES_WITH_AUTHN_MFE_ENABLED['ENABLE_AUTHN_MICROFRONTEND'] = True class RecoverAccountTests(TestCase): @@ -67,7 +65,7 @@ def test_account_recovery(self): # try to login with previous password assert not self.client.login(username=self.user.username, password='password') - @override_settings(FEATURES=FEATURES_WITH_AUTHN_MFE_ENABLED) + @override_settings(ENABLE_AUTHN_MICROFRONTEND=True) @skip_unless_lms def test_authn_mfe_url_in_reset_link(self): """ diff --git a/common/djangoapps/student/models/user.py b/common/djangoapps/student/models/user.py index 4789f0e47c38..d8f5bf0bac1c 100644 --- a/common/djangoapps/student/models/user.py +++ b/common/djangoapps/student/models/user.py @@ -1284,7 +1284,7 @@ def add_user_to_default_group(user, group): # pylint: disable=missing-function- def create_comments_service_user(user): # pylint: disable=missing-function-docstring - if not settings.FEATURES['ENABLE_DISCUSSION_SERVICE']: + if not getattr(settings, 'ENABLE_DISCUSSION_SERVICE', False): # Don't try--it won't work, and it will fill the logs with lots of errors return try: diff --git a/common/djangoapps/student/tests/test_activate_account.py b/common/djangoapps/student/tests/test_activate_account.py index 12fef9f4de89..3fd6a1b432e8 100644 --- a/common/djangoapps/student/tests/test_activate_account.py +++ b/common/djangoapps/student/tests/test_activate_account.py @@ -17,9 +17,6 @@ from openedx.core.djangolib.testing.utils import skip_unless_lms from openedx.features.enterprise_support.tests.factories import EnterpriseCustomerUserFactory -FEATURES_WITH_AUTHN_MFE_ENABLED = settings.FEATURES.copy() -FEATURES_WITH_AUTHN_MFE_ENABLED['ENABLE_AUTHN_MICROFRONTEND'] = True - @skip_unless_lms class TestActivateAccount(TestCase): @@ -180,7 +177,7 @@ def test_email_confirmation_notification_on_logistration(self): self.assertContains(response, 'Your email could not be confirmed') @override_settings(LOGIN_REDIRECT_WHITELIST=['localhost:1991']) - @override_settings(FEATURES={**FEATURES_WITH_AUTHN_MFE_ENABLED, 'ENABLE_ENTERPRISE_INTEGRATION': True}) + @override_settings(ENABLE_AUTHN_MICROFRONTEND=True, ENABLE_ENTERPRISE_INTEGRATION=True) def test_authenticated_account_activation_with_valid_next_url(self): """ Verify that an activation link with a valid next URL will redirect @@ -234,7 +231,7 @@ def test_account_activation_invalid_next_url_redirects_dashboard(self): self.assertRedirects(response, expected_destination) self._assert_user_active_state(expected_active_state=True) - @override_settings(FEATURES=FEATURES_WITH_AUTHN_MFE_ENABLED) + @override_settings(ENABLE_AUTHN_MICROFRONTEND=True) def test_unauthenticated_user_redirects_to_mfe(self): """ Verify that if Authn MFE is enabled then authenticated user redirects to @@ -259,7 +256,7 @@ def test_unauthenticated_user_redirects_to_mfe(self): assert response.url == (login_page_url + 'error') @override_settings(LOGIN_REDIRECT_WHITELIST=['localhost:1991']) - @override_settings(FEATURES=FEATURES_WITH_AUTHN_MFE_ENABLED) + @override_settings(ENABLE_AUTHN_MICROFRONTEND=True) def test_unauthenticated_user_redirects_to_mfe_with_valid_next_url(self): """ Verify that if Authn MFE is enabled then authenticated user redirects to diff --git a/common/djangoapps/student/tests/test_authz.py b/common/djangoapps/student/tests/test_authz.py index d349da4b1bf6..4e2d980e2e86 100644 --- a/common/djangoapps/student/tests/test_authz.py +++ b/common/djangoapps/student/tests/test_authz.py @@ -53,71 +53,64 @@ def test_creator_group_not_enabled(self): """ assert user_has_role(self.user, CourseCreatorRole()) + @override_settings(ENABLE_CREATOR_GROUP=True) def test_creator_group_enabled_but_empty(self): """ Tests creator group feature on, but group empty. """ - with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}): - assert not user_has_role(self.user, CourseCreatorRole()) + assert not user_has_role(self.user, CourseCreatorRole()) - # Make user staff. This will cause CourseCreatorRole().has_user to return True. - self.user.is_staff = True - assert user_has_role(self.user, CourseCreatorRole()) + # Make user staff. This will cause CourseCreatorRole().has_user to return True. + self.user.is_staff = True + assert user_has_role(self.user, CourseCreatorRole()) + @override_settings(ENABLE_CREATOR_GROUP=True) def test_creator_group_enabled_nonempty(self): """ Tests creator group feature on, user added. """ - with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}): - add_users(self.admin, CourseCreatorRole(), self.user) - assert user_has_role(self.user, CourseCreatorRole()) + add_users(self.admin, CourseCreatorRole(), self.user) + assert user_has_role(self.user, CourseCreatorRole()) - # check that a user who has not been added to the group still returns false - user_not_added = UserFactory.create(username='testuser2', email='test+courses2@edx.org', password='foo2') - assert not user_has_role(user_not_added, CourseCreatorRole()) + # check that a user who has not been added to the group still returns false + user_not_added = UserFactory.create(username='testuser2', email='test+courses2@edx.org', password='foo2') + assert not user_has_role(user_not_added, CourseCreatorRole()) - # remove first user from the group and verify that CourseCreatorRole().has_user now returns false - remove_users(self.admin, CourseCreatorRole(), self.user) - assert not user_has_role(self.user, CourseCreatorRole()) + # remove first user from the group and verify that CourseCreatorRole().has_user now returns false + remove_users(self.admin, CourseCreatorRole(), self.user) + assert not user_has_role(self.user, CourseCreatorRole()) + @override_settings(ENABLE_CREATOR_GROUP=True, DISABLE_COURSE_CREATION=True) def test_course_creation_disabled(self): """ Tests that the COURSE_CREATION_DISABLED flag overrides course creator group settings. """ - with mock.patch.dict('django.conf.settings.FEATURES', - {'DISABLE_COURSE_CREATION': True, "ENABLE_CREATOR_GROUP": True}): - # Add user to creator group. - add_users(self.admin, CourseCreatorRole(), self.user) + # Add user to creator group. + add_users(self.admin, CourseCreatorRole(), self.user) - # DISABLE_COURSE_CREATION overrides (user is not marked as staff). - assert not user_has_role(self.user, CourseCreatorRole()) + # DISABLE_COURSE_CREATION overrides (user is not marked as staff). + assert not user_has_role(self.user, CourseCreatorRole()) - # Mark as staff. Now CourseCreatorRole().has_user returns true. - self.user.is_staff = True - assert user_has_role(self.user, CourseCreatorRole()) + # Mark as staff. Now CourseCreatorRole().has_user returns true. + self.user.is_staff = True + assert user_has_role(self.user, CourseCreatorRole()) - # Remove user from creator group. CourseCreatorRole().has_user still returns true because is_staff=True - remove_users(self.admin, CourseCreatorRole(), self.user) - assert user_has_role(self.user, CourseCreatorRole()) + # Remove user from creator group. CourseCreatorRole().has_user still returns true because is_staff=True + remove_users(self.admin, CourseCreatorRole(), self.user) + assert user_has_role(self.user, CourseCreatorRole()) + @override_settings(ENABLE_CREATOR_GROUP=True, DISABLE_COURSE_CREATION=False) def test_add_user_not_authenticated(self): """ Tests that adding to creator group fails if user is not authenticated """ - with mock.patch.dict( - 'django.conf.settings.FEATURES', - {'DISABLE_COURSE_CREATION': False, "ENABLE_CREATOR_GROUP": True} - ): - anonymous_user = AnonymousUser() - role = CourseCreatorRole() - add_users(self.admin, role, anonymous_user) - assert not user_has_role(anonymous_user, role) + anonymous_user = AnonymousUser() + role = CourseCreatorRole() + add_users(self.admin, role, anonymous_user) + assert not user_has_role(anonymous_user, role) + @override_settings(ENABLE_CREATOR_GROUP=True, DISABLE_COURSE_CREATION=False) def test_add_user_not_active(self): """ Tests that adding to creator group fails if user is not active """ - with mock.patch.dict( - 'django.conf.settings.FEATURES', - {'DISABLE_COURSE_CREATION': False, "ENABLE_CREATOR_GROUP": True} - ): - self.user.is_active = False - add_users(self.admin, CourseCreatorRole(), self.user) - assert not user_has_role(self.user, CourseCreatorRole()) + self.user.is_active = False + add_users(self.admin, CourseCreatorRole(), self.user) + assert not user_has_role(self.user, CourseCreatorRole()) def test_add_user_to_group_requires_staff_access(self): with pytest.raises(PermissionDenied): # noqa: PT012 diff --git a/common/djangoapps/student/tests/test_certificates.py b/common/djangoapps/student/tests/test_certificates.py index a25fe5560ec8..9de3e95844a5 100644 --- a/common/djangoapps/student/tests/test_certificates.py +++ b/common/djangoapps/student/tests/test_certificates.py @@ -1,7 +1,6 @@ """Tests for display of certificates on the student dashboard. """ import datetime -from unittest.mock import patch from zoneinfo import ZoneInfo import ddt @@ -206,8 +205,7 @@ def setUpClass(cls): cls.store.update_item(cls.course, cls.USERNAME) @ddt.data('verified') - @override_settings(CERT_NAME_SHORT='Test_Certificate') - @patch.dict('django.conf.settings.FEATURES', {'CERTIFICATES_HTML_VIEW': True}) + @override_settings(CERT_NAME_SHORT='Test_Certificate', CERTIFICATES_HTML_VIEW=True) def test_linked_student_to_web_view_credential(self, enrollment_mode): cert = self._create_certificate(enrollment_mode) diff --git a/common/djangoapps/student/tests/test_email.py b/common/djangoapps/student/tests/test_email.py index 467eae934e56..8c4788a432ed 100644 --- a/common/djangoapps/student/tests/test_email.py +++ b/common/djangoapps/student/tests/test_email.py @@ -232,8 +232,7 @@ def test_send_email_to_inactive_user(self, email): @ddt.ddt -@patch.dict('django.conf.settings.FEATURES', {'ENABLE_SPECIAL_EXAMS': True}) -@override_settings(ACCOUNT_MICROFRONTEND_URL='http://account-mfe') +@override_settings(ACCOUNT_MICROFRONTEND_URL='http://account-mfe', ENABLE_SPECIAL_EXAMS=True) @skip_unless_lms class ProctoringRequirementsEmailTests(EmailTemplateTagMixin, ModuleStoreTestCase): """ diff --git a/common/djangoapps/student/tests/test_enrollment.py b/common/djangoapps/student/tests/test_enrollment.py index b7f480a8945f..a5705352d3ec 100644 --- a/common/djangoapps/student/tests/test_enrollment.py +++ b/common/djangoapps/student/tests/test_enrollment.py @@ -7,6 +7,7 @@ import ddt import pytest from django.conf import settings +from django.test import override_settings from django.urls import reverse from openedx_events.testing import OpenEdxEventsTestMixin @@ -28,7 +29,7 @@ @ddt.ddt -@patch.dict('django.conf.settings.FEATURES', {'ENABLE_SPECIAL_EXAMS': True}) +@override_settings(ENABLE_SPECIAL_EXAMS=True) @skip_unless_lms class EnrollmentTest(OpenEdxEventsTestMixin, UrlResetMixin, ModuleStoreTestCase): """ @@ -42,7 +43,7 @@ class EnrollmentTest(OpenEdxEventsTestMixin, UrlResetMixin, ModuleStoreTestCase) PASSWORD = "edx" URLCONF_MODULES = ['openedx.core.djangoapps.embargo'] - @patch.dict(settings.FEATURES, {'EMBARGO': True}) + @override_settings(EMBARGO=True) def setUp(self): """ Create a course and user, then log in. """ super().setUp() @@ -274,7 +275,7 @@ def test_upgrade_proctoring_enrollment(self, mode): @patch.dict( 'django.conf.settings.PROCTORING_BACKENDS', {'test_provider_honor_mode': {'allow_honor_mode': True}} ) - @patch.dict(settings.FEATURES, {'ENABLE_PROCTORED_EXAMS': True}) + @override_settings(ENABLE_PROCTORED_EXAMS=True) def test_enroll_in_proctored_course_honor_mode_allowed(self): """ If the proctoring provider allows honor mode, send proctoring requirements email when learners @@ -293,7 +294,7 @@ def test_enroll_in_proctored_course_honor_mode_allowed(self): CourseEnrollment.enroll(self.user, course_honor_mode.id, 'honor') # pylint: disable=no-member assert mock_send_email.called - @patch.dict(settings.FEATURES, {'EMBARGO': True}) + @override_settings(EMBARGO=True) def test_embargo_restrict(self): # When accessing the course from an embargoed country, # we should be blocked. @@ -306,7 +307,7 @@ def test_embargo_restrict(self): is_enrolled = CourseEnrollment.is_enrolled(self.user, self.course.id) assert not is_enrolled - @patch.dict(settings.FEATURES, {'EMBARGO': True}) + @override_settings(EMBARGO=True) def test_embargo_allow(self): response = self._change_enrollment('enroll') assert response.status_code == 200 diff --git a/common/djangoapps/student/tests/tests.py b/common/djangoapps/student/tests/tests.py index c7a0b4c5037c..20819b6b8859 100644 --- a/common/djangoapps/student/tests/tests.py +++ b/common/djangoapps/student/tests/tests.py @@ -80,7 +80,7 @@ def test_process_survey_link(self): link2_expected = f"http://www.mysurvey.com?unique={user_id}" assert process_survey_link(link2, user) == link2_expected - @patch.dict('django.conf.settings.FEATURES', {'CERTIFICATES_HTML_VIEW': False}) + @override_settings(CERTIFICATES_HTML_VIEW=False) def test_cert_info(self): user = UserFactory.create() survey_url = "http://a_survey.com" @@ -477,7 +477,7 @@ def test_linked_in_add_to_profile_btn_not_appearing_without_config(self): self.assertNotContains(response, escape(response_url)) @skip_unless_lms - @patch.dict('django.conf.settings.FEATURES', {'CERTIFICATES_HTML_VIEW': False}) + @override_settings(CERTIFICATES_HTML_VIEW=False) def test_linked_in_add_to_profile_btn_with_certificate(self): # If user has a certificate with valid linked-in config then Add Certificate to LinkedIn button # should be visible. and it has URL value with valid parameters. diff --git a/common/djangoapps/third_party_auth/__init__.py b/common/djangoapps/third_party_auth/__init__.py index 027c4648c460..2821dfdeab80 100644 --- a/common/djangoapps/third_party_auth/__init__.py +++ b/common/djangoapps/third_party_auth/__init__.py @@ -12,5 +12,5 @@ def is_enabled(): return configuration_helpers.get_value( "ENABLE_THIRD_PARTY_AUTH", - settings.FEATURES.get("ENABLE_THIRD_PARTY_AUTH") + getattr(settings, 'ENABLE_THIRD_PARTY_AUTH', False) ) diff --git a/common/djangoapps/third_party_auth/decorators.py b/common/djangoapps/third_party_auth/decorators.py index 58912bc98714..8e2215b44a21 100644 --- a/common/djangoapps/third_party_auth/decorators.py +++ b/common/djangoapps/third_party_auth/decorators.py @@ -21,7 +21,7 @@ def wrapped_view(request, *args, **kwargs): """ Modify the response with the correct X-Frame-Options. """ resp = view_func(request, *args, **kwargs) x_frame_option = settings.X_FRAME_OPTIONS - if settings.FEATURES['ENABLE_THIRD_PARTY_AUTH']: + if getattr(settings, 'ENABLE_THIRD_PARTY_AUTH', False): referer = request.META.get('HTTP_REFERER') if referer is not None: parsed_url = urlparse(referer) diff --git a/common/djangoapps/third_party_auth/models.py b/common/djangoapps/third_party_auth/models.py index 5aaeb9885c1c..e172d3c7d6e5 100644 --- a/common/djangoapps/third_party_auth/models.py +++ b/common/djangoapps/third_party_auth/models.py @@ -70,7 +70,7 @@ def clean_username(username=''): """ Simple helper method to ensure a username is compatible with our system requirements. """ - if settings.FEATURES.get("ENABLE_UNICODE_USERNAME"): + if getattr(settings, 'ENABLE_UNICODE_USERNAME', False): return ('_').join(re.findall(settings.USERNAME_REGEX_PARTIAL, username))[:USERNAME_MAX_LENGTH] else: return ('_').join(re.findall(r'[a-zA-Z0-9\-]+', username))[:USERNAME_MAX_LENGTH] diff --git a/common/djangoapps/third_party_auth/tests/specs/base.py b/common/djangoapps/third_party_auth/tests/specs/base.py index 739806569963..76bc0c13519a 100644 --- a/common/djangoapps/third_party_auth/tests/specs/base.py +++ b/common/djangoapps/third_party_auth/tests/specs/base.py @@ -149,12 +149,12 @@ def assert_register_form_populates_unicode_username_correctly( partial_unicode_username = unicode_username + ascii_substring pipeline_kwargs = pipeline.get(request)["kwargs"] - assert settings.FEATURES["ENABLE_UNICODE_USERNAME"] is False + assert getattr(settings, 'ENABLE_UNICODE_USERNAME', False) is False self._check_registration_form_username(pipeline_kwargs, unicode_username, "") self._check_registration_form_username(pipeline_kwargs, partial_unicode_username, ascii_substring) - with mock.patch.dict("django.conf.settings.FEATURES", {"ENABLE_UNICODE_USERNAME": True}): + with django_utils.override_settings(ENABLE_UNICODE_USERNAME=True): self._check_registration_form_username(pipeline_kwargs, unicode_username, unicode_username) def assert_exception_redirect_looks_correct(self, expected_uri, auth_entry=None): diff --git a/common/djangoapps/third_party_auth/tests/test_decorators.py b/common/djangoapps/third_party_auth/tests/test_decorators.py index b18f0ef0c68b..f72720fc2cb8 100644 --- a/common/djangoapps/third_party_auth/tests/test_decorators.py +++ b/common/djangoapps/third_party_auth/tests/test_decorators.py @@ -48,7 +48,7 @@ def test_x_frame_options(self, url, expected_result): @ddt.data('http://localhost/login', 'http://not-a-real-domain.com', None) def test_feature_flag_off(self, url): - with self.settings(FEATURES={'ENABLE_THIRD_PARTY_AUTH': False}): + with self.settings(ENABLE_THIRD_PARTY_AUTH=False): request = self.construct_request(url) response = mock_view(request) assert response['X-Frame-Options'] == 'DENY' diff --git a/common/djangoapps/third_party_auth/tests/test_models.py b/common/djangoapps/third_party_auth/tests/test_models.py index 4db68fec5d8c..bfdf21d38a06 100644 --- a/common/djangoapps/third_party_auth/tests/test_models.py +++ b/common/djangoapps/third_party_auth/tests/test_models.py @@ -41,14 +41,14 @@ def test_unique_entity_id_enforcement_for_non_current_configs(self): bad_config.save() assert ctx.records[0].msg == f'Entity ID: {self.saml_provider_config.entity_id} already in use' - @override_settings(FEATURES={'ENABLE_UNICODE_USERNAME': False}) + @override_settings(ENABLE_UNICODE_USERNAME=False) def test_clean_username_unicode_disabled(self): """ Test the username cleaner function with unicode disabled """ assert clean_username('ItJüstWòrks™') == 'ItJ_stW_rks' - @override_settings(FEATURES={'ENABLE_UNICODE_USERNAME': True}) + @override_settings(ENABLE_UNICODE_USERNAME=True) def test_clean_username_unicode_enabled(self): """ Test the username cleaner function with unicode enabled diff --git a/common/djangoapps/third_party_auth/tests/test_settings.py b/common/djangoapps/third_party_auth/tests/test_settings.py index 2bc647fee616..3074b85621dd 100644 --- a/common/djangoapps/third_party_auth/tests/test_settings.py +++ b/common/djangoapps/third_party_auth/tests/test_settings.py @@ -62,7 +62,7 @@ def test_social_auth_context_processors(self): assert 'social_django.context_processors.backends' in context_processors assert 'social_django.context_processors.login_redirect' in context_processors - @override_settings(FEATURES={'ENABLE_UNICODE_USERNAME': False}) + @override_settings(ENABLE_UNICODE_USERNAME=False) def test_social_auth_clean_usernames_default(self): """Verify SOCIAL_AUTH_CLEAN_USERNAMES is True when unicode usernames disabled.""" # Note: SOCIAL_AUTH_CLEAN_USERNAMES is a Derived setting, computed at settings load time. diff --git a/common/djangoapps/third_party_auth/tests/testutil.py b/common/djangoapps/third_party_auth/tests/testutil.py index af2696536945..1376cacff231 100644 --- a/common/djangoapps/third_party_auth/tests/testutil.py +++ b/common/djangoapps/third_party_auth/tests/testutil.py @@ -27,7 +27,7 @@ from openedx.core.storage import OverwriteStorage AUTH_FEATURES_KEY = 'ENABLE_THIRD_PARTY_AUTH' -AUTH_FEATURE_ENABLED = AUTH_FEATURES_KEY in settings.FEATURES +AUTH_FEATURE_ENABLED = hasattr(settings, AUTH_FEATURES_KEY) def patch_mako_templates(): diff --git a/common/djangoapps/util/course.py b/common/djangoapps/util/course.py index 6eeaec0966f6..4b2e076bde28 100644 --- a/common/djangoapps/util/course.py +++ b/common/djangoapps/util/course.py @@ -80,7 +80,7 @@ def has_certificates_enabled(course): course: This can be either a course overview object or a course block. Returns a boolean if the course has enabled certificates """ - if not settings.FEATURES.get('CERTIFICATES_HTML_VIEW', False): + if not getattr(settings, 'CERTIFICATES_HTML_VIEW', False): return False return course.cert_html_view_enabled diff --git a/lms/djangoapps/ccx/plugins.py b/lms/djangoapps/ccx/plugins.py index 0fe6327cceca..6a47625907ba 100644 --- a/lms/djangoapps/ccx/plugins.py +++ b/lms/djangoapps/ccx/plugins.py @@ -28,7 +28,7 @@ def is_enabled(cls, course, user=None): """ Returns true if CCX has been enabled and the specified user is a coach """ - if not settings.FEATURES.get('CUSTOM_COURSES_EDX', False) or not course.enable_ccx: + if not getattr(settings, 'CUSTOM_COURSES_EDX', False) or not course.enable_ccx: # If ccx is not enable do not show ccx coach tab. return False diff --git a/lms/djangoapps/ccx/tests/test_views.py b/lms/djangoapps/ccx/tests/test_views.py index 0633f4eb6178..324caad27d7e 100644 --- a/lms/djangoapps/ccx/tests/test_views.py +++ b/lms/djangoapps/ccx/tests/test_views.py @@ -230,7 +230,7 @@ def assert_progress_summary(self, ccx_course_key, due): @patch('lms.djangoapps.ccx.views.render_to_response', intercept_renderer) @patch('lms.djangoapps.courseware.views.views.render_to_response', intercept_renderer) - @patch.dict('django.conf.settings.FEATURES', {'CUSTOM_COURSES_EDX': True}) + @override_settings(CUSTOM_COURSES_EDX=True) def test_edit_schedule(self): """ Get CCX schedule, modify it, save it. @@ -1119,7 +1119,7 @@ def test_coach_tab_for_ccx_advance_settings(self, ccx_feature_flag, enable_ccx, """ Test ccx coach tab state (visible or hidden) depending on the value of enable_ccx flag, ccx feature flag. """ - with self.settings(FEATURES={'CUSTOM_COURSES_EDX': ccx_feature_flag}): + with override_settings(CUSTOM_COURSES_EDX=ccx_feature_flag): course = self.ccx_enabled_course if enable_ccx else self.ccx_disabled_course assert expected_result == self.check_ccx_tab(course, self.user) diff --git a/lms/djangoapps/certificates/apis/v0/tests/test_views.py b/lms/djangoapps/certificates/apis/v0/tests/test_views.py index d08241b2cd79..7b27a03446a4 100644 --- a/lms/djangoapps/certificates/apis/v0/tests/test_views.py +++ b/lms/djangoapps/certificates/apis/v0/tests/test_views.py @@ -6,7 +6,7 @@ from unittest.mock import patch import ddt -from django.conf import settings +from django.test import override_settings from django.urls import reverse from django.utils import timezone from freezegun import freeze_time @@ -382,7 +382,7 @@ def test_query_counts(self): assert resp.status_code == status.HTTP_200_OK assert len(resp.data) == 2 - @patch.dict(settings.FEATURES, {'CERTIFICATES_HTML_VIEW': True}) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_with_no_certificate_configuration(self): """ Verify that certificates are not returned until there is an active diff --git a/lms/djangoapps/certificates/apps.py b/lms/djangoapps/certificates/apps.py index a437bac5a3a7..8ddf090addde 100644 --- a/lms/djangoapps/certificates/apps.py +++ b/lms/djangoapps/certificates/apps.py @@ -23,6 +23,6 @@ def ready(self): # Can't import models at module level in AppConfigs, and models get # included from the signal handlers from lms.djangoapps.certificates import signals # pylint: disable=unused-import # noqa: F401 - if settings.FEATURES.get('ENABLE_SPECIAL_EXAMS'): + if getattr(settings, 'ENABLE_SPECIAL_EXAMS', False): from lms.djangoapps.certificates.services import CertificateService set_runtime_service('certificates', CertificateService()) diff --git a/lms/djangoapps/certificates/tests/test_api.py b/lms/djangoapps/certificates/tests/test_api.py index 08c75a271056..f53011d3c31a 100644 --- a/lms/djangoapps/certificates/tests/test_api.py +++ b/lms/djangoapps/certificates/tests/test_api.py @@ -76,10 +76,6 @@ BETA_TESTER_METHOD = "lms.djangoapps.certificates.api.access.is_beta_tester" CERTS_VIEWABLE_METHOD = "lms.djangoapps.certificates.api.certificates_viewable_for_course" PASSED_OR_ALLOWLISTED_METHOD = "lms.djangoapps.certificates.api._has_passed_or_is_allowlisted" -FEATURES_WITH_CERTS_ENABLED = settings.FEATURES.copy() -FEATURES_WITH_CERTS_ENABLED["CERTIFICATES_HTML_VIEW"] = True - - class WebCertificateTestMixin: """ Mixin with helpers for testing Web Certificates. @@ -191,14 +187,14 @@ def verify_downloadable_pdf_cert(self): "uuid": cert.verify_uuid, } - @patch.dict(settings.FEATURES, {"CERTIFICATES_HTML_VIEW": True}) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_pdf_cert_with_html_enabled(self): self.verify_downloadable_pdf_cert() def test_pdf_cert_with_html_disabled(self): self.verify_downloadable_pdf_cert() - @patch.dict(settings.FEATURES, {"CERTIFICATES_HTML_VIEW": True}) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_with_downloadable_web_cert(self): cert_status = certificate_status_for_student(self.student, self.course.id) assert certificate_downloadable_status(self.student, self.course.id) == { @@ -221,7 +217,7 @@ def test_with_downloadable_web_cert(self): (False, timedelta(days=2), CertificatesDisplayBehaviors.END_WITH_DATE, False, None, True), ) @ddt.unpack - @patch.dict(settings.FEATURES, {"CERTIFICATES_HTML_VIEW": True}) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_cert_api_return( self, self_paced, @@ -476,7 +472,7 @@ def test_no_certificates_for_user(self): """ assert not get_certificates_for_user(self.student_no_cert.username) - @patch.dict(settings.FEATURES, {"CERTIFICATES_HTML_VIEW": True}) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_get_web_certificate_url(self): """ Test the get_certificate_url with a web cert course @@ -490,7 +486,7 @@ def test_get_web_certificate_url(self): cert_url = get_certificate_url(user_id=self.student.id, course_id=self.web_cert_course.id, uuid=self.uuid) assert expected_url == cert_url - @patch.dict(settings.FEATURES, {"CERTIFICATES_HTML_VIEW": True}) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_get_pdf_certificate_url(self): """ Test the get_certificate_url with a pdf cert course @@ -522,7 +518,7 @@ def setUp(self): mode=CourseMode.VERIFIED, ) - @patch.dict(settings.FEATURES, {"CERTIFICATES_HTML_VIEW": False}) + @override_settings(CERTIFICATES_HTML_VIEW=False) def test_cert_url_empty_with_invalid_certificate(self): """ Test certificate url is empty if html view is not enabled and certificate is not yet generated @@ -530,7 +526,7 @@ def test_cert_url_empty_with_invalid_certificate(self): url = get_certificate_url(self.user.id, self.course_run_key) assert url == "" - @patch.dict(settings.FEATURES, {"CERTIFICATES_HTML_VIEW": True}) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_generation(self): """ Test that a cert is successfully generated @@ -546,7 +542,7 @@ def test_generation(self): assert cert.status == CertificateStatuses.downloadable assert cert.mode == CourseMode.VERIFIED - @patch.dict(settings.FEATURES, {"CERTIFICATES_HTML_VIEW": True}) + @override_settings(CERTIFICATES_HTML_VIEW=True) @ddt.data(True, False) def test_generation_unverified(self, enable_idv_requirement): """ @@ -567,7 +563,7 @@ def test_generation_unverified(self, enable_idv_requirement): else: assert cert.status == CertificateStatuses.downloadable - @patch.dict(settings.FEATURES, {"CERTIFICATES_HTML_VIEW": True}) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_generation_notpassing(self): """ Test that a cert is successfully generated with a status of notpassing @@ -652,7 +648,7 @@ def _assert_enabled_for_course(self, course_key, expect_enabled): assert expect_enabled == actual_enabled -@override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) +@override_settings(CERTIFICATES_HTML_VIEW=True) class CertificatesBrandingTest(ModuleStoreTestCase): """Test certificates branding.""" diff --git a/lms/djangoapps/certificates/tests/test_support_views.py b/lms/djangoapps/certificates/tests/test_support_views.py index 80b15112fcac..00cb4a13db33 100644 --- a/lms/djangoapps/certificates/tests/test_support_views.py +++ b/lms/djangoapps/certificates/tests/test_support_views.py @@ -8,7 +8,6 @@ from uuid import uuid4 import ddt -from django.conf import settings from django.test.utils import override_settings from django.urls import reverse from opaque_keys.edx.keys import CourseKey @@ -25,8 +24,6 @@ from xmodule.modulestore.tests.factories import CourseFactory # pylint: disable=wrong-import-order CAN_GENERATE_METHOD = 'lms.djangoapps.certificates.generation_handler._can_generate_regular_certificate' -FEATURES_WITH_CERTS_ENABLED = settings.FEATURES.copy() -FEATURES_WITH_CERTS_ENABLED['CERTIFICATES_HTML_VIEW'] = True class CertificateSupportTestCase(ModuleStoreTestCase): @@ -213,7 +210,7 @@ def test_results(self): assert retrieved_cert['download_url'] == self.CERT_DOWNLOAD_URL assert not retrieved_cert['regenerate'] - @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_download_link(self): self.cert.course_id = self.course_key self.cert.download_url = '' diff --git a/lms/djangoapps/certificates/tests/test_utils.py b/lms/djangoapps/certificates/tests/test_utils.py index e9c7b8787868..8d52140cbdb2 100644 --- a/lms/djangoapps/certificates/tests/test_utils.py +++ b/lms/djangoapps/certificates/tests/test_utils.py @@ -2,10 +2,10 @@ Tests for Certificates app utility functions """ from datetime import datetime, timedelta -from unittest.mock import patch import ddt from django.test import TestCase +from django.test.utils import override_settings from pytz import utc from lms.djangoapps.certificates.utils import has_html_certificates_enabled, should_certificate_be_visible @@ -27,14 +27,14 @@ def setUp(self): super().setUp() self.course_overview = CourseOverviewFactory.create() - @patch.dict('django.conf.settings.FEATURES', {'CERTIFICATES_HTML_VIEW': False}) + @override_settings(CERTIFICATES_HTML_VIEW=False) def test_has_html_certificates_enabled_from_course_overview_cert_html_view_disabled(self): """ Test to ensure we return the correct value when the `CERTIFICATES_HTML_VIEW` setting is disabled. """ assert not has_html_certificates_enabled(self.course_overview) - @patch.dict('django.conf.settings.FEATURES', {'CERTIFICATES_HTML_VIEW': True}) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_has_html_certificates_enabled_from_course_overview_enabled(self): """ Test to ensure we return the correct value when the HTML certificates are enabled in a course-run. @@ -44,7 +44,7 @@ def test_has_html_certificates_enabled_from_course_overview_enabled(self): assert has_html_certificates_enabled(self.course_overview) - @patch.dict('django.conf.settings.FEATURES', {'CERTIFICATES_HTML_VIEW': True}) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_has_html_certificates_enabled_from_course_overview_disabled(self): """ Test to ensure we return the correct value when the HTML certificates are disabled in a course-run. diff --git a/lms/djangoapps/certificates/tests/test_views.py b/lms/djangoapps/certificates/tests/test_views.py index 14c5e027d5c1..4977d2166157 100644 --- a/lms/djangoapps/certificates/tests/test_views.py +++ b/lms/djangoapps/certificates/tests/test_views.py @@ -4,7 +4,6 @@ import datetime from uuid import uuid4 -from django.conf import settings from django.test.client import Client from django.test.utils import override_settings @@ -19,17 +18,6 @@ ) from xmodule.modulestore.tests.factories import CourseFactory # pylint: disable=wrong-import-order -FEATURES_WITH_CERTS_ENABLED = settings.FEATURES.copy() -FEATURES_WITH_CERTS_ENABLED['CERTIFICATES_HTML_VIEW'] = True - -FEATURES_WITH_CERTS_DISABLED = settings.FEATURES.copy() -FEATURES_WITH_CERTS_DISABLED['CERTIFICATES_HTML_VIEW'] = False - -FEATURES_WITH_CUSTOM_CERTS_ENABLED = { - "CUSTOM_CERTIFICATE_TEMPLATES_ENABLED": True -} -FEATURES_WITH_CUSTOM_CERTS_ENABLED.update(FEATURES_WITH_CERTS_ENABLED) - class CertificatesViewsSiteTests(ModuleStoreTestCase): """ @@ -129,7 +117,7 @@ def _add_course_certificates(self, count=1, signatory_count=0, is_active=True): self.course.save() self.store.update_item(self.course, self.user.id) - @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + @override_settings(CERTIFICATES_HTML_VIEW=True) @with_site_configuration(configuration={'platform_name': 'My Platform Site'}) def test_html_view_for_site(self): test_url = get_certificate_url( @@ -149,7 +137,7 @@ def test_html_view_for_site(self): ) self.assertContains(response, 'About My Platform Site') - @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_html_view_site_configuration_missing(self): test_url = get_certificate_url( user_id=self.user.id, @@ -165,7 +153,7 @@ def test_html_view_site_configuration_missing(self): 'This should not survive being overwritten by static content', ) - @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED, GOOGLE_ANALYTICS_4_ID='GA-abc') + @override_settings(CERTIFICATES_HTML_VIEW=True, GOOGLE_ANALYTICS_4_ID='GA-abc') @with_site_configuration(configuration={'platform_name': 'My Platform Site'}) def test_html_view_with_g4(self): test_url = get_certificate_url( diff --git a/lms/djangoapps/certificates/tests/test_webview_views.py b/lms/djangoapps/certificates/tests/test_webview_views.py index 69831716565f..0d5d4d8dad09 100644 --- a/lms/djangoapps/certificates/tests/test_webview_views.py +++ b/lms/djangoapps/certificates/tests/test_webview_views.py @@ -51,13 +51,7 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -FEATURES_WITH_CERTS_ENABLED = settings.FEATURES.copy() -FEATURES_WITH_CERTS_ENABLED['CERTIFICATES_HTML_VIEW'] = True - -FEATURES_WITH_CERTS_DISABLED = settings.FEATURES.copy() -FEATURES_WITH_CERTS_DISABLED['CERTIFICATES_HTML_VIEW'] = False - -FEATURES_WITH_CUSTOM_CERTS_ENABLED = FEATURES_WITH_CERTS_ENABLED.copy() +FEATURES_WITH_CUSTOM_CERTS_ENABLED = settings.FEATURES.copy() FEATURES_WITH_CUSTOM_CERTS_ENABLED['CUSTOM_CERTIFICATE_TEMPLATES_ENABLED'] = True name_affirmation_service = get_name_affirmation_service() @@ -289,7 +283,7 @@ def setUp(self): 'max_effort': '10' } - @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_linkedin_share_url(self): """ Test: LinkedIn share URL. @@ -314,7 +308,7 @@ def test_linkedin_share_url(self): js_escaped_string(self.linkedin_url.format(params=urlencode(params))), ) - @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + @override_settings(CERTIFICATES_HTML_VIEW=True) @with_site_configuration( configuration={ 'platform_name': 'My Platform Site', 'LINKEDIN_COMPANY_ID': 2448, @@ -348,7 +342,7 @@ def test_linkedin_share_url_site(self): "CERTIFICATE_FACEBOOK": True, "CERTIFICATE_FACEBOOK_TEXT": "test FB text" }) - @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_render_certificate_html_view_with_facebook_meta_tags(self): """ Test view html certificate if share to FB is enabled. @@ -381,7 +375,7 @@ def test_render_certificate_html_view_with_facebook_meta_tags(self): @patch.dict("django.conf.settings.SOCIAL_SHARING_SETTINGS", { "CERTIFICATE_FACEBOOK": False, }) - @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_render_certificate_html_view_without_facebook_meta_tags(self): """ Test view html certificate if share to FB is disabled. @@ -408,7 +402,7 @@ def test_render_certificate_html_view_without_facebook_meta_tags(self): self.assertNotContains(response, 'test_organization {self.course.number} Certificate |') self.assertContains(response, 'logo_test1.png') - @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + @override_settings(CERTIFICATES_HTML_VIEW=True) @patch.dict("django.conf.settings.SOCIAL_SHARING_SETTINGS", { "CERTIFICATE_TWITTER": True, "CERTIFICATE_FACEBOOK": True, @@ -597,7 +591,7 @@ def test_rendering_maximum_data(self): # Test course overrides self.assertContains(response, "/static/certificates/images/course_override_logo.png") - @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_render_html_view_valid_certificate(self): self._add_course_certificates(count=1, signatory_count=2) test_url = get_certificate_url( @@ -620,7 +614,7 @@ def test_render_html_view_valid_certificate(self): response = self.client.get(test_url) self.assertContains(response, str(self.cert.verify_uuid)) - @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_render_certificate_only_for_downloadable_status(self): """ Tests that Certificate HTML Web View returns Certificate only if certificate status is 'downloadable', @@ -649,7 +643,7 @@ def test_render_certificate_only_for_downloadable_status(self): (CertificateStatuses.audit_notpassing, False), ) @ddt.unpack - @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_audit_certificate_display(self, status, eligible_for_certificate): """ Ensure that audit-mode certs are only shown in the web view if they @@ -672,7 +666,7 @@ def test_audit_certificate_display(self, status, eligible_for_certificate): else: assert response.status_code == 404 - @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_html_view_returns_404_for_invalid_certificate(self): """ Tests that Certificate HTML Web View successfully retrieves certificate only @@ -694,7 +688,7 @@ def test_html_view_returns_404_for_invalid_certificate(self): response = self.client.get(test_url) assert response.status_code == 404 - @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_html_lang_attribute_is_dynamic_for_certificate_html_view(self): """ Tests that Certificate HTML Web View's lang attribute is based on user language. @@ -717,7 +711,7 @@ def test_html_lang_attribute_is_dynamic_for_certificate_html_view(self): self.assertContains(response, '') @ddt.data(False, True) - @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_html_view_for_non_viewable_certificate_and_for_student_user(self, date_override): """ Tests that Certificate HTML Web View returns "Cannot Find Certificate" @@ -755,7 +749,7 @@ def test_html_view_for_non_viewable_certificate_and_for_student_user(self, date_ self.assertContains(response, "Cannot Find Certificate") self.assertContains(response, "We cannot find a certificate with this URL or ID number.") - @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_render_html_view_with_valid_signatories(self): self._add_course_certificates(count=1, signatory_count=2) test_url = get_certificate_url( @@ -771,7 +765,7 @@ def test_render_html_view_with_valid_signatories(self): self.assertContains(response, 'Signatory_Organization 0') self.assertContains(response, '/static/certificates/images/demo-sig0.png') - @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_course_display_name_not_override_with_course_title(self): # if certificate in block has not course_title then course name should not be overridden with this title. test_certificates = [ @@ -798,7 +792,7 @@ def test_course_display_name_not_override_with_course_title(self): self.assertNotContains(response, 'test_course_title_0') self.assertContains(response, 'refundable course') - @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_course_display_overrides(self): """ Tests if `Course Number Display String` or `Course Organization Display` is set for a course @@ -821,7 +815,7 @@ def test_course_display_overrides(self): self.assertContains(response, 'overridden_number') self.assertContains(response, 'overridden_org') - @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_certificate_view_without_org_logo(self): test_certificates = [ { @@ -846,7 +840,7 @@ def test_certificate_view_without_org_logo(self): # make sure response html has only one organization logo container for edX self.assertContains(response, "