1919from cms .djangoapps .contentstore .tests .utils import AjaxEnabledTestClient , CourseTestCase , parse_json
2020from cms .djangoapps .contentstore .utils import reverse_course_url , reverse_library_url
2121from cms .djangoapps .course_creators .views import add_user_with_status_granted as grant_course_creator_status
22- from common .djangoapps .student .roles import LibraryUserRole , CourseStaffRole
22+ from common .djangoapps .student .roles import LibraryUserRole
2323from xmodule .modulestore .tests .factories import LibraryFactory # lint-amnesty, pylint: disable=wrong-import-order
24- from cms .djangoapps .course_creators .models import CourseCreator
25-
26- from common .djangoapps .student import auth
2724
2825from ..component import get_component_templates
2926from ..library import user_can_create_library
30- from ..course import get_allowed_organizations_for_libraries
3127
3228LIBRARY_REST_URL = '/library/' # URL for GET/POST requests involving libraries
3329
@@ -55,51 +51,26 @@ def setUp(self):
5551 ######################################################
5652 # Tests for /library/ - list and create libraries:
5753
58- # When libraries are disabled, nobody can create libraries
5954 @mock .patch ("cms.djangoapps.contentstore.views.library.LIBRARIES_ENABLED" , False )
6055 def test_library_creator_status_libraries_not_enabled (self ):
6156 _ , nostaff_user = self .create_non_staff_authed_user_client ()
6257 self .assertEqual (user_can_create_library (nostaff_user ), False )
6358
64- # When creator group is disabled, non-staff users can create libraries
65- @mock .patch ("cms.djangoapps.contentstore.views.library.LIBRARIES_ENABLED" , True )
66- def test_library_creator_status_with_no_course_creator_role (self ):
67- _ , nostaff_user = self .create_non_staff_authed_user_client ()
68- self .assertEqual (user_can_create_library (nostaff_user ), True )
69-
70- # When creator group is enabled, Non staff users cannot create libraries
71- @mock .patch ("cms.djangoapps.contentstore.views.library.LIBRARIES_ENABLED" , True )
72- def test_library_creator_status_for_enabled_creator_group_setting_for_non_staff_users (self ):
73- _ , nostaff_user = self .create_non_staff_authed_user_client ()
74- with mock .patch .dict ('django.conf.settings.FEATURES' , {"ENABLE_CREATOR_GROUP" : True }):
75- self .assertEqual (user_can_create_library (nostaff_user ), False )
76-
77- # Global staff can create libraries
7859 @mock .patch ("cms.djangoapps.contentstore.views.library.LIBRARIES_ENABLED" , True )
7960 def test_library_creator_status_with_is_staff_user (self ):
8061 self .assertEqual (user_can_create_library (self .user ), True )
8162
82- # When creator groups are enabled, global staff can create libraries
83- @mock .patch ("cms.djangoapps.contentstore.views.library.LIBRARIES_ENABLED" , True )
84- def test_library_creator_status_for_enabled_creator_group_setting_with_is_staff_user (self ):
85- with mock .patch .dict ('django.conf.settings.FEATURES' , {"ENABLE_CREATOR_GROUP" : True }):
86- self .assertEqual (user_can_create_library (self .user ), True )
87-
88- # When creator groups are enabled, course creators can create libraries
8963 @mock .patch ("cms.djangoapps.contentstore.views.library.LIBRARIES_ENABLED" , True )
90- def test_library_creator_status_with_course_creator_role_for_enabled_creator_group_setting (self ):
64+ def test_library_creator_status_with_course_creator_role (self ):
9165 _ , nostaff_user = self .create_non_staff_authed_user_client ()
9266 with mock .patch .dict ('django.conf.settings.FEATURES' , {"ENABLE_CREATOR_GROUP" : True }):
9367 grant_course_creator_status (self .user , nostaff_user )
9468 self .assertEqual (user_can_create_library (nostaff_user ), True )
9569
96- # When creator groups are enabled, course staff members can create libraries
9770 @mock .patch ("cms.djangoapps.contentstore.views.library.LIBRARIES_ENABLED" , True )
98- def test_library_creator_status_with_course_staff_role_for_enabled_creator_group_setting (self ):
71+ def test_library_creator_status_with_no_course_creator_role (self ):
9972 _ , nostaff_user = self .create_non_staff_authed_user_client ()
100- with mock .patch .dict ('django.conf.settings.FEATURES' , {"ENABLE_CREATOR_GROUP" : True }):
101- auth .add_users (self .user , CourseStaffRole (self .course .id ), nostaff_user )
102- self .assertEqual (user_can_create_library (nostaff_user ), True )
73+ self .assertEqual (user_can_create_library (nostaff_user ), True )
10374
10475 @ddt .data (
10576 (False , False , True ),
@@ -217,9 +188,9 @@ def test_lib_create_permission_no_course_creator_role_and_no_course_creator_grou
217188 self .assertEqual (response .status_code , 200 )
218189
219190 @patch .dict ('django.conf.settings.FEATURES' , {'ENABLE_CREATOR_GROUP' : True })
220- def test_lib_create_permission_no_course_creator_role_and_no_course_creator_group_and_no_course_staff_role (self ):
191+ def test_lib_create_permission_no_course_creator_role_and_course_creator_group (self ):
221192 """
222- Users who are not given course creator roles or course staff role should not be able to create libraries
193+ Users who are not given course creator roles should not be able to create libraries
223194 if ENABLE_CREATOR_GROUP is enabled.
224195 """
225196 self .client .logout ()
@@ -230,23 +201,6 @@ def test_lib_create_permission_no_course_creator_role_and_no_course_creator_grou
230201 })
231202 self .assertEqual (response .status_code , 403 )
232203
233- @patch .dict ('django.conf.settings.FEATURES' , {'ENABLE_CREATOR_GROUP' : True })
234- def test_lib_create_permission_course_staff_role (self ):
235- """
236- Users who are staff on any existing course should able to create libraries
237- if ENABLE_CREATOR_GROUP is enabled.
238- """
239- self .client .logout ()
240- ns_user , password = self .create_non_staff_user ()
241- self .client .login (username = ns_user .username , password = password )
242-
243- auth .add_users (self .user , CourseStaffRole (self .course .id ), ns_user )
244- self .assertTrue (auth .user_has_role (ns_user , CourseStaffRole (self .course .id )))
245- response = self .client .ajax_post (LIBRARY_REST_URL , {
246- 'org' : 'org' , 'library' : 'lib' , 'display_name' : "New Library" ,
247- })
248- self .assertEqual (response .status_code , 200 )
249-
250204 @ddt .data (
251205 {},
252206 {'org' : 'org' },
@@ -451,41 +405,3 @@ def test_component_limits(self):
451405 response = self .client .ajax_post (reverse ('xblock_handler' ), data )
452406 self .assertEqual (response .status_code , 400 )
453407 self .assertIn ('cannot have more than 1 component' , parse_json (response )['error' ])
454-
455- def test_allowed_organizations_for_library (self ):
456- """
457- Test the different organizations that a user can select for creating a library, depending
458- on Feature Flags and on user role.
459- With organization staff access enabled, a user should be able to select organizations they
460- are a staff member of. Else, with creator groups enabled, the user should be able to select
461- organizations they are course creator for.
462- """
463- course_creator = CourseCreator .objects .create (user = self .user , all_organizations = True )
464- with patch ('cms.djangoapps.course_creators.models.CourseCreator.objects.filter' ) as mock_filter :
465- mock_filter .return_value .first .return_value = course_creator
466- with patch ('organizations.models.Organization.objects.all' ) as mock_all :
467- mock_all .return_value .values_list .return_value = ['org1' , 'org2' ]
468- with patch ('common.djangoapps.student.roles.OrgStaffRole.get_orgs_for_user' ) as get_user_orgs :
469- get_user_orgs .return_value = ['org3' ]
470- # Call the method under test
471- with mock .patch .dict (
472- 'django.conf.settings.FEATURES' ,
473- {"ENABLE_ORGANIZATION_STAFF_ACCESS_FOR_CONTENT_LIBRARIES" : False }
474- ):
475- with mock .patch .dict (
476- 'django.conf.settings.FEATURES' ,
477- {"ENABLE_CREATOR_GROUP" : False }
478- ):
479- organizations = get_allowed_organizations_for_libraries (self .user )
480- # Assert that the method returned the expected value
481- self .assertEqual (organizations , [])
482- with mock .patch .dict ('django.conf.settings.FEATURES' , {"ENABLE_CREATOR_GROUP" : True }):
483- organizations = get_allowed_organizations_for_libraries (self .user )
484- # Assert that the method returned the expected value
485- self .assertEqual (organizations , ['org1' , 'org2' ])
486- with mock .patch .dict (
487- 'django.conf.settings.FEATURES' ,
488- {"ENABLE_ORGANIZATION_STAFF_ACCESS_FOR_CONTENT_LIBRARIES" : True }
489- ):
490- organizations = get_allowed_organizations_for_libraries (self .user )
491- self .assertEqual (organizations , ['org3' ])
0 commit comments