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
30 changes: 15 additions & 15 deletions cms/djangoapps/contentstore/tests/test_contentstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,23 +1345,23 @@ def test_create_course_with_course_creation_disabled_not_staff(self):
self.user.save()
self.assert_course_permission_denied()

@override_settings(ENABLE_CREATOR_GROUP=True)
def test_create_course_no_course_creators_staff(self):
"""Test new course creation -- course creation group enabled, staff, group is empty."""
with mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_CREATOR_GROUP': True}):
self.assert_created_course()
self.assert_created_course()

@override_settings(ENABLE_CREATOR_GROUP=True)
def test_create_course_no_course_creators_not_staff(self):
"""Test new course creation -- error path for course creator group enabled, not staff, group is empty."""
with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}):
self.user.is_staff = False
self.user.save()
self.assert_course_permission_denied()
self.user.is_staff = False
self.user.save()
self.assert_course_permission_denied()

@override_settings(ENABLE_CREATOR_GROUP=True)
def test_create_course_with_course_creator(self):
"""Test new course creation -- use course creator group"""
with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}):
auth.add_users(self.user, CourseCreatorRole(), self.user)
self.assert_created_course()
auth.add_users(self.user, CourseCreatorRole(), self.user)
self.assert_created_course()

def test_create_course_with_unicode_in_id_disabled(self):
"""
Expand Down Expand Up @@ -2014,13 +2014,13 @@ def test_rerun_course_fail_duplicate_course(self):
# Verify that the existing course continues to be in the course listing
self.assertInCourseListing(existent_course_key)

@override_settings(ENABLE_CREATOR_GROUP=True)
def test_rerun_with_permission_denied(self):
with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}):
source_course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split)
auth.add_users(self.user, CourseCreatorRole(), self.user)
self.user.is_staff = False
self.user.save()
self.post_rerun_request(source_course.id, response_code=403, expect_error=True)
source_course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split)
auth.add_users(self.user, CourseCreatorRole(), self.user)
self.user.is_staff = False
self.user.save()
self.post_rerun_request(source_course.id, response_code=403, expect_error=True)

def test_rerun_error(self):
error_message = "Mock Error Message"
Expand Down
10 changes: 5 additions & 5 deletions cms/djangoapps/contentstore/tests/test_course_create_rerun.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def test_course_creation_for_known_organization(self, organizations_autocreate):
self.assertEqual(len(course_orgs), 1) # noqa: PT009
self.assertEqual(course_orgs[0]['short_name'], 'orgX') # noqa: PT009

@override_settings(FEATURES={'ENABLE_CREATOR_GROUP': True})
@override_settings(ENABLE_CREATOR_GROUP=True)
def test_course_creation_when_user_not_in_org(self):
"""
Tests course creation when user doesn't have the required role.
Expand All @@ -208,7 +208,7 @@ def test_course_creation_when_user_not_in_org(self):
})
self.assertEqual(response.status_code, 403) # noqa: PT009

@override_settings(FEATURES={'ENABLE_CREATOR_GROUP': True})
@override_settings(ENABLE_CREATOR_GROUP=True)
@mock.patch(
'cms.djangoapps.course_creators.admin.render_to_string',
mock.Mock(side_effect=mock_render_to_string, autospec=True)
Expand All @@ -235,7 +235,7 @@ def test_course_creation_when_user_in_org_with_creator_role(self):
})
self.assertEqual(response.status_code, 200) # noqa: PT009

@override_settings(FEATURES={'ENABLE_CREATOR_GROUP': True})
@override_settings(ENABLE_CREATOR_GROUP=True)
@mock.patch(
'cms.djangoapps.course_creators.admin.render_to_string',
mock.Mock(side_effect=mock_render_to_string, autospec=True)
Expand All @@ -262,7 +262,7 @@ def test_course_creation_with_all_org_checked(self):
})
self.assertEqual(response.status_code, 200) # noqa: PT009

@override_settings(FEATURES={'ENABLE_CREATOR_GROUP': True})
@override_settings(ENABLE_CREATOR_GROUP=True)
@mock.patch(
'cms.djangoapps.course_creators.admin.render_to_string',
mock.Mock(side_effect=mock_render_to_string, autospec=True)
Expand Down Expand Up @@ -291,7 +291,7 @@ def test_course_creation_with_permission_for_specific_organization(self):
})
self.assertEqual(response.status_code, 200) # noqa: PT009

@override_settings(FEATURES={'ENABLE_CREATOR_GROUP': True})
@override_settings(ENABLE_CREATOR_GROUP=True)
@mock.patch(
'cms.djangoapps.course_creators.admin.render_to_string',
mock.Mock(side_effect=mock_render_to_string, autospec=True)
Expand Down
4 changes: 2 additions & 2 deletions cms/djangoapps/contentstore/tests/test_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,12 +574,12 @@ def test_creation(self):

# Now check that logged-in users without CourseCreator role cannot create libraries
self._login_as_non_staff_user(logout_first=False)
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_CREATOR_GROUP': True}):
with override_settings(ENABLE_CREATOR_GROUP=True):
self._assert_cannot_create_library(expected_code=403) # 403 user is not CourseCreator

# Now check that logged-in users with CourseCreator role can create libraries
add_user_with_status_granted(self.user, self.non_staff_user)
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_CREATOR_GROUP': True}):
with override_settings(ENABLE_CREATOR_GROUP=True):
lib_key2 = self._create_library(library="lib2", display_name="Test Library 2")
library2 = modulestore().get_library(lib_key2)
self.assertIsNotNone(library2) # noqa: PT009
Expand Down
8 changes: 4 additions & 4 deletions cms/djangoapps/contentstore/views/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,7 @@ def _get_course_creator_status(user):
course_creator_status = 'granted'
elif settings.FEATURES.get('DISABLE_COURSE_CREATION', False):
course_creator_status = 'disallowed_for_this_site'
elif settings.FEATURES.get('ENABLE_CREATOR_GROUP', False):
elif getattr(settings, 'ENABLE_CREATOR_GROUP', False):
course_creator_status = get_course_creator_status(user)
if course_creator_status is None:
# User not grandfathered in as an existing user, has not previously visited the dashboard page.
Expand All @@ -2038,7 +2038,7 @@ def get_allowed_organizations(user):
"""
Helper method for returning the list of organizations for which the user is allowed to create courses.
"""
if settings.FEATURES.get('ENABLE_CREATOR_GROUP', False):
if getattr(settings, 'ENABLE_CREATOR_GROUP', False):
return get_organizations(user)
else:
return []
Expand All @@ -2058,7 +2058,7 @@ def get_allowed_organizations_for_libraries(user):

# This allows people in the course creator group for an org to create
# libraries, which mimics course behavior.
if settings.FEATURES.get('ENABLE_CREATOR_GROUP', False):
if getattr(settings, 'ENABLE_CREATOR_GROUP', False):
organizations_set.update(get_organizations(user))

return sorted(organizations_set)
Expand All @@ -2068,7 +2068,7 @@ def user_can_create_organizations(user):
"""
Returns True if the user can create organizations.
"""
return user.is_staff or not settings.FEATURES.get('ENABLE_CREATOR_GROUP', False)
return user.is_staff or not getattr(settings, 'ENABLE_CREATOR_GROUP', False)


def get_organizations_for_non_course_creators(user):
Expand Down
2 changes: 1 addition & 1 deletion cms/djangoapps/contentstore/views/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _user_can_create_library_for_org(user, org=None):
return False
elif user.is_staff:
return True
elif settings.FEATURES.get('ENABLE_CREATOR_GROUP', False):
elif getattr(settings, 'ENABLE_CREATOR_GROUP', False):
is_course_creator = get_course_creator_status(user) == 'granted'
if is_course_creator:
return True
Expand Down
25 changes: 11 additions & 14 deletions cms/djangoapps/contentstore/views/tests/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_library_creator_status_with_no_course_creator_role(self):
@mock.patch("cms.djangoapps.contentstore.toggles.libraries_v1_enabled", True)
def test_library_creator_status_for_enabled_creator_group_setting_for_non_staff_users(self):
_, nostaff_user = self.create_non_staff_authed_user_client()
with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}):
with override_settings(ENABLE_CREATOR_GROUP=True):
self.assertEqual(user_can_create_library(nostaff_user, None), False) # noqa: PT009

# Global staff can create libraries for any org, even ones that don't exist.
Expand All @@ -88,14 +88,14 @@ def test_library_creator_status_with_is_staff_user_no_org(self):
# When creator groups are enabled, global staff can create libraries in any org
@mock.patch("cms.djangoapps.contentstore.toggles.libraries_v1_enabled", True)
def test_library_creator_status_for_enabled_creator_group_setting_with_is_staff_user(self):
with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}):
with override_settings(ENABLE_CREATOR_GROUP=True):
self.assertEqual(user_can_create_library(self.user, 'RandomOrg'), True) # noqa: PT009

# When creator groups are enabled, course creators can create libraries in any org.
@mock.patch("cms.djangoapps.contentstore.toggles.libraries_v1_enabled", True)
def test_library_creator_status_with_course_creator_role_for_enabled_creator_group_setting(self):
_, nostaff_user = self.create_non_staff_authed_user_client()
with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}):
with override_settings(ENABLE_CREATOR_GROUP=True):
grant_course_creator_status(self.user, nostaff_user)
self.assertEqual(user_can_create_library(nostaff_user, 'soMeRandOmoRg'), True) # noqa: PT009

Expand All @@ -104,7 +104,7 @@ def test_library_creator_status_with_course_creator_role_for_enabled_creator_gro
@mock.patch("cms.djangoapps.contentstore.toggles.libraries_v1_enabled", True)
def test_library_creator_status_with_course_staff_role_for_enabled_creator_group_setting(self):
_, nostaff_user = self.create_non_staff_authed_user_client()
with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}):
with override_settings(ENABLE_CREATOR_GROUP=True):
auth.add_users(self.user, CourseStaffRole(self.course.id), nostaff_user)
self.assertEqual(user_can_create_library(nostaff_user, self.course.org), True) # noqa: PT009
self.assertEqual(user_can_create_library(nostaff_user, 'SomEOtherOrg'), False) # noqa: PT009
Expand All @@ -114,7 +114,7 @@ def test_library_creator_status_with_course_staff_role_for_enabled_creator_group
@mock.patch("cms.djangoapps.contentstore.toggles.libraries_v1_enabled", True)
def test_library_creator_status_with_course_instructor_role_for_enabled_creator_group_setting(self):
_, nostaff_user = self.create_non_staff_authed_user_client()
with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}):
with override_settings(ENABLE_CREATOR_GROUP=True):
auth.add_users(self.user, CourseInstructorRole(self.course.id), nostaff_user)
self.assertEqual(user_can_create_library(nostaff_user, self.course.org), True) # noqa: PT009
self.assertEqual(user_can_create_library(nostaff_user, 'SomEOtherOrg'), False) # noqa: PT009
Expand Down Expand Up @@ -206,7 +206,7 @@ def test_create_library(self):
self.assertEqual(response.status_code, 200) # noqa: PT009
# That's all we check. More detailed tests are in contentstore.tests.test_libraries...

@patch.dict('django.conf.settings.FEATURES', {'ENABLE_CREATOR_GROUP': True})
@override_settings(ENABLE_CREATOR_GROUP=True)
def test_lib_create_permission(self):
"""
Users who are given course creator roles should be able to create libraries.
Expand All @@ -220,7 +220,7 @@ def test_lib_create_permission(self):
})
self.assertEqual(response.status_code, 200) # noqa: PT009

@patch.dict('django.conf.settings.FEATURES', {'ENABLE_CREATOR_GROUP': False})
@override_settings(ENABLE_CREATOR_GROUP=False)
def test_lib_create_permission_no_course_creator_role_and_no_course_creator_group(self):
"""
Users who are not given course creator roles should still be able to create libraries
Expand All @@ -234,7 +234,7 @@ def test_lib_create_permission_no_course_creator_role_and_no_course_creator_grou
})
self.assertEqual(response.status_code, 200) # noqa: PT009

@patch.dict('django.conf.settings.FEATURES', {'ENABLE_CREATOR_GROUP': True})
@override_settings(ENABLE_CREATOR_GROUP=True)
def test_lib_create_permission_no_course_creator_role_and_no_course_creator_group_and_no_course_staff_role(self):
"""
Users who are not given course creator roles or course staff role should not be able to create libraries
Expand All @@ -248,7 +248,7 @@ def test_lib_create_permission_no_course_creator_role_and_no_course_creator_grou
})
self.assertEqual(response.status_code, 403) # noqa: PT009

@patch.dict('django.conf.settings.FEATURES', {'ENABLE_CREATOR_GROUP': True})
@override_settings(ENABLE_CREATOR_GROUP=True)
def test_lib_create_permission_course_staff_role(self):
"""
Users who are staff on any existing course should able to create libraries
Expand Down Expand Up @@ -492,14 +492,11 @@ def test_allowed_organizations_for_library(self):
'django.conf.settings.FEATURES',
{"ENABLE_ORGANIZATION_STAFF_ACCESS_FOR_CONTENT_LIBRARIES": False}
):
with mock.patch.dict(
'django.conf.settings.FEATURES',
{"ENABLE_CREATOR_GROUP": False}
):
with override_settings(ENABLE_CREATOR_GROUP=False):
organizations = get_allowed_organizations_for_libraries(self.user)
# Assert that the method returned the expected value
self.assertEqual(organizations, []) # noqa: PT009
with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}):
with override_settings(ENABLE_CREATOR_GROUP=True):
# Assert that correct org values are returned based on course creator state
for course_creator_state in CourseCreator.STATES:
course_creator.state = course_creator_state
Expand Down
16 changes: 8 additions & 8 deletions cms/djangoapps/contentstore/views/tests/test_organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,44 +89,44 @@ def setUpTestData(cls):
)

@override_settings(
ENABLE_CREATOR_GROUP=False,
FEATURES={
**settings.FEATURES,
'ENABLE_ORGANIZATION_STAFF_ACCESS_FOR_CONTENT_LIBRARIES': False,
'ENABLE_CREATOR_GROUP': False,
}
},
)
def test_both_toggles_disabled(self):
allowed_orgs = get_allowed_organizations_for_libraries(self.library_author)
assert allowed_orgs == []

@override_settings(
ENABLE_CREATOR_GROUP=True,
FEATURES={
**settings.FEATURES,
'ENABLE_ORGANIZATION_STAFF_ACCESS_FOR_CONTENT_LIBRARIES': True,
'ENABLE_CREATOR_GROUP': True,
}
},
)
def test_both_toggles_enabled(self):
allowed_orgs = get_allowed_organizations_for_libraries(self.library_author)
assert allowed_orgs == ["CreatorOrg", "OrgStaffOrg"]

@override_settings(
ENABLE_CREATOR_GROUP=False,
FEATURES={
**settings.FEATURES,
'ENABLE_ORGANIZATION_STAFF_ACCESS_FOR_CONTENT_LIBRARIES': True,
'ENABLE_CREATOR_GROUP': False,
}
},
)
def test_org_staff_enabled(self):
allowed_orgs = get_allowed_organizations_for_libraries(self.library_author)
assert allowed_orgs == ["OrgStaffOrg"]

@override_settings(
ENABLE_CREATOR_GROUP=True,
FEATURES={
**settings.FEATURES,
'ENABLE_ORGANIZATION_STAFF_ACCESS_FOR_CONTENT_LIBRARIES': False,
'ENABLE_CREATOR_GROUP': True,
}
},
)
def test_creator_group_enabled(self):
allowed_orgs = get_allowed_organizations_for_libraries(self.library_author)
Expand Down
6 changes: 4 additions & 2 deletions cms/djangoapps/course_creators/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.core import mail
from django.http import HttpRequest
from django.test import TestCase
from django.test.utils import override_settings

from cms.djangoapps.course_creators.admin import CourseCreatorAdmin
from cms.djangoapps.course_creators.models import CourseCreator
Expand Down Expand Up @@ -52,10 +53,10 @@ def setUp(self):

self.studio_request_email = 'mark@marky.mark'
self.enable_creator_group_patch = {
"ENABLE_CREATOR_GROUP": True,
"STUDIO_REQUEST_EMAIL": self.studio_request_email
"STUDIO_REQUEST_EMAIL": self.studio_request_email,
}

@override_settings(ENABLE_CREATOR_GROUP=True)
@mock.patch(
'cms.djangoapps.course_creators.admin.render_to_string',
mock.Mock(side_effect=mock_render_to_string, autospec=True)
Expand Down Expand Up @@ -103,6 +104,7 @@ def change_state_and_verify_email(state, is_creator):

change_state_and_verify_email(CourseCreator.DENIED, False)

@override_settings(ENABLE_CREATOR_GROUP=True)
@mock.patch(
'cms.djangoapps.course_creators.admin.render_to_string',
mock.Mock(side_effect=mock_render_to_string, autospec=True)
Expand Down
Loading
Loading