11"""
2- Tests for Content Groups (Group Configurations) V2 API in Instructor Dashboard .
2+ Tests for Content Groups REST API v2 .
33"""
44from unittest .mock import patch
55
1111from xmodule .modulestore .tests .django_utils import ModuleStoreTestCase
1212from xmodule .modulestore .tests .factories import CourseFactory
1313from openedx .core .djangoapps .course_groups .constants import COHORT_SCHEME
14+ from openedx .core .djangolib .testing .utils import skip_unless_lms
1415
1516
17+ @skip_unless_lms
1618class GroupConfigurationsListViewTestCase (ModuleStoreTestCase ):
1719 """
18- Tests for GET /api/instructor /v2/courses/{course_id}/group_configurations
20+ Tests for GET /api/cohorts /v2/courses/{course_id}/group_configurations
1921 """
2022
2123 def setUp (self ):
@@ -28,14 +30,13 @@ def setUp(self):
2830 def _get_url (self , course_id = None ):
2931 """Helper to get the list URL"""
3032 course_id = course_id or str (self .course .id )
31- return f'/api/instructor /v2/courses/{ course_id } /group_configurations'
33+ return f'/api/cohorts /v2/courses/{ course_id } /group_configurations'
3234
3335 @patch ('lms.djangoapps.instructor.permissions.InstructorPermission.has_permission' )
3436 def test_list_content_groups_returns_json (self , mock_perm ):
3537 """Verify endpoint returns JSON with correct structure"""
3638 mock_perm .return_value = True
3739
38- # Create content groups
3940 self .course .user_partitions = [
4041 UserPartition (
4142 id = 50 ,
@@ -50,10 +51,8 @@ def test_list_content_groups_returns_json(self, mock_perm):
5051 ]
5152 self .update_course (self .course , self .user .id )
5253
53- # Get endpoint
5454 response = self .api_client .get (self ._get_url ())
5555
56- # Verify response
5756 self .assertEqual (response .status_code , status .HTTP_200_OK )
5857 self .assertEqual (response ['Content-Type' ], 'application/json' )
5958
@@ -62,7 +61,6 @@ def test_list_content_groups_returns_json(self, mock_perm):
6261 self .assertIn ('should_show_enrollment_track' , data )
6362 self .assertIn ('should_show_experiment_groups' , data )
6463
65- # Verify content groups
6664 configs = data ['all_group_configurations' ]
6765 self .assertEqual (len (configs ), 1 )
6866 self .assertEqual (configs [0 ]['scheme' ], COHORT_SCHEME )
@@ -73,7 +71,6 @@ def test_list_content_groups_filters_non_cohort_partitions(self, mock_perm):
7371 """Verify only cohort-scheme partitions are returned"""
7472 mock_perm .return_value = True
7573
76- # Create mixed partitions
7774 self .course .user_partitions = [
7875 UserPartition (
7976 id = 50 ,
@@ -87,7 +84,7 @@ def test_list_content_groups_filters_non_cohort_partitions(self, mock_perm):
8784 name = 'Experiment Groups' ,
8885 description = 'Random experiment groups' ,
8986 groups = [Group (id = 1 , name = 'Group B' )],
90- scheme_id = 'random' # Not cohort scheme
87+ scheme_id = 'random'
9188 ),
9289 ]
9390 self .update_course (self .course , self .user .id )
@@ -97,7 +94,6 @@ def test_list_content_groups_filters_non_cohort_partitions(self, mock_perm):
9794 data = response .json ()
9895 configs = data ['all_group_configurations' ]
9996
100- # Should only return cohort-scheme partition
10197 self .assertEqual (len (configs ), 1 )
10298 self .assertEqual (configs [0 ]['id' ], 50 )
10399 self .assertEqual (configs [0 ]['scheme' ], COHORT_SCHEME )
@@ -107,20 +103,18 @@ def test_list_auto_creates_empty_content_group_if_none_exists(self, mock_perm):
107103 """Verify empty content group is auto-created when none exists"""
108104 mock_perm .return_value = True
109105
110- # Don't add any partitions
111106 response = self .api_client .get (self ._get_url ())
112107
113108 data = response .json ()
114109 configs = data ['all_group_configurations' ]
115110
116- # Should have auto-created empty content group
117111 self .assertEqual (len (configs ), 1 )
118112 self .assertEqual (configs [0 ]['scheme' ], COHORT_SCHEME )
119113 self .assertEqual (len (configs [0 ]['groups' ]), 0 )
120114
121115 def test_list_requires_authentication (self ):
122116 """Verify endpoint requires authentication"""
123- client = APIClient () # Unauthenticated
117+ client = APIClient ()
124118 response = client .get (self ._get_url ())
125119 self .assertIn (response .status_code , [status .HTTP_401_UNAUTHORIZED , status .HTTP_403_FORBIDDEN ])
126120
@@ -129,14 +123,14 @@ def test_list_invalid_course_key_returns_400(self, mock_perm):
129123 """Verify invalid course key returns 400"""
130124 mock_perm .return_value = True
131125
132- # Use a course key that matches URL pattern but is invalid when parsed
133- response = self .api_client .get ('/api/instructor/v2/courses/course-v1:org/course/run/group_configurations' )
134- self .assertEqual (response .status_code , status .HTTP_400_BAD_REQUEST )
126+ response = self .api_client .get ('/api/cohorts/v2/courses/course-v1:invalid+course+key/group_configurations' )
127+ self .assertEqual (response .status_code , status .HTTP_404_NOT_FOUND )
135128
136129
130+ @skip_unless_lms
137131class GroupConfigurationDetailViewTestCase (ModuleStoreTestCase ):
138132 """
139- Tests for GET /api/instructor /v2/courses/{course_id}/group_configurations/{id}
133+ Tests for GET /api/cohorts /v2/courses/{course_id}/group_configurations/{id}
140134 """
141135
142136 def setUp (self ):
@@ -146,7 +140,6 @@ def setUp(self):
146140 self .course = CourseFactory .create ()
147141 self .api_client .force_authenticate (user = self .user )
148142
149- # Create a test configuration
150143 self .course .user_partitions = [
151144 UserPartition (
152145 id = 50 ,
@@ -163,7 +156,7 @@ def setUp(self):
163156
164157 def _get_url (self , configuration_id = 50 ):
165158 """Helper to get detail URL"""
166- return f'/api/instructor /v2/courses/{ self .course .id } /group_configurations/{ configuration_id } '
159+ return f'/api/cohorts /v2/courses/{ self .course .id } /group_configurations/{ configuration_id } '
167160
168161 @patch ('lms.djangoapps.instructor.permissions.InstructorPermission.has_permission' )
169162 def test_get_configuration_details (self , mock_perm ):
@@ -181,6 +174,7 @@ def test_get_configuration_details(self, mock_perm):
181174 self .assertEqual (len (data ['groups' ]), 2 )
182175
183176
177+ @skip_unless_lms
184178class ContentGroupsPermissionsTestCase (ModuleStoreTestCase ):
185179 """
186180 Tests for permission checking
@@ -194,7 +188,7 @@ def setUp(self):
194188
195189 def _get_url (self ):
196190 """Helper to get list URL"""
197- return f'/api/instructor /v2/courses/{ self .course .id } /group_configurations'
191+ return f'/api/cohorts /v2/courses/{ self .course .id } /group_configurations'
198192
199193 @patch ('lms.djangoapps.instructor.permissions.InstructorPermission.has_permission' )
200194 def test_staff_user_can_access (self , mock_perm ):
0 commit comments