33"""
44from unittest .mock import patch
55
6+ from django .test import override_settings
67from rest_framework import status
78from rest_framework .test import APIClient
89
9- from xmodule .partitions .partitions import Group , UserPartition
1010from common .djangoapps .student .tests .factories import UserFactory
11- from xmodule .modulestore .tests .django_utils import ModuleStoreTestCase
12- from xmodule .modulestore .tests .factories import CourseFactory
1311from openedx .core .djangoapps .course_groups .constants import COHORT_SCHEME
1412from openedx .core .djangolib .testing .utils import skip_unless_lms
13+ from xmodule .modulestore .tests .django_utils import ModuleStoreTestCase
14+ from xmodule .modulestore .tests .factories import CourseFactory
15+ from xmodule .partitions .partitions import Group , UserPartition
16+
17+ TEST_STUDIO_BASE_URL = "https://studio.example.com"
1518
1619
1720@skip_unless_lms
@@ -28,10 +31,16 @@ def setUp(self):
2831 self .api_client .force_authenticate (user = self .user )
2932
3033 def _get_url (self , course_id = None ):
31- """Helper to get the list URL"""
34+ """Helper to get the API URL"""
3235 course_id = course_id or str (self .course .id )
3336 return f'/api/cohorts/v2/courses/{ course_id } /group_configurations'
3437
38+ def _get_expected_studio_url (self , course_id = None ):
39+ """Helper to get the expected Studio URL"""
40+ course_id = course_id or str (self .course .id )
41+ return f'{ TEST_STUDIO_BASE_URL } /course/{ course_id } /group_configurations'
42+
43+ @override_settings (MFE_CONFIG = {"STUDIO_BASE_URL" : TEST_STUDIO_BASE_URL })
3544 @patch ('lms.djangoapps.instructor.permissions.InstructorPermission.has_permission' )
3645 def test_list_content_groups_returns_json (self , mock_perm ):
3746 """Verify endpoint returns JSON with correct structure"""
@@ -57,18 +66,26 @@ def test_list_content_groups_returns_json(self, mock_perm):
5766 self .assertEqual (response ['Content-Type' ], 'application/json' )
5867
5968 data = response .json ()
60- self .assertIn ('all_group_configurations' , data )
61- self .assertIn ('should_show_enrollment_track' , data )
62- self .assertIn ('should_show_experiment_groups' , data )
69+ self .assertIn ('id' , data )
70+ self .assertIn ('groups' , data )
71+ self .assertIn ('studio_content_groups_link' , data )
72+
73+ # Verify partition ID is returned
74+ self .assertEqual (data ['id' ], 50 )
75+
76+ # Verify groups
77+ groups = data ['groups' ]
78+ self .assertEqual (len (groups ), 2 )
79+ self .assertEqual (groups [0 ]['name' ], 'Content Group A' )
80+ self .assertEqual (groups [1 ]['name' ], 'Content Group B' )
6381
64- configs = data ['all_group_configurations' ]
65- self .assertEqual (len (configs ), 1 )
66- self .assertEqual (configs [0 ]['scheme' ], COHORT_SCHEME )
67- self .assertEqual (len (configs [0 ]['groups' ]), 2 )
82+ # Verify full Studio URL
83+ expected_studio_url = self ._get_expected_studio_url ()
84+ self .assertEqual (data ['studio_content_groups_link' ], expected_studio_url )
6885
6986 @patch ('lms.djangoapps.instructor.permissions.InstructorPermission.has_permission' )
7087 def test_list_content_groups_filters_non_cohort_partitions (self , mock_perm ):
71- """Verify only cohort-scheme partitions are returned"""
88+ """Verify only groups from cohort-scheme partitions are returned"""
7289 mock_perm .return_value = True
7390
7491 self .course .user_partitions = [
@@ -92,25 +109,32 @@ def test_list_content_groups_filters_non_cohort_partitions(self, mock_perm):
92109 response = self .api_client .get (self ._get_url ())
93110
94111 data = response .json ()
95- configs = data ['all_group_configurations' ]
96112
97- self .assertEqual (len (configs ), 1 )
98- self .assertEqual (configs [0 ]['id' ], 50 )
99- self .assertEqual (configs [0 ]['scheme' ], COHORT_SCHEME )
113+ # Verify cohort partition ID is returned
114+ self .assertEqual (data ['id' ], 50 )
115+
116+ # Only groups from cohort partition should be returned
117+ groups = data ['groups' ]
118+ self .assertEqual (len (groups ), 1 )
119+ self .assertEqual (groups [0 ]['name' ], 'Group A' )
100120
121+ @override_settings (MFE_CONFIG = {"STUDIO_BASE_URL" : TEST_STUDIO_BASE_URL })
101122 @patch ('lms.djangoapps.instructor.permissions.InstructorPermission.has_permission' )
102- def test_list_auto_creates_empty_content_group_if_none_exists (self , mock_perm ):
103- """Verify empty content group is auto-created when none exists """
123+ def test_list_returns_empty_groups_when_none_exist (self , mock_perm ):
124+ """Verify empty groups array and null id when no content groups exist """
104125 mock_perm .return_value = True
105126
106127 response = self .api_client .get (self ._get_url ())
107128
108129 data = response .json ()
109- configs = data ['all_group_configurations' ]
110130
111- self .assertEqual (len (configs ), 1 )
112- self .assertEqual (configs [0 ]['scheme' ], COHORT_SCHEME )
113- self .assertEqual (len (configs [0 ]['groups' ]), 0 )
131+ # ID should be null when no partition exists
132+ self .assertIsNone (data ['id' ])
133+ self .assertEqual (len (data ['groups' ]), 0 )
134+
135+ # Verify full Studio URL
136+ expected_studio_url = self ._get_expected_studio_url ()
137+ self .assertEqual (data ['studio_content_groups_link' ], expected_studio_url )
114138
115139 def test_list_requires_authentication (self ):
116140 """Verify endpoint requires authentication"""
0 commit comments