diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 58cd39a80868..79a59d2a0f19 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -20,6 +20,7 @@ jobs: name: ${{ matrix.shard_name }}(py=${{ matrix.python-version }},dj=${{ matrix.django-version }},mongo=${{ matrix.mongo-version }}) runs-on: ${{ matrix.os-version }} strategy: + fail-fast: false matrix: python-version: - "3.11" diff --git a/cms/djangoapps/cms_user_tasks/tests.py b/cms/djangoapps/cms_user_tasks/tests.py index 8a9bc5532101..a9fc437bf084 100644 --- a/cms/djangoapps/cms_user_tasks/tests.py +++ b/cms/djangoapps/cms_user_tasks/tests.py @@ -254,7 +254,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 +277,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')) + self.assertFalse(settings.ENABLE_COURSE_OLX_VALIDATION) self.assertEqual(len(mail.outbox), 1) 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/course_creators/admin.py b/cms/djangoapps/course_creators/admin.py index a1d34b3897fc..e6f0cb540265 100644 --- a/cms/djangoapps/course_creators/admin.py +++ b/cms/djangoapps/course_creators/admin.py @@ -142,7 +142,7 @@ def send_user_notification_callback(sender, **kwargs): # pylint: disable=unused user = kwargs['user'] updated_state = kwargs['state'] - studio_request_email = settings.FEATURES.get('STUDIO_REQUEST_EMAIL', '') + studio_request_email = settings.STUDIO_REQUEST_EMAIL context = {'studio_request_email': studio_request_email} subject = render_to_string('emails/course_creator_subject.txt', context) @@ -169,7 +169,7 @@ def send_admin_notification_callback(sender, **kwargs): # pylint: disable=unuse """ user = kwargs['user'] - studio_request_email = settings.FEATURES.get('STUDIO_REQUEST_EMAIL', '') + studio_request_email = settings.STUDIO_REQUEST_EMAIL context = {'user_name': user.username, 'user_email': user.email} subject = render_to_string('emails/course_creator_admin_subject.txt', context) diff --git a/cms/djangoapps/course_creators/tests/test_admin.py b/cms/djangoapps/course_creators/tests/test_admin.py index c747b92075ce..f639744a3903 100644 --- a/cms/djangoapps/course_creators/tests/test_admin.py +++ b/cms/djangoapps/course_creators/tests/test_admin.py @@ -8,7 +8,7 @@ from django.contrib.admin.sites import AdminSite from django.core import mail from django.http import HttpRequest -from django.test import TestCase +from django.test import TestCase, override_settings from cms.djangoapps.course_creators.admin import CourseCreatorAdmin from cms.djangoapps.course_creators.models import CourseCreator @@ -51,10 +51,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 - } @mock.patch( 'cms.djangoapps.course_creators.admin.render_to_string', @@ -84,7 +80,7 @@ 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): + with override_settings(ENABLE_CREATOR_GROUP=True, STUDIO_REQUEST_EMAIL=self.studio_request_email): # User is initially unrequested. self.assertFalse(auth.user_has_role(self.user, CourseCreatorRole())) @@ -138,7 +134,7 @@ def check_admin_message_state(state, expect_sent_to_admin, expect_sent_to_user): else: self.assertEqual(base_num_emails, len(mail.outbox)) - with mock.patch.dict('django.conf.settings.FEATURES', self.enable_creator_group_patch): + with override_settings(ENABLE_CREATOR_GROUP=True, STUDIO_REQUEST_EMAIL=self.studio_request_email): # 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. diff --git a/cms/djangoapps/course_creators/tests/test_views.py b/cms/djangoapps/course_creators/tests/test_views.py index 5ea37b37fcbf..9fde55e8f5fc 100644 --- a/cms/djangoapps/course_creators/tests/test_views.py +++ b/cms/djangoapps/course_creators/tests/test_views.py @@ -6,7 +6,7 @@ from unittest import mock from django.core.exceptions import PermissionDenied -from django.test import TestCase +from django.test import TestCase, override_settings from django.urls import reverse from cms.djangoapps.course_creators.views import ( @@ -65,7 +65,7 @@ def test_add_unrequested(self): self.assertEqual('unrequested', get_course_creator_status(self.user)) def test_add_granted(self): - with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}): + with override_settings(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())) @@ -79,7 +79,7 @@ def test_add_granted(self): self.assertTrue(auth.user_has_role(self.user, CourseCreatorRole())) def test_update_creator_group(self): - with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}): + with override_settings(ENABLE_CREATOR_GROUP=True): self.assertFalse(auth.user_has_role(self.user, CourseCreatorRole())) update_course_creator_group(self.admin, self.user, True) self.assertTrue(auth.user_has_role(self.user, CourseCreatorRole())) @@ -87,7 +87,7 @@ def test_update_creator_group(self): self.assertFalse(auth.user_has_role(self.user, CourseCreatorRole())) def test_update_org_content_creator_role(self): - with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}): + with override_settings(ENABLE_CREATOR_GROUP=True): self.assertFalse(auth.user_has_role(self.user, OrgContentCreatorRole(self.org))) update_org_content_creator_role(self.admin, self.user, [self.org]) self.assertTrue(auth.user_has_role(self.user, OrgContentCreatorRole(self.org))) diff --git a/cms/djangoapps/models/settings/course_metadata.py b/cms/djangoapps/models/settings/course_metadata.py index c66f5b65e4c9..6c5d7ff3f641 100644 --- a/cms/djangoapps/models/settings/course_metadata.py +++ b/cms/djangoapps/models/settings/course_metadata.py @@ -103,19 +103,19 @@ def get_exclude_list_of_fields(cls, course_key): exclude_list.append('giturl') # Do not show edxnotes if the feature is disabled. - if not settings.FEATURES.get('ENABLE_EDXNOTES'): + if not settings.ENABLE_EDXNOTES: exclude_list.append('edxnotes') # Do not show video auto advance if the feature is disabled - if not settings.FEATURES.get('ENABLE_OTHER_COURSE_SETTINGS'): + if not settings.ENABLE_OTHER_COURSE_SETTINGS: exclude_list.append('other_course_settings') # Do not show video_upload_pipeline if the feature is disabled. - if not settings.FEATURES.get('ENABLE_VIDEO_UPLOAD_PIPELINE'): + if not settings.ENABLE_VIDEO_UPLOAD_PIPELINE: exclude_list.append('video_upload_pipeline') # Do not show video auto advance if the feature is disabled - if not settings.FEATURES.get('ENABLE_AUTOADVANCE_VIDEOS'): + if not settings.ENABLE_AUTOADVANCE_VIDEOS: exclude_list.append('video_auto_advance') # Do not show social sharing url field if the feature is disabled. @@ -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 settings.ENABLE_TEAMS: exclude_list.append('teams_configuration') - if not settings.FEATURES.get('ENABLE_VIDEO_BUMPER'): + if not settings.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 settings.CUSTOM_COURSES_EDX: exclude_list.append('enable_ccx') exclude_list.append('ccx_connector') diff --git a/cms/lib/xblock/test/test_authoring_mixin.py b/cms/lib/xblock/test/test_authoring_mixin.py index eee86df8bf4f..368c6de2905e 100644 --- a/cms/lib/xblock/test/test_authoring_mixin.py +++ b/cms/lib/xblock/test/test_authoring_mixin.py @@ -32,9 +32,6 @@ class AuthoringMixinTestCase(ModuleStoreTestCase): ENROLLMENT_GROUPS_TITLE = "Enrollment Track Groups" STAFF_LOCKED = 'The unit that contains this component is hidden from learners' - FEATURES_WITH_ENROLLMENT_TRACK_DISABLED = settings.FEATURES.copy() - FEATURES_WITH_ENROLLMENT_TRACK_DISABLED['ENABLE_ENROLLMENT_TRACK_USER_PARTITION'] = False - @XBlock.register_temp_plugin(PureXBlock, 'pure') def setUp(self): """ @@ -170,7 +167,7 @@ def test_html_false_content_group(self): [self.STAFF_LOCKED] ) - @override_settings(FEATURES=FEATURES_WITH_ENROLLMENT_TRACK_DISABLED) + @override_settings(ENABLE_ENROLLMENT_TRACK_USER_PARTITION=False) def test_enrollment_tracks_disabled(self): """ Test that the "no groups" messages doesn't reference enrollment tracks if diff --git a/cms/urls.py b/cms/urls.py index 048339bc9fe9..3e0a1a015635 100644 --- a/cms/urls.py +++ b/cms/urls.py @@ -245,12 +245,12 @@ name='export_git') ] -if settings.FEATURES.get('ENABLE_SERVICE_STATUS'): +if settings.ENABLE_SERVICE_STATUS: urlpatterns.append(path('status/', include('openedx.core.djangoapps.service_status.urls'))) # The password pages in the admin tool are disabled so that all password # changes go through our user portal and follow complexity requirements. -if not settings.FEATURES.get('ENABLE_CHANGE_USER_PASSWORD_ADMIN'): +if not settings.ENABLE_CHANGE_USER_PASSWORD_ADMIN: urlpatterns.append(re_path(r'^admin/auth/user/\d+/password/$', handler404)) urlpatterns.append(path('admin/password_change/', handler404)) urlpatterns.append( @@ -264,7 +264,7 @@ contentstore_views.entrance_exam)) # Enable Web/HTML Certificates -if settings.FEATURES.get('CERTIFICATES_HTML_VIEW'): +if settings.CERTIFICATES_HTML_VIEW: from cms.djangoapps.contentstore.views.certificates import ( CertificateActivationAPIView, CertificateDetailAPIView, diff --git a/common/djangoapps/course_modes/models.py b/common/djangoapps/course_modes/models.py index a739a9076fac..00f1f4faaae8 100644 --- a/common/djangoapps/course_modes/models.py +++ b/common/djangoapps/course_modes/models.py @@ -826,7 +826,7 @@ def is_eligible_for_certificate(cls, mode_slug, status=None): """ ineligible_modes = [cls.AUDIT] - if settings.FEATURES.get('DISABLE_HONOR_CERTIFICATES', False): + if settings.DISABLE_HONOR_CERTIFICATES: # Adding check so that we can regenerate the certificate for learners who have # already earned the certificate using honor mode from lms.djangoapps.certificates.data import CertificateStatuses diff --git a/common/djangoapps/course_modes/tests/test_models.py b/common/djangoapps/course_modes/tests/test_models.py index 35ea05f69203..446106d20b6e 100644 --- a/common/djangoapps/course_modes/tests/test_models.py +++ b/common/djangoapps/course_modes/tests/test_models.py @@ -442,7 +442,7 @@ def test_expiration_datetime_explicitly_set_to_none(self): @ddt.unpack def test_eligible_for_cert(self, disable_honor_cert, mode_slug, expected_eligibility): """Verify that non-audit modes are eligible for a cert.""" - with override_settings(FEATURES={'DISABLE_HONOR_CERTIFICATES': disable_honor_cert}): + with override_settings(DISABLE_HONOR_CERTIFICATES=disable_honor_cert): assert CourseMode.is_eligible_for_certificate(mode_slug) == expected_eligibility @ddt.data( diff --git a/common/djangoapps/course_modes/tests/test_views.py b/common/djangoapps/course_modes/tests/test_views.py index 65b4980eba01..99b337537133 100644 --- a/common/djangoapps/course_modes/tests/test_views.py +++ b/common/djangoapps/course_modes/tests/test_views.py @@ -47,7 +47,7 @@ class CourseModeViewTest(CatalogIntegrationMixin, UrlResetMixin, ModuleStoreTest """ URLCONF_MODULES = ['common.djangoapps.course_modes.urls'] - @patch.dict(settings.FEATURES, {'MODE_CREATION_FOR_TESTING': True}) + @override_settings(MODE_CREATION_FOR_TESTING=True) def setUp(self): super().setUp() now = datetime.now(ZoneInfo("UTC")) @@ -640,7 +640,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() @@ -656,7 +656,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/course_modes/urls.py b/common/djangoapps/course_modes/urls.py index 8c3e562688d8..51f6fae7d805 100644 --- a/common/djangoapps/course_modes/urls.py +++ b/common/djangoapps/course_modes/urls.py @@ -11,7 +11,7 @@ ] # Enable verified mode creation -if settings.FEATURES.get('MODE_CREATION_FOR_TESTING'): +if settings.MODE_CREATION_FOR_TESTING: urlpatterns.append( re_path(fr'^create_mode/{settings.COURSE_ID_PATTERN}/$', views.create_mode, diff --git a/common/djangoapps/course_modes/views.py b/common/djangoapps/course_modes/views.py index 09164dc40e7c..2307ab13452f 100644 --- a/common/djangoapps/course_modes/views.py +++ b/common/djangoapps/course_modes/views.py @@ -381,7 +381,7 @@ def _redirect_to_course_or_dashboard(self, course, course_key, user): def create_mode(request, course_id): """Add a mode to the course corresponding to the given course ID. - Only available when settings.FEATURES['MODE_CREATION_FOR_TESTING'] is True. + Only available when settings.MODE_CREATION_FOR_TESTING is True. Attempts to use the following querystring parameters from the request: `mode_slug` (str): The mode to add, either 'honor', 'verified', or 'professional' diff --git a/common/djangoapps/edxmako/shortcuts.py b/common/djangoapps/edxmako/shortcuts.py index a8b0e7a0d9f5..43f3413777c2 100644 --- a/common/djangoapps/edxmako/shortcuts.py +++ b/common/djangoapps/edxmako/shortcuts.py @@ -45,7 +45,7 @@ def marketing_link(name): link_map = settings.MKTG_URL_LINK_MAP enable_mktg_site = configuration_helpers.get_value( 'ENABLE_MKTG_SITE', - settings.FEATURES.get('ENABLE_MKTG_SITE', False) + settings.ENABLE_MKTG_SITE ) marketing_urls = configuration_helpers.get_value( 'MKTG_URLS', @@ -115,7 +115,7 @@ def is_marketing_link_set(name): enable_mktg_site = configuration_helpers.get_value( 'ENABLE_MKTG_SITE', - settings.FEATURES.get('ENABLE_MKTG_SITE', False) + settings.ENABLE_MKTG_SITE ) marketing_urls = configuration_helpers.get_value( 'MKTG_URLS', diff --git a/common/djangoapps/edxmako/tests.py b/common/djangoapps/edxmako/tests.py index 51c2ab4efdd1..9df4328322b0 100644 --- a/common/djangoapps/edxmako/tests.py +++ b/common/djangoapps/edxmako/tests.py @@ -35,12 +35,12 @@ class ShortcutsTests(UrlResetMixin, TestCase): def test_marketing_link(self): with override_settings(MKTG_URL_LINK_MAP={'ABOUT': self._get_test_url_name()}): # test marketing site on - with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}): + with override_settings(ENABLE_MKTG_SITE=True): expected_link = 'https://dummy-root/about-us' link = marketing_link('ABOUT') assert link == expected_link # test marketing site off - with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': False}): + with override_settings(ENABLE_MKTG_SITE=False): expected_link = reverse(self._get_test_url_name()) link = marketing_link('ABOUT') assert link == expected_link @@ -49,11 +49,11 @@ def test_marketing_link(self): def test_is_marketing_link_set(self): with override_settings(MKTG_URL_LINK_MAP={'ABOUT': self._get_test_url_name()}): # test marketing site on - with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}): + with override_settings(ENABLE_MKTG_SITE=True): assert is_marketing_link_set('ABOUT') assert not is_marketing_link_set('NOT_CONFIGURED') # test marketing site off - with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': False}): + with override_settings(ENABLE_MKTG_SITE=False): assert is_marketing_link_set('ABOUT') assert not is_marketing_link_set('NOT_CONFIGURED') @@ -61,12 +61,12 @@ def test_is_marketing_link_set(self): def test_is_any_marketing_link_set(self): with override_settings(MKTG_URL_LINK_MAP={'ABOUT': self._get_test_url_name()}): # test marketing site on - with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}): + with override_settings(ENABLE_MKTG_SITE=True): assert is_any_marketing_link_set(['ABOUT']) assert is_any_marketing_link_set(['ABOUT', 'NOT_CONFIGURED']) assert not is_any_marketing_link_set(['NOT_CONFIGURED']) # test marketing site off - with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': False}): + with override_settings(ENABLE_MKTG_SITE=False): assert is_any_marketing_link_set(['ABOUT']) assert is_any_marketing_link_set(['ABOUT', 'NOT_CONFIGURED']) assert not is_any_marketing_link_set(['NOT_CONFIGURED']) @@ -84,11 +84,11 @@ def _get_test_url_name(self): # lint-amnesty, pylint: disable=missing-function- def test_override_marketing_link_valid(self): expected_link = 'https://edx.org' # test marketing site on - with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}): + with override_settings(ENABLE_MKTG_SITE=True): link = marketing_link('TOS') assert link == expected_link # test marketing site off - with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': False}): + with override_settings(ENABLE_MKTG_SITE=False): link = marketing_link('TOS') assert link == expected_link @@ -97,11 +97,11 @@ def test_override_marketing_link_valid(self): def test_override_marketing_link_invalid(self): expected_link = '#' # test marketing site on - with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}): + with override_settings(ENABLE_MKTG_SITE=True): link = marketing_link('TOS') assert link == expected_link # test marketing site off - with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': False}): + with override_settings(ENABLE_MKTG_SITE=False): link = marketing_link('TOS') assert link == expected_link @@ -112,7 +112,7 @@ def test_link_map_url_reverse(self): 'BAD_URL': 'foobarbaz', } - with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': False}): + with override_settings(ENABLE_MKTG_SITE=False): with override_settings(MKTG_URL_LINK_MAP=url_link_map): link = marketing_link('ABOUT') assert link == '/dashboard' diff --git a/common/djangoapps/third_party_auth/__init__.py b/common/djangoapps/third_party_auth/__init__.py index 027c4648c460..8ae3323429a7 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") + settings.ENABLE_THIRD_PARTY_AUTH ) diff --git a/common/djangoapps/third_party_auth/apps.py b/common/djangoapps/third_party_auth/apps.py index 7f6b82cfde1f..5f47080990ea 100644 --- a/common/djangoapps/third_party_auth/apps.py +++ b/common/djangoapps/third_party_auth/apps.py @@ -13,7 +13,7 @@ def ready(self): from .signals import handlers # noqa: F401 pylint: disable=unused-import # To override the settings before loading social_django. - if settings.FEATURES.get('ENABLE_THIRD_PARTY_AUTH', False): + if settings.ENABLE_THIRD_PARTY_AUTH: self._enable_third_party_auth() def _enable_third_party_auth(self): diff --git a/common/djangoapps/third_party_auth/decorators.py b/common/djangoapps/third_party_auth/decorators.py index 66540212e10e..8b29680be10c 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 settings.ENABLE_THIRD_PARTY_AUTH: referer = request.META.get('HTTP_REFERER') if referer is not None: parsed_url = urlparse(referer) diff --git a/common/djangoapps/third_party_auth/management/commands/remove_social_auth_users.py b/common/djangoapps/third_party_auth/management/commands/remove_social_auth_users.py index 798816d4c190..acd6848aa9a6 100644 --- a/common/djangoapps/third_party_auth/management/commands/remove_social_auth_users.py +++ b/common/djangoapps/third_party_auth/management/commands/remove_social_auth_users.py @@ -38,7 +38,7 @@ def add_arguments(self, parser): def handle(self, *args, **options): slug = options['IDP'] - if not settings.FEATURES.get('ENABLE_ENROLLMENT_RESET'): + if not settings.ENABLE_ENROLLMENT_RESET: raise CommandError('ENABLE_ENROLLMENT_RESET feature not enabled on this enviroment') try: diff --git a/common/djangoapps/third_party_auth/management/commands/tests/test_remove_social_auth_users.py b/common/djangoapps/third_party_auth/management/commands/tests/test_remove_social_auth_users.py index 8da9ed626573..396314a201ed 100644 --- a/common/djangoapps/third_party_auth/management/commands/tests/test_remove_social_auth_users.py +++ b/common/djangoapps/third_party_auth/management/commands/tests/test_remove_social_auth_users.py @@ -20,10 +20,6 @@ from common.djangoapps.third_party_auth.tests.factories import SAMLProviderConfigFactory from openedx.core.djangolib.testing.utils import skip_unless_lms -FEATURES_WITH_ENABLED = settings.FEATURES.copy() -FEATURES_WITH_ENABLED['ENABLE_ENROLLMENT_RESET'] = True - - @skip_unless_lms class TestRemoveSocialAuthUsersCommand(TestCase): """ @@ -64,7 +60,7 @@ def create_social_auth_entry(self, user, provider): def find_user_social_auth_entry(self, username): UserSocialAuth.objects.get(user__username=username) - @override_settings(FEATURES=FEATURES_WITH_ENABLED) + @override_settings(ENABLE_ENROLLMENT_RESET=True) def test_remove_users(self): call_command(self.command, self.provider_hogwarts.slug, force=True) @@ -83,14 +79,14 @@ def test_remove_users(self): # other social auth intact self.find_user_social_auth_entry(self.user_viktor.username) - @override_settings(FEATURES=FEATURES_WITH_ENABLED) + @override_settings(ENABLE_ENROLLMENT_RESET=True) def test_invalid_idp(self): invalid_slug = 'jedi-academy' err_string = f'No SAML provider found for slug {invalid_slug}' with self.assertRaisesRegex(CommandError, err_string): call_command(self.command, invalid_slug) - @override_settings(FEATURES=FEATURES_WITH_ENABLED) + @override_settings(ENABLE_ENROLLMENT_RESET=True) def test_confirmation_required(self): """ By default this command will require user input to confirm """ with self._replace_stdin('confirm'): @@ -101,7 +97,7 @@ def test_confirmation_required(self): with pytest.raises(UserSocialAuth.DoesNotExist): self.find_user_social_auth_entry('harry') - @override_settings(FEATURES=FEATURES_WITH_ENABLED) + @override_settings(ENABLE_ENROLLMENT_RESET=True) def test_confirmation_failure(self): err_string = 'User confirmation required. No records have been modified' with self.assertRaisesRegex(CommandError, err_string): diff --git a/common/djangoapps/third_party_auth/models.py b/common/djangoapps/third_party_auth/models.py index d3beafb4db88..0c7b8f55a575 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 settings.ENABLE_UNICODE_USERNAME: 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/settings.py b/common/djangoapps/third_party_auth/settings.py index 0aeb94fbd498..48a35a7da932 100644 --- a/common/djangoapps/third_party_auth/settings.py +++ b/common/djangoapps/third_party_auth/settings.py @@ -43,7 +43,7 @@ def apply_settings(django_settings): django_settings.SOCIAL_AUTH_AZUREAD_OAUTH2_AUTH_EXTRA_ARGUMENTS = {'msafed': 0} # Avoid default username check to allow non-ascii characters - django_settings.SOCIAL_AUTH_CLEAN_USERNAMES = not settings.FEATURES.get("ENABLE_UNICODE_USERNAME") + django_settings.SOCIAL_AUTH_CLEAN_USERNAMES = not settings.ENABLE_UNICODE_USERNAME # Inject our customized auth pipeline. All auth backends must work with # this pipeline. diff --git a/common/djangoapps/third_party_auth/tests/specs/base.py b/common/djangoapps/third_party_auth/tests/specs/base.py index 524cd64ff366..65f11672dca5 100644 --- a/common/djangoapps/third_party_auth/tests/specs/base.py +++ b/common/djangoapps/third_party_auth/tests/specs/base.py @@ -15,7 +15,7 @@ from django.contrib.messages.storage import fallback from django.contrib.sessions.backends import cache from django.urls import reverse -from django.test import utils as django_utils +from django.test import override_settings, utils as django_utils from django.conf import settings as django_settings # lint-amnesty, pylint: disable=reimported from social_core import actions, exceptions from social_django import utils as social_utils @@ -150,12 +150,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 settings.ENABLE_UNICODE_USERNAME 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 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): @@ -577,7 +577,7 @@ def complete_url(self): @unittest.skipUnless( - testutil.AUTH_FEATURES_KEY in django_settings.FEATURES, testutil.AUTH_FEATURES_KEY + " not in settings.FEATURES" + django_settings.ENABLE_THIRD_PARTY_AUTH, testutil.AUTH_FEATURES_KEY + " not in settings.FEATURES" ) @django_utils.override_settings() # For settings reversion on a method-by-method basis. class IntegrationTest(testutil.TestCase, test.TestCase, HelperMixin): diff --git a/common/djangoapps/third_party_auth/tests/specs/test_testshib.py b/common/djangoapps/third_party_auth/tests/specs/test_testshib.py index 47fcfa5b0bac..f1666c0fcb26 100644 --- a/common/djangoapps/third_party_auth/tests/specs/test_testshib.py +++ b/common/djangoapps/third_party_auth/tests/specs/test_testshib.py @@ -13,6 +13,7 @@ import httpretty from django.conf import settings from django.contrib import auth +from django.test import override_settings from enterprise.models import EnterpriseCustomerIdentityProvider, EnterpriseCustomerUser from freezegun import freeze_time from social_core import actions @@ -285,9 +286,7 @@ def test_full_pipeline_succeeds_for_unlinking_testshib_account( # First we expect that we're in the linked state, with a backend entry. self.assert_social_auth_exists_for_user(request.user, strategy) - FEATURES_WITH_ENTERPRISE_ENABLED = settings.FEATURES.copy() - FEATURES_WITH_ENTERPRISE_ENABLED["ENABLE_ENTERPRISE_INTEGRATION"] = True - with patch.dict("django.conf.settings.FEATURES", FEATURES_WITH_ENTERPRISE_ENABLED): + with override_settings(ENABLE_ENTERPRISE_INTEGRATION=True): # Fire off the disconnect pipeline without the user information. actions.do_disconnect( request.backend, None, None, redirect_field_name=auth.REDIRECT_FIELD_NAME, request=request 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 ed0b74ebb396..87f596d85d12 100644 --- a/common/djangoapps/third_party_auth/tests/test_models.py +++ b/common/djangoapps/third_party_auth/tests/test_models.py @@ -40,14 +40,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 accecca09ec8..2eed14aaecff 100644 --- a/common/djangoapps/third_party_auth/tests/test_settings.py +++ b/common/djangoapps/third_party_auth/tests/test_settings.py @@ -1,6 +1,7 @@ """Unit tests for settings.py.""" from unittest.mock import patch +from django.test import override_settings from common.djangoapps.third_party_auth import provider, settings from common.djangoapps.third_party_auth.tests import testutil from common.djangoapps.third_party_auth.tests.utils import skip_unless_thirdpartyauth @@ -62,6 +63,6 @@ def test_apply_settings_avoids_default_username_check(self): settings.apply_settings(self.settings) assert self.settings.SOCIAL_AUTH_CLEAN_USERNAMES # verify default behavior - with patch.dict('django.conf.settings.FEATURES', {'ENABLE_UNICODE_USERNAME': True}): + with override_settings(ENABLE_UNICODE_USERNAME=True): settings.apply_settings(self.settings) assert not self.settings.SOCIAL_AUTH_CLEAN_USERNAMES diff --git a/common/djangoapps/third_party_auth/tests/testutil.py b/common/djangoapps/third_party_auth/tests/testutil.py index 33eb30009b41..2a7517d50ff9 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 = settings.ENABLE_THIRD_PARTY_AUTH def patch_mako_templates(): diff --git a/common/djangoapps/util/course.py b/common/djangoapps/util/course.py index abef18a3263d..c98959fd02ec 100644 --- a/common/djangoapps/util/course.py +++ b/common/djangoapps/util/course.py @@ -59,7 +59,7 @@ def get_link_for_about_page(course): if is_social_sharing_enabled and course.social_sharing_url: course_about_url = course.social_sharing_url - elif settings.FEATURES.get('ENABLE_MKTG_SITE') and getattr(course, 'marketing_url', None): + elif settings.ENABLE_MKTG_SITE and getattr(course, 'marketing_url', None): course_about_url = course.marketing_url else: course_about_url = f'{about_base_url}/courses/{course.id}/about' @@ -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 settings.CERTIFICATES_HTML_VIEW: return False return course.cert_html_view_enabled diff --git a/common/djangoapps/util/file.py b/common/djangoapps/util/file.py index 57ac2c8534c4..d4c90dfb4e1f 100644 --- a/common/djangoapps/util/file.py +++ b/common/djangoapps/util/file.py @@ -115,10 +115,7 @@ def course_filename_prefix_generator(course_id, separator='_'): course_id.run ]) - enable_course_filename_ccx_suffix = settings.FEATURES.get( - 'ENABLE_COURSE_FILENAME_CCX_SUFFIX', - False - ) + enable_course_filename_ccx_suffix = settings.ENABLE_COURSE_FILENAME_CCX_SUFFIX if enable_course_filename_ccx_suffix and getattr(course_id, 'ccx', None): filename = separator.join([filename, 'ccx', course_id.ccx]) diff --git a/common/djangoapps/util/milestones_helpers.py b/common/djangoapps/util/milestones_helpers.py index 94ec358f9286..1b7e786d2c04 100644 --- a/common/djangoapps/util/milestones_helpers.py +++ b/common/djangoapps/util/milestones_helpers.py @@ -45,7 +45,7 @@ def is_prerequisite_courses_enabled(): """ Returns boolean indicating prerequisite courses enabled system wide or not. """ - return settings.FEATURES.get('ENABLE_PREREQUISITE_COURSES') and ENABLE_MILESTONES_APP.is_enabled() + return settings.ENABLE_PREREQUISITE_COURSES and ENABLE_MILESTONES_APP.is_enabled() def add_prerequisite_course(course_key, prerequisite_course_key): diff --git a/common/djangoapps/util/tests/test_course.py b/common/djangoapps/util/tests/test_course.py index f0baf5581479..069b50dea4a3 100644 --- a/common/djangoapps/util/tests/test_course.py +++ b/common/djangoapps/util/tests/test_course.py @@ -51,9 +51,7 @@ def get_course_sharing_link(self, enable_social_sharing, enable_mktg_site, use_o Returns course sharing url. """ mock_settings = { - 'FEATURES': { - 'ENABLE_MKTG_SITE': enable_mktg_site, - }, + 'ENABLE_MKTG_SITE': enable_mktg_site, 'SOCIAL_SHARING_SETTINGS': { 'CUSTOM_COURSE_URLS': enable_social_sharing } diff --git a/common/djangoapps/util/tests/test_file.py b/common/djangoapps/util/tests/test_file.py index e90ac4e5b524..e7e17f9fd792 100644 --- a/common/djangoapps/util/tests/test_file.py +++ b/common/djangoapps/util/tests/test_file.py @@ -57,7 +57,7 @@ def test_locators(self, course_key): [CCXLocator.from_course_locator(CourseLocator(org='foo', course='bar', run='baz'), '1'), 'foo_bar_baz_ccx_1'], ) @ddt.unpack - @override_settings(FEATURES={'ENABLE_COURSE_FILENAME_CCX_SUFFIX': True}) + @override_settings(ENABLE_COURSE_FILENAME_CCX_SUFFIX=True) def test_include_ccx_id(self, course_key, expected_filename): """ Test filename prefix genaration from multiple course key formats. @@ -83,7 +83,7 @@ def test_custom_separator(self, course_key): [CCXLocator.from_course_locator(CourseLocator(org='foo', course='bar', run='baz'), '1'), 'foo-bar-baz-ccx-1'], ) @ddt.unpack - @override_settings(FEATURES={'ENABLE_COURSE_FILENAME_CCX_SUFFIX': True}) + @override_settings(ENABLE_COURSE_FILENAME_CCX_SUFFIX=True) def test_custom_separator_including_ccx_id(self, course_key, expected_filename): """ Test filename prefix is generated with a custom separator. diff --git a/common/djangoapps/util/tests/test_milestones_helpers.py b/common/djangoapps/util/tests/test_milestones_helpers.py index efff367d75bb..b7f4a6f5367b 100644 --- a/common/djangoapps/util/tests/test_milestones_helpers.py +++ b/common/djangoapps/util/tests/test_milestones_helpers.py @@ -59,9 +59,7 @@ def test_pre_requisite_courses_enabled(self, feature_flags): ENABLE_PREREQUISITE_COURSES and MILESTONES_APP feature flags. """ - with patch.dict("django.conf.settings.FEATURES", { - 'ENABLE_PREREQUISITE_COURSES': feature_flags[0], - }), override_settings(MILESTONES_APP=feature_flags[1]): + with override_settings(ENABLE_PREREQUISITE_COURSES=feature_flags[0], MILESTONES_APP=feature_flags[1]): assert feature_flags[2] == milestones_helpers.is_prerequisite_courses_enabled() def test_add_milestone_returns_none_when_app_disabled(self): diff --git a/lms/djangoapps/branding/api.py b/lms/djangoapps/branding/api.py index 52aeb9b3e1b8..77b8099b713b 100644 --- a/lms/djangoapps/branding/api.py +++ b/lms/djangoapps/branding/api.py @@ -431,7 +431,7 @@ def _footer_mobile_links(is_secure): platform_name = configuration_helpers.get_value('platform_name', settings.PLATFORM_NAME) mobile_links = [] - if settings.FEATURES.get('ENABLE_FOOTER_MOBILE_APP_LINKS'): + if settings.ENABLE_FOOTER_MOBILE_APP_LINKS: mobile_links = [ { "name": "apple", diff --git a/lms/djangoapps/branding/tests/test_api.py b/lms/djangoapps/branding/tests/test_api.py index 71819a98d940..4097dcad4df4 100644 --- a/lms/djangoapps/branding/tests/test_api.py +++ b/lms/djangoapps/branding/tests/test_api.py @@ -46,7 +46,7 @@ class TestFooter(TestCase): """Test retrieving the footer. """ maxDiff = None - @mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}) + @override_settings(ENABLE_MKTG_SITE=True) @mock.patch.dict('django.conf.settings.MKTG_URLS', { "ROOT": "https://edx.org", "ENTERPRISE": "/enterprise" @@ -62,7 +62,7 @@ def test_footer_business_links_no_marketing_query_params(self): business_links = _footer_business_links() assert business_links[0]['url'] == 'https://edx.org/enterprise' - @mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}) + @override_settings(ENABLE_MKTG_SITE=True) @mock.patch.dict('django.conf.settings.MKTG_URLS', { "ROOT": "https://edx.org", "ABOUT": "/about-us", diff --git a/lms/djangoapps/branding/tests/test_page.py b/lms/djangoapps/branding/tests/test_page.py index 46f10bd6923a..0e88847466f1 100644 --- a/lms/djangoapps/branding/tests/test_page.py +++ b/lms/djangoapps/branding/tests/test_page.py @@ -24,12 +24,6 @@ from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order from xmodule.course_block import CATALOG_VISIBILITY_ABOUT, CATALOG_VISIBILITY_NONE -FEATURES_WITH_STARTDATE = settings.FEATURES.copy() -FEATURES_WITH_STARTDATE['DISABLE_START_DATES'] = False -FEATURES_WO_STARTDATE = settings.FEATURES.copy() -FEATURES_WO_STARTDATE['DISABLE_START_DATES'] = True - - def mock_render_to_response(*args, **kwargs): """ Mock the render_to_response function @@ -65,7 +59,7 @@ def get_headers(cache_response): return headers - @override_settings(FEATURES=FEATURES_WITH_STARTDATE) + @override_settings(DISABLE_START_DATES=False) def test_none_user_index_access_with_startdate_fails(self): """ This is a regression test for a bug where the incoming user is @@ -76,12 +70,12 @@ def test_none_user_index_access_with_startdate_fails(self): response = self.client.get(reverse('root')) assert response.status_code == 200 - @override_settings(FEATURES=FEATURES_WITH_STARTDATE) + @override_settings(DISABLE_START_DATES=False) def test_anon_user_with_startdate_index(self): response = self.client.get('/') assert response.status_code == 200 - @override_settings(FEATURES=FEATURES_WO_STARTDATE) + @override_settings(DISABLE_START_DATES=True) def test_anon_user_no_startdate_index(self): response = self.client.get('/') assert response.status_code == 200 @@ -131,7 +125,7 @@ class PreRequisiteCourseCatalog(ModuleStoreTestCase, LoginEnrollmentTestCase, Mi """ ENABLED_SIGNALS = ['course_published'] - @patch.dict(settings.FEATURES, {'ENABLE_PREREQUISITE_COURSES': True}) + @override_settings(ENABLE_PREREQUISITE_COURSES=True) def test_course_with_prereq(self): """ Simulate having a course which has closed enrollments that has @@ -220,7 +214,7 @@ def setUp(self): @patch('common.djangoapps.student.views.management.render_to_response', RENDER_MOCK) @patch('lms.djangoapps.courseware.views.views.render_to_response', RENDER_MOCK) - @patch.dict('django.conf.settings.FEATURES', {'ENABLE_COURSE_DISCOVERY': False}) + @override_settings(ENABLE_COURSE_DISCOVERY=False) def test_course_discovery_off(self): """ Asserts that the Course Discovery UI elements follow the @@ -244,7 +238,7 @@ def test_course_discovery_off(self): @patch('common.djangoapps.student.views.management.render_to_response', RENDER_MOCK) @patch('lms.djangoapps.courseware.views.views.render_to_response', RENDER_MOCK) - @patch.dict('django.conf.settings.FEATURES', {'ENABLE_COURSE_DISCOVERY': True}) + @override_settings(ENABLE_COURSE_DISCOVERY=True) def test_course_discovery_on(self): """ Asserts that the Course Discovery UI elements follow the @@ -266,7 +260,7 @@ def test_course_discovery_on(self): @patch('common.djangoapps.student.views.management.render_to_response', RENDER_MOCK) @patch('lms.djangoapps.courseware.views.views.render_to_response', RENDER_MOCK) - @patch.dict('django.conf.settings.FEATURES', {'ENABLE_COURSE_DISCOVERY': False}) + @override_settings(ENABLE_COURSE_DISCOVERY=False) def test_course_cards_sorted_by_default_sorting(self): response = self.client.get('/') assert response.status_code == 200 @@ -291,8 +285,7 @@ def test_course_cards_sorted_by_default_sorting(self): @patch('common.djangoapps.student.views.management.render_to_response', RENDER_MOCK) @patch('lms.djangoapps.courseware.views.views.render_to_response', RENDER_MOCK) - @patch.dict('django.conf.settings.FEATURES', {'ENABLE_COURSE_SORTING_BY_START_DATE': False}) - @patch.dict('django.conf.settings.FEATURES', {'ENABLE_COURSE_DISCOVERY': False}) + @override_settings(ENABLE_COURSE_SORTING_BY_START_DATE=False, ENABLE_COURSE_DISCOVERY=False) def test_course_cards_sorted_by_start_date_disabled(self): response = self.client.get('/') assert response.status_code == 200 diff --git a/lms/djangoapps/branding/tests/test_views.py b/lms/djangoapps/branding/tests/test_views.py index 10c27192d11a..3d8eee51acb2 100644 --- a/lms/djangoapps/branding/tests/test_views.py +++ b/lms/djangoapps/branding/tests/test_views.py @@ -46,7 +46,7 @@ def test_footer_content_types(self, theme, accepts, content_type, content): assert resp['Content-Type'] == content_type self.assertContains(resp, content) - @mock.patch.dict(settings.FEATURES, {'ENABLE_FOOTER_MOBILE_APP_LINKS': True}) + @override_settings(ENABLE_FOOTER_MOBILE_APP_LINKS=True) def test_footer_json(self): self._set_feature_flag(True) with with_comprehensive_theme_context(None): diff --git a/lms/djangoapps/branding/views.py b/lms/djangoapps/branding/views.py index 33c5813f16ff..1cd824081196 100644 --- a/lms/djangoapps/branding/views.py +++ b/lms/djangoapps/branding/views.py @@ -98,13 +98,13 @@ def courses(request): enable_mktg_site = configuration_helpers.get_value( 'ENABLE_MKTG_SITE', - settings.FEATURES.get('ENABLE_MKTG_SITE', False) + settings.ENABLE_MKTG_SITE ) if enable_mktg_site: return redirect(marketing_link('COURSES'), permanent=True) - if not settings.FEATURES.get('COURSES_ARE_BROWSABLE'): + if not settings.COURSES_ARE_BROWSABLE: raise Http404 # we do not expect this case to be reached in cases where diff --git a/lms/djangoapps/ccx/plugins.py b/lms/djangoapps/ccx/plugins.py index 1852f5727a28..2555ac74f2f2 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 settings.CUSTOM_COURSES_EDX 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_field_override_performance.py b/lms/djangoapps/ccx/tests/test_field_override_performance.py index a7128495eb59..08a26e4ebbe1 100644 --- a/lms/djangoapps/ccx/tests/test_field_override_performance.py +++ b/lms/djangoapps/ccx/tests/test_field_override_performance.py @@ -37,12 +37,7 @@ QUERY_COUNT_TABLE_IGNORELIST = WAFFLE_TABLES -@mock.patch.dict( - 'django.conf.settings.FEATURES', - { - 'ENABLE_XBLOCK_VIEW_ENDPOINT': True, - } -) +@override_settings(ENABLE_XBLOCK_VIEW_ENDPOINT=True) @ddt.ddt class FieldOverridePerformanceTestCase(FieldOverrideTestMixin, ProceduralCourseTestMixin, ModuleStoreTestCase): """ diff --git a/lms/djangoapps/ccx/tests/test_views.py b/lms/djangoapps/ccx/tests/test_views.py index e993d5dc0b7b..3a7357c08841 100644 --- a/lms/djangoapps/ccx/tests/test_views.py +++ b/lms/djangoapps/ccx/tests/test_views.py @@ -229,7 +229,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. @@ -1118,7 +1118,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 self.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 c8ef620dd2db..9e76593c1b75 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 @@ -380,7 +380,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 50e5442c28be..8b510881187f 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 - if settings.FEATURES.get('ENABLE_SPECIAL_EXAMS'): + if settings.ENABLE_SPECIAL_EXAMS: from lms.djangoapps.certificates.services import CertificateService set_runtime_service('certificates', CertificateService()) diff --git a/lms/djangoapps/certificates/generation_handler.py b/lms/djangoapps/certificates/generation_handler.py index 8c7641635731..3833d3709600 100644 --- a/lms/djangoapps/certificates/generation_handler.py +++ b/lms/djangoapps/certificates/generation_handler.py @@ -454,5 +454,4 @@ def _id_verification_enforced_and_missing(user): """ Return true if IDV is required for this course and the user does not have it """ - return settings.FEATURES.get( - 'ENABLE_CERTIFICATES_IDV_REQUIREMENT') and not IDVerificationService.user_is_verified(user) + return settings.ENABLE_CERTIFICATES_IDV_REQUIREMENT and not IDVerificationService.user_is_verified(user) diff --git a/lms/djangoapps/certificates/management/commands/tests/test_regenerate_noidv_cert.py b/lms/djangoapps/certificates/management/commands/tests/test_regenerate_noidv_cert.py index d8c2402168b5..5e2a238741b4 100644 --- a/lms/djangoapps/certificates/management/commands/tests/test_regenerate_noidv_cert.py +++ b/lms/djangoapps/certificates/management/commands/tests/test_regenerate_noidv_cert.py @@ -5,8 +5,8 @@ from unittest import mock import pytest -from django.conf import settings from django.core.management import CommandError, call_command +from django.test import override_settings from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory @@ -23,7 +23,7 @@ # base setup is unverified users, Enable certificates IDV requirements turned off, # and normal passing grade certificates for convenience -@mock.patch.dict(settings.FEATURES, ENABLE_CERTIFICATES_IDV_REQUIREMENT=False) +@override_settings(ENABLE_CERTIFICATES_IDV_REQUIREMENT=False) @mock.patch(ID_VERIFIED_METHOD, mock.Mock(return_value=False)) @mock.patch(PASSING_GRADE_METHOD, mock.Mock(return_value=True)) @mock.patch(WEB_CERTS_METHOD, mock.Mock(return_value=True)) diff --git a/lms/djangoapps/certificates/tests/test_api.py b/lms/djangoapps/certificates/tests/test_api.py index 827e4017c631..f16263e644ed 100644 --- a/lms/djangoapps/certificates/tests/test_api.py +++ b/lms/djangoapps/certificates/tests/test_api.py @@ -9,7 +9,6 @@ import ddt import pytz from config_models.models import cache -from django.conf import settings from django.test import RequestFactory, TestCase from django.test.utils import override_settings from django.urls import reverse @@ -76,10 +75,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 +186,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 +216,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 +471,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 +485,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 +517,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 +525,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 +541,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): """ @@ -557,7 +552,7 @@ def test_generation_unverified(self, enable_idv_requirement): with mock.patch(PASSING_GRADE_METHOD, return_value=True): with mock.patch(ID_VERIFIED_METHOD, return_value=False): - with mock.patch.dict(settings.FEATURES, ENABLE_CERTIFICATES_IDV_REQUIREMENT=enable_idv_requirement): + with override_settings(ENABLE_CERTIFICATES_IDV_REQUIREMENT=enable_idv_requirement): generate_certificate_task(self.user, self.course_run_key) cert = get_certificate_for_user_id(self.user.id, self.course_run_key) @@ -567,7 +562,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 +647,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_generation_handler.py b/lms/djangoapps/certificates/tests/test_generation_handler.py index d63cdce2acf7..aba196d797ca 100644 --- a/lms/djangoapps/certificates/tests/test_generation_handler.py +++ b/lms/djangoapps/certificates/tests/test_generation_handler.py @@ -207,7 +207,7 @@ def test_can_generate_not_verified(self, enable_idv_requirement): Test handling when the user's id is not verified """ with mock.patch(ID_VERIFIED_METHOD, return_value=False), \ - mock.patch.dict(settings.FEATURES, ENABLE_CERTIFICATES_IDV_REQUIREMENT=enable_idv_requirement): + override_settings(ENABLE_CERTIFICATES_IDV_REQUIREMENT=enable_idv_requirement): self.assertNotEqual( enable_idv_requirement, _can_generate_allowlist_certificate(self.user, self.course_run_key, self.enrollment_mode)) @@ -350,15 +350,15 @@ def test_generate_allowlist_honor_cert(self): CertificateAllowlistFactory.create(course_id=course_run_key, user=self.user) # Enable Honor Certificates and verify we can generate an AllowList certificate - with override_settings(FEATURES={**settings.FEATURES, 'DISABLE_HONOR_CERTIFICATES': False}): + with override_settings(DISABLE_HONOR_CERTIFICATES=False): assert _can_generate_allowlist_certificate(self.user, course_run_key, enrollment_mode) # Disable Honor Certificates and verify we cannot generate an AllowList certificate - with override_settings(FEATURES={**settings.FEATURES, 'DISABLE_HONOR_CERTIFICATES': True}): + with override_settings(DISABLE_HONOR_CERTIFICATES=True): assert not _can_generate_allowlist_certificate(self.user, course_run_key, enrollment_mode) -@mock.patch.dict(settings.FEATURES, ENABLE_CERTIFICATES_IDV_REQUIREMENT=False) +@override_settings(ENABLE_CERTIFICATES_IDV_REQUIREMENT=False) @mock.patch(ID_VERIFIED_METHOD, mock.Mock(return_value=True)) @mock.patch(CCX_COURSE_METHOD, mock.Mock(return_value=False)) @mock.patch(PASSING_GRADE_METHOD, mock.Mock(return_value=True)) @@ -535,7 +535,7 @@ def test_can_generate_not_verified_cert(self, enable_idv_requirement): ) with mock.patch(ID_VERIFIED_METHOD, return_value=False), \ - mock.patch.dict(settings.FEATURES, ENABLE_CERTIFICATES_IDV_REQUIREMENT=enable_idv_requirement): + override_settings(ENABLE_CERTIFICATES_IDV_REQUIREMENT=enable_idv_requirement): self.assertNotEqual( enable_idv_requirement, _can_generate_regular_certificate(u, self.course_run_key, self.enrollment_mode, self.grade) @@ -557,7 +557,7 @@ def test_can_generate_not_verified_no_cert(self, enable_idv_requirement): ) with mock.patch(ID_VERIFIED_METHOD, return_value=False), \ - mock.patch.dict(settings.FEATURES, ENABLE_CERTIFICATES_IDV_REQUIREMENT=enable_idv_requirement): + override_settings(ENABLE_CERTIFICATES_IDV_REQUIREMENT=enable_idv_requirement): self.assertNotEqual( enable_idv_requirement, _can_generate_regular_certificate(u, self.course_run_key, self.enrollment_mode, self.grade) @@ -585,7 +585,7 @@ def test_can_generate_not_verified_not_passing(self, enable_idv_requirement): ) with mock.patch(ID_VERIFIED_METHOD, return_value=False), \ - mock.patch.dict(settings.FEATURES, ENABLE_CERTIFICATES_IDV_REQUIREMENT=enable_idv_requirement), \ + override_settings(ENABLE_CERTIFICATES_IDV_REQUIREMENT=enable_idv_requirement), \ mock.patch(PASSING_GRADE_METHOD, return_value=False): assert not _can_generate_regular_certificate(u, self.course_run_key, self.enrollment_mode, self.grade) if enable_idv_requirement: @@ -615,7 +615,7 @@ def test_can_generate_not_verified_not_passing_allowlist(self, enable_idv_requir CertificateAllowlistFactory(course_id=self.course_run_key, user=u) with mock.patch(ID_VERIFIED_METHOD, return_value=False), \ - mock.patch.dict(settings.FEATURES, ENABLE_CERTIFICATES_IDV_REQUIREMENT=enable_idv_requirement), \ + override_settings(ENABLE_CERTIFICATES_IDV_REQUIREMENT=enable_idv_requirement), \ mock.patch(PASSING_GRADE_METHOD, return_value=False): assert not _can_generate_regular_certificate(u, self.course_run_key, self.enrollment_mode, self.grade) if enable_idv_requirement: @@ -792,11 +792,11 @@ def test_can_generate_honor_cert(self): # Enable Honor Certificates and verify we can generate a certificate with mock.patch(ID_VERIFIED_METHOD, return_value=False), \ mock.patch(PASSING_GRADE_METHOD, return_value=True), \ - override_settings(FEATURES={**settings.FEATURES, 'DISABLE_HONOR_CERTIFICATES': False}): + override_settings(DISABLE_HONOR_CERTIFICATES=False): assert _can_generate_regular_certificate(self.user, course_run_key, enrollment_mode, grade) # Disable Honor Certificates and verify we cannot generate a certificate with mock.patch(ID_VERIFIED_METHOD, return_value=False), \ mock.patch(PASSING_GRADE_METHOD, return_value=True), \ - override_settings(FEATURES={**settings.FEATURES, 'DISABLE_HONOR_CERTIFICATES': True}): + override_settings(DISABLE_HONOR_CERTIFICATES=True): assert not _can_generate_regular_certificate(self.user, course_run_key, enrollment_mode, grade) diff --git a/lms/djangoapps/certificates/tests/test_models.py b/lms/djangoapps/certificates/tests/test_models.py index cd778bb8d8f2..f818507e420d 100644 --- a/lms/djangoapps/certificates/tests/test_models.py +++ b/lms/djangoapps/certificates/tests/test_models.py @@ -7,7 +7,6 @@ import ddt import pytest -from django.conf import settings from django.core.exceptions import ValidationError from django.core.files.uploadedfile import SimpleUploadedFile from django.test import TestCase @@ -44,9 +43,6 @@ ENROLLMENT_METHOD = 'common.djangoapps.student.models.course_enrollment.CourseEnrollment.enrollment_mode_for_user' PROFILE_METHOD = 'common.djangoapps.student.models_api.get_name' -FEATURES_INVALID_FILE_PATH = settings.FEATURES.copy() -FEATURES_INVALID_FILE_PATH['CERTS_HTML_VIEW_CONFIG_PATH'] = 'invalid/path/to/config.json' - TEST_DIR = path(__file__).dirname() TEST_DATA_DIR = 'common/test/data/' PLATFORM_ROOT = TEST_DIR.parent.parent.parent.parent @@ -195,7 +191,6 @@ def test_get_not_enabled_returns_blank(self): self.config.save() assert len(self.config.get_config()) == 0 - @override_settings(FEATURES=FEATURES_INVALID_FILE_PATH) def test_get_no_database_no_file(self): """ Tests get configuration that is not enabled. diff --git a/lms/djangoapps/certificates/tests/test_support_views.py b/lms/djangoapps/certificates/tests/test_support_views.py index 89ec8ac7ee51..9b8ca8d54d88 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 @@ -23,8 +22,6 @@ from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, 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): @@ -211,7 +208,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 298e624fdd8e..2ff93087a0c5 100644 --- a/lms/djangoapps/certificates/tests/test_utils.py +++ b/lms/djangoapps/certificates/tests/test_utils.py @@ -2,10 +2,8 @@ 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 import override_settings, TestCase from pytz import utc from lms.djangoapps.certificates.utils import has_html_certificates_enabled, should_certificate_be_visible @@ -27,14 +25,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 +42,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 520baa2a8fb2..0bb200da8156 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 @@ -20,18 +19,6 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, 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): """ Tests for the certificates web/html views @@ -130,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( @@ -150,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, @@ -166,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 1bfcd6ae2e66..eb97cd67b79a 100644 --- a/lms/djangoapps/certificates/tests/test_webview_views.py +++ b/lms/djangoapps/certificates/tests/test_webview_views.py @@ -51,15 +51,6 @@ 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['CUSTOM_CERTIFICATE_TEMPLATES_ENABLED'] = True - name_affirmation_service = get_name_affirmation_service() @@ -289,7 +280,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 +305,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 +339,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 +372,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 +399,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 +588,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 +611,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 +640,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 +663,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 +685,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 +708,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 +746,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 +762,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 +789,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 +812,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 +837,7 @@ def test_certificate_view_without_org_logo(self): # make sure response html has only one organization logo container for edX self.assertContains(response, "
  • ", 1) - @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_render_html_view_without_signatories(self): self._add_course_certificates(count=1, signatory_count=0) test_url = get_certificate_url( @@ -858,7 +849,7 @@ def test_render_html_view_without_signatories(self): self.assertNotContains(response, 'Signatory_Name 0') self.assertNotContains(response, 'Signatory_Title 0') - @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + @override_settings(CERTIFICATES_HTML_VIEW=True) def test_render_html_view_is_html_escaped(self): test_certificates = [ { @@ -887,7 +878,7 @@ def test_render_html_view_is_html_escaped(self): self.assertNotContains(response, '