Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
Unit tests for course details views.
"""
import json
from unittest.mock import MagicMock, patch
from unittest.mock import MagicMock

import ddt
from django.test.utils import override_settings
from django.urls import reverse
from openedx_authz.constants.roles import COURSE_EDITOR, COURSE_STAFF
from rest_framework import status
Expand Down Expand Up @@ -57,7 +58,7 @@ def test_put_permissions_unauthorized(self):
self.assertEqual(error, "You do not have permission to perform this action.") # noqa: PT009
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) # noqa: PT009

@patch.dict("django.conf.settings.FEATURES", {"ENABLE_PREREQUISITE_COURSES": True})
@override_settings(ENABLE_PREREQUISITE_COURSES=True)
def test_put_invalid_pre_requisite_course(self):
pre_requisite_course_keys = [str(self.course.id), "invalid_key"]
request_data = {"pre_requisite_courses": pre_requisite_course_keys}
Expand Down Expand Up @@ -619,7 +620,7 @@ def test_put_user_without_role_then_added_can_update(self):
)
self.assertEqual(response.status_code, status.HTTP_200_OK) # noqa: PT009

@patch.dict("django.conf.settings.FEATURES", {"ENABLE_PREREQUISITE_COURSES": True})
@override_settings(ENABLE_PREREQUISITE_COURSES=True)
def test_put_invalid_pre_requisite_course_with_authz(self):
"""
Ensure validation still applies under AuthZ.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import ddt
from django.conf import settings
from django.test import override_settings
from django.urls import reverse
from openedx_authz.constants.roles import COURSE_EDITOR
from rest_framework import status
Expand Down Expand Up @@ -73,13 +74,7 @@ def test_credit_eligibility_setting(self):
self.assertIn("credit_requirements", response.data) # noqa: PT009
self.assertTrue(response.data["is_credit_course"]) # noqa: PT009

@patch.dict(
"django.conf.settings.FEATURES",
{
"ENABLE_PREREQUISITE_COURSES": True,
"MILESTONES_APP": True,
},
)
@override_settings(ENABLE_PREREQUISITE_COURSES=True, MILESTONES_APP=True)
def test_prerequisite_courses_enabled_setting(self):
"""
Make sure if the feature flags are enabled we have updated the dict keys in response.
Expand Down
6 changes: 3 additions & 3 deletions cms/djangoapps/contentstore/tests/test_course_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def compare_date_fields(self, details, encoded, context, field):
elif field in encoded and encoded[field] is not None:
self.fail(field + " included in encoding but missing from details at " + context)

@mock.patch.dict("django.conf.settings.FEATURES", {'ENABLE_PREREQUISITE_COURSES': True})
@override_settings(ENABLE_PREREQUISITE_COURSES=True)
def test_pre_requisite_course_update_and_fetch(self):
self.assertFalse(milestones_helpers.any_unfulfilled_milestones(self.course.id, self.user.id), # noqa: PT009
msg='The initial empty state should be: no prerequisite courses')
Expand Down Expand Up @@ -324,7 +324,7 @@ def test_pre_requisite_course_update_and_fetch(self):
self.assertFalse(milestones_helpers.any_unfulfilled_milestones(self.course.id, self.user.id), # noqa: PT009
msg='Should not have prerequisite courses anymore')

@mock.patch.dict("django.conf.settings.FEATURES", {'ENABLE_PREREQUISITE_COURSES': True})
@override_settings(ENABLE_PREREQUISITE_COURSES=True)
def test_invalid_pre_requisite_course(self):
url = get_url(self.course.id)
resp = self.client.get_json(url)
Expand Down Expand Up @@ -436,7 +436,7 @@ def test_entrance_exam_store_default_min_score(self):
self.assertEqual(course.entrance_exam_minimum_score_pct, .5) # noqa: PT009

@unittest.skipUnless(settings.ENTRANCE_EXAMS, True)
@mock.patch.dict("django.conf.settings.FEATURES", {'ENABLE_PREREQUISITE_COURSES': True})
@override_settings(ENABLE_PREREQUISITE_COURSES=True)
def test_entrance_after_changing_other_setting(self):
"""
Test entrance exam is not deactivated when prerequisites removed.
Expand Down
10 changes: 2 additions & 8 deletions cms/djangoapps/contentstore/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,10 +884,7 @@ def setUp(self):
super().setUp()
self.course = CourseFactory.create()

@patch.dict("django.conf.settings.FEATURES", {
"ENABLE_PREREQUISITE_COURSES": False,
})
@override_settings(ENTRANCE_EXAMS=False)
@override_settings(ENABLE_PREREQUISITE_COURSES=False, ENTRANCE_EXAMS=False)
@patch("cms.djangoapps.contentstore.utils.CourseDetails.update_from_json")
def test_update_course_details_self_paced(self, mock_update):
"""
Expand All @@ -910,10 +907,7 @@ def test_update_course_details_self_paced(self, mock_update):
utils.update_course_details(mock_request, self.course.id, payload, None)
mock_update.assert_called_once_with(self.course.id, expected_payload, mock_request.user)

@patch.dict("django.conf.settings.FEATURES", {
"ENABLE_PREREQUISITE_COURSES": False,
})
@override_settings(ENTRANCE_EXAMS=False)
@override_settings(ENABLE_PREREQUISITE_COURSES=False, ENTRANCE_EXAMS=False)
@patch("cms.djangoapps.contentstore.utils.CourseDetails.update_from_json")
def test_update_course_details_instructor_paced(self, mock_update):
"""
Expand Down
6 changes: 1 addition & 5 deletions cms/lib/xblock/test/test_authoring_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""


from django.conf import settings
from django.test.utils import override_settings
from xblock.core import XBlock

Expand Down Expand Up @@ -32,9 +31,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):
"""
Expand Down Expand Up @@ -170,7 +166,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
Expand Down
3 changes: 2 additions & 1 deletion common/djangoapps/student/tests/test_course_listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from django.conf import settings
from django.test.client import Client
from django.test.utils import override_settings
from milestones.tests.utils import MilestonesTestCaseMixin

from common.djangoapps.student.models import CourseEnrollment # pylint: disable=unused-import
Expand Down Expand Up @@ -139,7 +140,7 @@ def test_course_listing_errored_deleted_courses(self):
assert len(courses_list) == 1, courses_list
assert courses_list[0].course_id == good_location

@mock.patch.dict("django.conf.settings.FEATURES", {'ENABLE_PREREQUISITE_COURSES': True})
@override_settings(ENABLE_PREREQUISITE_COURSES=True)
def test_course_listing_has_pre_requisite_courses(self):
"""
Creates four courses. Enroll test user in all courses
Expand Down
2 changes: 1 addition & 1 deletion common/djangoapps/student/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def test_sharing_icons_for_future_course(self, set_marketing, set_social_sharing
assert ('Share on Twitter' in response.content.decode('utf-8')) == (set_marketing or set_social_sharing)
assert ('Share on Facebook' in response.content.decode('utf-8')) == (set_marketing or set_social_sharing)

@patch.dict("django.conf.settings.FEATURES", {'ENABLE_PREREQUISITE_COURSES': True})
@override_settings(ENABLE_PREREQUISITE_COURSES=True)
def test_pre_requisites_appear_on_dashboard(self):
"""
When a course has a prerequisite, the dashboard should display the prerequisite.
Expand Down
8 changes: 4 additions & 4 deletions common/djangoapps/student/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def _check_verification_status_on(self, mode, value):
self.assertContains(response, f'class="course {mode}"')
self.assertContains(response, value)

@patch.dict("django.conf.settings.FEATURES", {'ENABLE_VERIFIED_CERTIFICATES': True})
@override_settings(ENABLE_VERIFIED_CERTIFICATES=True)
def test_verification_status_visible(self):
"""
Test that the certificate verification status for courses is visible on the dashboard.
Expand Down Expand Up @@ -402,7 +402,7 @@ def _check_verification_status_off(self, mode, value):
self.assertNotContains(response, f"class=\"course {mode}\"")
self.assertNotContains(response, value)

@patch.dict("django.conf.settings.FEATURES", {'ENABLE_VERIFIED_CERTIFICATES': False})
@override_settings(ENABLE_VERIFIED_CERTIFICATES=False)
def test_verification_status_invisible(self):
"""
Test that the certificate verification status for courses is not visible on the dashboard
Expand Down Expand Up @@ -621,7 +621,7 @@ def setUp(self):
cache.clear()

@skip_unless_lms
@patch.dict("django.conf.settings.FEATURES", {'ENABLE_VERIFIED_CERTIFICATES': False})
@override_settings(ENABLE_VERIFIED_CERTIFICATES=False)
@ddt.data(
('testserver1.com', {'ENABLE_VERIFIED_CERTIFICATES': True}),
('testserver2.com', {'ENABLE_VERIFIED_CERTIFICATES': True, 'DISPLAY_COURSE_MODES_ON_DASHBOARD': True}),
Expand All @@ -642,7 +642,7 @@ def test_course_mode_visible(self, site_domain, site_configuration_values):
self.assertContains(response, 'class="course professional"')

@skip_unless_lms
@patch.dict("django.conf.settings.FEATURES", {'ENABLE_VERIFIED_CERTIFICATES': False})
@override_settings(ENABLE_VERIFIED_CERTIFICATES=False)
@ddt.data(
('testserver3.com', {'ENABLE_VERIFIED_CERTIFICATES': False}),
('testserver4.com', {'DISPLAY_COURSE_MODES_ON_DASHBOARD': False}),
Expand Down
4 changes: 2 additions & 2 deletions common/djangoapps/student/views/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,11 @@ def student_dashboard(request): # pylint: disable=too-many-statements

enable_verified_certificates = configuration_helpers.get_value(
'ENABLE_VERIFIED_CERTIFICATES',
settings.FEATURES.get('ENABLE_VERIFIED_CERTIFICATES')
getattr(settings, 'ENABLE_VERIFIED_CERTIFICATES', False)
)
display_course_modes_on_dashboard = configuration_helpers.get_value(
'DISPLAY_COURSE_MODES_ON_DASHBOARD',
settings.FEATURES.get('DISPLAY_COURSE_MODES_ON_DASHBOARD', True)
settings.DISPLAY_COURSE_MODES_ON_DASHBOARD
)
activation_email_support_link = configuration_helpers.get_value(
'ACTIVATION_EMAIL_SUPPORT_LINK', settings.ACTIVATION_EMAIL_SUPPORT_LINK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from uuid import uuid4

import pytest
from django.conf import settings
from django.core.management import call_command
from django.core.management.base import CommandError
from django.test import TestCase, override_settings
Expand All @@ -20,9 +19,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):
Expand Down Expand Up @@ -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)

Expand All @@ -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): # noqa: PT027
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'):
Expand All @@ -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): # noqa: PT027
Expand Down
2 changes: 1 addition & 1 deletion common/djangoapps/util/milestones_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,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):
Expand Down
8 changes: 4 additions & 4 deletions common/djangoapps/util/tests/test_milestones_helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Tests for the milestones helpers library, which is the integration point for the edx_milestones API
"""
from unittest.mock import patch

import ddt
import pytest
Expand Down Expand Up @@ -61,9 +60,10 @@ 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):
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/branding/tests/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,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
Expand Down
5 changes: 2 additions & 3 deletions lms/djangoapps/certificates/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@


from datetime import datetime, timedelta
from unittest.mock import patch

from ddt import data, ddt, unpack
from django.conf import settings
from django.test.utils import override_settings
from milestones.tests.utils import MilestonesTestCaseMixin
from pytz import UTC

Expand Down Expand Up @@ -181,7 +180,7 @@ def test_course_ids_with_certs_for_user(self):
{course_1.id, course_2.id}
)

@patch.dict(settings.FEATURES, {'ENABLE_PREREQUISITE_COURSES': True})
@override_settings(ENABLE_PREREQUISITE_COURSES=True)
def test_course_milestone_collected(self):
student = UserFactory()
course = CourseFactory.create(org='edx', number='998', display_name='Test Course')
Expand Down
8 changes: 4 additions & 4 deletions lms/djangoapps/courseware/tests/test_about.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_logged_in_marketing(self):
resp = self.client.get(url)
self.assertRedirects(resp, course_home_url(self.course.id), fetch_redirect_response=False)

@patch.dict(settings.FEATURES, {'ENABLE_COURSE_HOME_REDIRECT': False})
@override_settings(ENABLE_COURSE_HOME_REDIRECT=False)
@patch.dict(settings.FEATURES, {'ENABLE_MKTG_SITE': True})
def test_logged_in_marketing_without_course_home_redirect(self):
"""
Expand All @@ -135,7 +135,7 @@ def test_logged_in_marketing_without_course_home_redirect(self):
# should not be redirected
self.assertContains(resp, "OOGIE BLOOGIE")

@patch.dict(settings.FEATURES, {'ENABLE_COURSE_HOME_REDIRECT': True})
@override_settings(ENABLE_COURSE_HOME_REDIRECT=True)
@patch.dict(settings.FEATURES, {'ENABLE_MKTG_SITE': False})
def test_logged_in_marketing_without_mktg_site(self):
"""
Expand All @@ -148,7 +148,7 @@ def test_logged_in_marketing_without_mktg_site(self):
# should not be redirected
self.assertContains(resp, "OOGIE BLOOGIE")

@patch.dict(settings.FEATURES, {'ENABLE_PREREQUISITE_COURSES': True})
@override_settings(ENABLE_PREREQUISITE_COURSES=True)
def test_pre_requisite_course(self):
pre_requisite_course = CourseFactory.create(org='edX', course='900', display_name='pre requisite course')
course = CourseFactory.create(pre_requisite_courses=[str(pre_requisite_course.id)])
Expand All @@ -163,7 +163,7 @@ def test_pre_requisite_course(self):
f'{pre_requisite_courses[0]["display"]}</a> before you begin this course.'
) in resp.content.decode(resp.charset).strip('\n')

@patch.dict(settings.FEATURES, {'ENABLE_PREREQUISITE_COURSES': True})
@override_settings(ENABLE_PREREQUISITE_COURSES=True)
def test_about_page_unfulfilled_prereqs(self):
pre_requisite_course = CourseFactory.create(
org='edX',
Expand Down
3 changes: 1 addition & 2 deletions lms/djangoapps/courseware/tests/test_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,7 @@ def test__catalog_visibility_returns_typed_error(self):
assert isinstance(see_in_catalog_response, access_response.CatalogVisibilityError)
assert access._has_access_course(user, 'see_about_page', course_about)

@patch.dict("django.conf.settings.FEATURES", {'ENABLE_PREREQUISITE_COURSES': True})
@override_settings(MILESTONES_APP=True)
@override_settings(ENABLE_PREREQUISITE_COURSES=True, MILESTONES_APP=True)
def test_access_on_course_with_pre_requisites(self):
"""
Test course access when a course has pre-requisite course yet to be completed
Expand Down
3 changes: 1 addition & 2 deletions lms/djangoapps/courseware/tests/test_masquerade.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ def test_masquerade_options_for_learner(self, partitions_enabled):
"""
If there are partitions, then the View as Learner should NOT be available
"""
with patch.dict('django.conf.settings.FEATURES',
{'ENABLE_ENROLLMENT_TRACK_USER_PARTITION': partitions_enabled}):
with override_settings(ENABLE_ENROLLMENT_TRACK_USER_PARTITION=partitions_enabled):
response = self.get_available_masquerade_identities()
is_learner_available = 'Learner' in map(itemgetter('name'), response.json()['available'])
assert partitions_enabled != is_learner_available
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/courseware/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ def _course_home_redirect_enabled():
if configuration_helpers.get_value(
'ENABLE_MKTG_SITE', settings.FEATURES.get('ENABLE_MKTG_SITE', False)
) and configuration_helpers.get_value(
'ENABLE_COURSE_HOME_REDIRECT', settings.FEATURES.get('ENABLE_COURSE_HOME_REDIRECT', True)
'ENABLE_COURSE_HOME_REDIRECT', settings.ENABLE_COURSE_HOME_REDIRECT
):
return True

Expand Down
Loading
Loading