diff --git a/cms/djangoapps/contentstore/views/course.py b/cms/djangoapps/contentstore/views/course.py index c2fbcb4ab5d4..3c1e9881bcac 100644 --- a/cms/djangoapps/contentstore/views/course.py +++ b/cms/djangoapps/contentstore/views/course.py @@ -2146,7 +2146,7 @@ def get_allowed_organizations_for_libraries(user): # This allows org-level staff to create libraries. We should re-evaluate # whether this is necessary and try to normalize course and library creation # authorization behavior. - if settings.FEATURES.get('ENABLE_ORGANIZATION_STAFF_ACCESS_FOR_CONTENT_LIBRARIES', False): + if settings.ENABLE_ORGANIZATION_STAFF_ACCESS_FOR_CONTENT_LIBRARIES: organizations_set.update(get_organizations_for_non_course_creators(user)) # This allows people in the course creator group for an org to create diff --git a/common/djangoapps/student/models/user.py b/common/djangoapps/student/models/user.py index e769e11f3890..0749a970835c 100644 --- a/common/djangoapps/student/models/user.py +++ b/common/djangoapps/student/models/user.py @@ -1345,7 +1345,7 @@ def enforce_single_login(sender, request, user, signal, **kwargs): # pylint: di Sets the current session id in the user profile, to prevent concurrent logins. """ - if settings.FEATURES.get('PREVENT_CONCURRENT_LOGINS', False): + if settings.PREVENT_CONCURRENT_LOGINS: if signal == user_logged_in: key = request.session.session_key else: diff --git a/common/djangoapps/student/tests/test_models.py b/common/djangoapps/student/tests/test_models.py index 69e6d3916e3d..d57f4abfd5ac 100644 --- a/common/djangoapps/student/tests/test_models.py +++ b/common/djangoapps/student/tests/test_models.py @@ -7,7 +7,6 @@ import ddt from crum import set_current_request -from django.conf import settings from django.contrib.auth.models import AnonymousUser, User # pylint: disable=imported-auth-user from django.core.cache import cache from django.db import connection @@ -912,9 +911,7 @@ def register_and_enroll_student(): course_overview.save() if feature_enabled: - with override_settings( - FEATURES={**settings.FEATURES, 'DISABLE_ALLOWED_ENROLLMENT_IF_ENROLLMENT_CLOSED': True} - ): + with override_settings(DISABLE_ALLOWED_ENROLLMENT_IF_ENROLLMENT_CLOSED=True): assert register_and_enroll_student() is None else: assert register_and_enroll_student() is not None diff --git a/common/djangoapps/student/tests/test_views.py b/common/djangoapps/student/tests/test_views.py index ac724d6f847b..de97b2fc0220 100644 --- a/common/djangoapps/student/tests/test_views.py +++ b/common/djangoapps/student/tests/test_views.py @@ -1014,7 +1014,7 @@ def test_happy_path_upgrade_message( @skip_unless_lms -@unittest.skipUnless(settings.FEATURES.get("ENABLE_NOTICES"), 'Notices plugin is not enabled') +@unittest.skipUnless(getattr(settings, "ENABLE_NOTICES", False), 'Notices plugin is not enabled') class TestCourseDashboardNoticesRedirects(SharedModuleStoreTestCase): """ Tests for the Dashboard redirect functionality introduced via the Notices plugin. @@ -1089,7 +1089,7 @@ def test_user_with_unacknowledged_notice(self, mock_notices): """ mock_notices.return_value = reverse("about") - with override_settings(FEATURES={**settings.FEATURES, 'ENABLE_NOTICES': True}): + with override_settings(ENABLE_NOTICES=True): response = self.client.get(self.path) assert response.status_code == 302 @@ -1104,7 +1104,7 @@ def test_user_with_unacknowledged_notice_no_notices(self, mock_notices): """ mock_notices.return_value = None - with override_settings(FEATURES={**settings.FEATURES, 'ENABLE_NOTICES': True}): + with override_settings(ENABLE_NOTICES=True): response = self.client.get(self.path) assert response.status_code == 200 @@ -1117,7 +1117,7 @@ def test_user_with_unacknowledged_notice_plugin_disabled(self, mock_notices): """ mock_notices.return_value = None - with override_settings(FEATURES={**settings.FEATURES, 'ENABLE_NOTICES': False}): + with override_settings(ENABLE_NOTICES=False): response = self.client.get(self.path) assert response.status_code == 200 diff --git a/common/djangoapps/student/views/dashboard.py b/common/djangoapps/student/views/dashboard.py index d3e1311fe720..6c499c98c8f4 100644 --- a/common/djangoapps/student/views/dashboard.py +++ b/common/djangoapps/student/views/dashboard.py @@ -545,7 +545,7 @@ def student_dashboard(request): # pylint: disable=too-many-statements ) or settings.SUPPORT_SITE_LINK hide_dashboard_courses_until_activated = configuration_helpers.get_value( 'HIDE_DASHBOARD_COURSES_UNTIL_ACTIVATED', - settings.FEATURES.get('HIDE_DASHBOARD_COURSES_UNTIL_ACTIVATED', False) + getattr(settings, 'HIDE_DASHBOARD_COURSES_UNTIL_ACTIVATED', False) ) empty_dashboard_message = configuration_helpers.get_value( 'EMPTY_DASHBOARD_MESSAGE', None diff --git a/common/djangoapps/student/views/management.py b/common/djangoapps/student/views/management.py index 77483dd99c4e..b73f8b3150ef 100644 --- a/common/djangoapps/student/views/management.py +++ b/common/djangoapps/student/views/management.py @@ -247,7 +247,7 @@ def compose_activation_email( }) if route_enabled: - dest_addr = settings.FEATURES['REROUTE_ACTIVATION_EMAIL'] + dest_addr = getattr(settings, 'REROUTE_ACTIVATION_EMAIL', False) else: dest_addr = user.email @@ -293,7 +293,7 @@ def compose_and_send_activation_email( redirect_url: The URL to redirect to after successful activation registration_flow: Is the request coming from registration workflow """ - route_enabled = settings.FEATURES.get('REROUTE_ACTIVATION_EMAIL') + route_enabled = getattr(settings, 'REROUTE_ACTIVATION_EMAIL', False) msg = compose_activation_email( user, user_registration, route_enabled, profile.name, redirect_url, registration_flow diff --git a/lms/djangoapps/courseware/access.py b/lms/djangoapps/courseware/access.py index 2d7e22001b65..ae5654b7deef 100644 --- a/lms/djangoapps/courseware/access.py +++ b/lms/djangoapps/courseware/access.py @@ -297,7 +297,7 @@ def _can_enroll_courselike(user, courselike): # DISABLE_ALLOWED_ENROLLMENT_IF_ENROLLMENT_CLOSED flag is used to disable enrollment for user invited # to a course if user is registering when the course enrollment is closed if ( - settings.FEATURES.get('DISABLE_ALLOWED_ENROLLMENT_IF_ENROLLMENT_CLOSED') and + settings.DISABLE_ALLOWED_ENROLLMENT_IF_ENROLLMENT_CLOSED and not course_enrollment_open and not user_has_staff_access ): diff --git a/lms/djangoapps/courseware/block_render.py b/lms/djangoapps/courseware/block_render.py index eb62390c4ca6..8ef637b82bf0 100644 --- a/lms/djangoapps/courseware/block_render.py +++ b/lms/djangoapps/courseware/block_render.py @@ -1005,9 +1005,9 @@ def xblock_view(request, course_id, usage_id, view_name): resources: A list of tuples where the first element is the resource hash, and the second is the resource description """ - if not settings.FEATURES.get('ENABLE_XBLOCK_VIEW_ENDPOINT', False): + if not settings.ENABLE_XBLOCK_VIEW_ENDPOINT: log.warning("Attempt to use deactivated XBlock view endpoint -" - " see FEATURES['ENABLE_XBLOCK_VIEW_ENDPOINT']") + " see ENABLE_XBLOCK_VIEW_ENDPOINT") raise Http404 try: diff --git a/lms/djangoapps/courseware/tests/test_access.py b/lms/djangoapps/courseware/tests/test_access.py index bd75d4723933..e81178ece909 100644 --- a/lms/djangoapps/courseware/tests/test_access.py +++ b/lms/djangoapps/courseware/tests/test_access.py @@ -11,7 +11,6 @@ import pytest import pytz from ccx_keys.locator import CCXLocator -from django.conf import settings from django.contrib.auth.models import User # pylint: disable=imported-auth-user from django.test import TestCase from django.test.client import RequestFactory @@ -551,7 +550,7 @@ def test__has_access_course_can_enroll(self): course.save() assert not access._has_access_course(user, 'enroll', course) - @override_settings(FEATURES={**settings.FEATURES, 'DISABLE_ALLOWED_ENROLLMENT_IF_ENROLLMENT_CLOSED': True}) + @override_settings(DISABLE_ALLOWED_ENROLLMENT_IF_ENROLLMENT_CLOSED=True) def test__has_access_course_with_disable_allowed_enrollment_flag(self): yesterday = datetime.datetime.now(pytz.utc) - datetime.timedelta(days=1) tomorrow = datetime.datetime.now(pytz.utc) + datetime.timedelta(days=1) diff --git a/lms/djangoapps/courseware/tests/test_block_render.py b/lms/djangoapps/courseware/tests/test_block_render.py index 25d56ef60de7..2e38c0b4ebff 100644 --- a/lms/djangoapps/courseware/tests/test_block_render.py +++ b/lms/djangoapps/courseware/tests/test_block_render.py @@ -993,7 +993,7 @@ def test_will_recheck_access_handler_attribute(self, handler, will_recheck_acces @ddt.ddt -@patch.dict('django.conf.settings.FEATURES', {'ENABLE_XBLOCK_VIEW_ENDPOINT': True}) +@override_settings(ENABLE_XBLOCK_VIEW_ENDPOINT=True) class TestXBlockView(SharedModuleStoreTestCase, LoginEnrollmentTestCase): """ Test the handle_xblock_callback function diff --git a/lms/djangoapps/instructor/views/instructor_dashboard.py b/lms/djangoapps/instructor/views/instructor_dashboard.py index 82de958b49a8..bbc39c8fbbb9 100644 --- a/lms/djangoapps/instructor/views/instructor_dashboard.py +++ b/lms/djangoapps/instructor/views/instructor_dashboard.py @@ -824,7 +824,7 @@ def _section_open_response_assessment(request, course, openassessment_blocks, ac section_data = { 'fragment': block.render('ora_blocks_listing_view', context={ 'ora_items': ora_items, - 'ora_item_view_enabled': settings.FEATURES.get('ENABLE_XBLOCK_VIEW_ENDPOINT', False) + 'ora_item_view_enabled': settings.ENABLE_XBLOCK_VIEW_ENDPOINT }), 'section_key': 'open_response_assessment', 'section_display_name': _('Open Responses'), diff --git a/lms/urls.py b/lms/urls.py index f8885ca94fa5..893682157f0d 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -862,7 +862,7 @@ ), ] -if settings.FEATURES.get('ENABLE_DEBUG_RUN_PYTHON'): +if settings.ENABLE_DEBUG_RUN_PYTHON: urlpatterns += [ path('debug/run_python', debug_views.run_python), ] diff --git a/openedx/core/djangoapps/user_authn/views/auto_auth.py b/openedx/core/djangoapps/user_authn/views/auto_auth.py index b8c7de9df2d8..703a0c6a3c62 100644 --- a/openedx/core/djangoapps/user_authn/views/auto_auth.py +++ b/openedx/core/djangoapps/user_authn/views/auto_auth.py @@ -90,7 +90,7 @@ def auto_auth(request): # pylint: disable=too-many-statements redirect_when_done = _str2bool(request.GET.get('redirect', '')) or redirect_to login_when_done = 'no_login' not in request.GET - restricted = settings.FEATURES.get('RESTRICT_AUTOMATIC_AUTH', True) + restricted = settings.RESTRICT_AUTOMATIC_AUTH if is_superuser and restricted: return HttpResponseForbidden(_('Superuser creation not allowed')) diff --git a/openedx/core/djangoapps/user_authn/views/register.py b/openedx/core/djangoapps/user_authn/views/register.py index f03d660ddc09..17da7fbdba0c 100644 --- a/openedx/core/djangoapps/user_authn/views/register.py +++ b/openedx/core/djangoapps/user_authn/views/register.py @@ -475,7 +475,7 @@ def _skip_activation_email(user, running_pipeline, third_party_provider): ) return ( - settings.FEATURES.get('SKIP_EMAIL_VALIDATION', None) or + getattr(settings, 'SKIP_EMAIL_VALIDATION', False) or settings.FEATURES.get('AUTOMATIC_AUTH_FOR_TESTING') or (third_party_provider and third_party_provider.skip_email_verification and valid_email) ) diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_auto_auth.py b/openedx/core/djangoapps/user_authn/views/tests/test_auto_auth.py index ff393d1ca01b..d3349e011de5 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_auto_auth.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_auto_auth.py @@ -7,7 +7,7 @@ import ddt from django.conf import settings from django.contrib.auth.models import User # pylint: disable=imported-auth-user -from django.test import TestCase +from django.test import TestCase, override_settings from django.test.client import Client from opaque_keys.edx.locator import CourseLocator @@ -67,7 +67,7 @@ def test_create_user(self): assert user.is_active assert not user.profile.requires_parental_consent() - @patch.dict("django.conf.settings.FEATURES", {'RESTRICT_AUTOMATIC_AUTH': False}) + @override_settings(RESTRICT_AUTOMATIC_AUTH=False) def test_create_same_user(self): self._auto_auth({'username': 'test'}) self._auto_auth({'username': 'test'}) @@ -105,7 +105,7 @@ def test_create_defined_user(self): # By default, the user should not be global staff assert not user.is_staff - @patch.dict("django.conf.settings.FEATURES", {'RESTRICT_AUTOMATIC_AUTH': False}) + @override_settings(RESTRICT_AUTOMATIC_AUTH=False) def test_create_staff_user(self): # Create a staff user @@ -132,7 +132,7 @@ def test_course_enrollment(self, course_id, course_key): @ddt.data(*COURSE_IDS_DDT) @ddt.unpack - @patch.dict("django.conf.settings.FEATURES", {'RESTRICT_AUTOMATIC_AUTH': False}) + @override_settings(RESTRICT_AUTOMATIC_AUTH=False) def test_double_enrollment(self, course_id, course_key): # Create a user and enroll in a course @@ -337,7 +337,7 @@ def setUp(self): self.url = '/auto_auth' self.client = Client() - @patch.dict("django.conf.settings.FEATURES", {'RESTRICT_AUTOMATIC_AUTH': True}) + @override_settings(RESTRICT_AUTOMATIC_AUTH=True) def test_superuser(self): """ Make sure that superusers cannot be created. @@ -345,7 +345,7 @@ def test_superuser(self): response = self.client.get(self.url, {'username': 'test', 'superuser': 'true'}) assert response.status_code == 403 - @patch.dict("django.conf.settings.FEATURES", {'RESTRICT_AUTOMATIC_AUTH': True}) + @override_settings(RESTRICT_AUTOMATIC_AUTH=True) def test_modify_user(self): """ Make sure that existing users cannot be modified. diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_login.py b/openedx/core/djangoapps/user_authn/views/tests/test_login.py index 98db117aca20..2707bbec3966 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_login.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_login.py @@ -629,7 +629,7 @@ def test_login_refresh_anonymous_user(self): assert response.status_code == 401 assert jwt_cookies.jwt_cookie_header_payload_name() not in self.client.cookies - @patch.dict("django.conf.settings.FEATURES", {'PREVENT_CONCURRENT_LOGINS': True}) + @override_settings(PREVENT_CONCURRENT_LOGINS=True) def test_single_session(self): creds = {'email': self.user_email, 'password': self.password} client1 = Client() @@ -658,7 +658,7 @@ def test_single_session(self): # client1 will be logged out assert response.status_code == 302 - @patch.dict("django.conf.settings.FEATURES", {'PREVENT_CONCURRENT_LOGINS': True}) + @override_settings(PREVENT_CONCURRENT_LOGINS=True) def test_single_session_with_no_user_profile(self): """ Assert that user login with cas (Central Authentication Service) is @@ -700,7 +700,7 @@ def test_single_session_with_no_user_profile(self): # client1 will be logged out assert response.status_code == 302 - @patch.dict("django.conf.settings.FEATURES", {'PREVENT_CONCURRENT_LOGINS': True}) + @override_settings(PREVENT_CONCURRENT_LOGINS=True) def test_single_session_with_url_not_having_login_required_decorator(self): # accessing logout url as it does not have login-required decorator it will avoid redirect # and go inside the enforce_single_login