|
10 | 10 | from django.urls import reverse_lazy |
11 | 11 | from enterprise.models import EnterpriseCourseEnrollment |
12 | 12 |
|
| 13 | +from common.djangoapps.student.models import CourseEnrollment |
13 | 14 | from common.djangoapps.student.tests.factories import ( |
14 | 15 | CourseEnrollmentFactory, |
15 | 16 | UserFactory, |
@@ -144,7 +145,7 @@ def test_404_if_no_program_data(self, mock_get_programs, _mock_get_pathways): |
144 | 145 |
|
145 | 146 |
|
146 | 147 | @skip_unless_lms |
147 | | -class TestProgramsView(SharedModuleStoreTestCase, ProgramCacheMixin): |
| 148 | +class TestProgramsEnterpriseView(SharedModuleStoreTestCase, ProgramCacheMixin): |
148 | 149 | """Unit tests for the program details page.""" |
149 | 150 |
|
150 | 151 | enterprise_uuid = str(uuid4()) |
@@ -196,7 +197,7 @@ def setUp(self): |
196 | 197 | @with_site_configuration(configuration={"COURSE_CATALOG_API_URL": "foo"}) |
197 | 198 | @override_settings(FEATURES=dict(ENABLE_ENTERPRISE_INTEGRATION=True)) |
198 | 199 | @enterprise_is_enabled() |
199 | | - def test_program_list(self): |
| 200 | + def test_program_list_enterprise(self): |
200 | 201 | """ |
201 | 202 | Verify API returns proper response. |
202 | 203 | """ |
@@ -243,3 +244,92 @@ def test_program_empty_list_if_no_enterprise_enrollments(self): |
243 | 244 | response = self.client.get(self.url) |
244 | 245 | self.assertEqual(response.status_code, 200) |
245 | 246 | self.assertEqual(response.data, []) |
| 247 | + |
| 248 | + |
| 249 | +@skip_unless_lms |
| 250 | +class TestProgramsB2CView(SharedModuleStoreTestCase, ProgramCacheMixin): |
| 251 | + """Unit tests for the program details page.""" |
| 252 | + |
| 253 | + program_uuid = str(uuid4()) |
| 254 | + url = reverse_lazy("openedx.core.djangoapps.programs:v0:program_list_b2c") |
| 255 | + |
| 256 | + @classmethod |
| 257 | + def setUpClass(cls): |
| 258 | + super().setUpClass() |
| 259 | + |
| 260 | + cls.user = UserFactory() |
| 261 | + modulestore_course = ModuleStoreCourseFactory() |
| 262 | + course_run = CourseRunFactory(key=str(modulestore_course.id)) |
| 263 | + course = CourseFactory(course_runs=[course_run]) |
| 264 | + |
| 265 | + CourseEnrollmentFactory(is_active=True, course_id=modulestore_course.id, user=cls.user) |
| 266 | + |
| 267 | + cls.program = ProgramFactory( |
| 268 | + uuid=cls.program_uuid, |
| 269 | + courses=[course], |
| 270 | + title="Journey to cooking", |
| 271 | + type="MicroMasters", |
| 272 | + authoring_organizations=[ |
| 273 | + { |
| 274 | + "key": "MAX", |
| 275 | + "logo_image_url": "http://test.org/media/organization/logos/test-logo.png", |
| 276 | + } |
| 277 | + ], |
| 278 | + ) |
| 279 | + cls.site = SiteFactory(domain="test.localhost") |
| 280 | + |
| 281 | + def setUp(self): |
| 282 | + super().setUp() |
| 283 | + self.client.login(username=self.user.username, password=self.TEST_PASSWORD) |
| 284 | + self.set_program_in_catalog_cache(self.program_uuid, self.program) |
| 285 | + ProgramEnrollmentFactory.create( |
| 286 | + user=self.user, |
| 287 | + program_uuid=self.program_uuid, |
| 288 | + external_user_key="0001", |
| 289 | + ) |
| 290 | + |
| 291 | + @with_site_configuration(configuration={"COURSE_CATALOG_API_URL": "foo"}) |
| 292 | + def test_program_list_b2c(self): |
| 293 | + """ |
| 294 | + Verify API returns proper response. |
| 295 | + """ |
| 296 | + cache.set( |
| 297 | + SITE_PROGRAM_UUIDS_CACHE_KEY_TPL.format(domain=self.site.domain), |
| 298 | + [self.program_uuid], |
| 299 | + None, |
| 300 | + ) |
| 301 | + |
| 302 | + response = self.client.get(self.url) |
| 303 | + self.assertEqual(response.status_code, 200) |
| 304 | + program = response.data[0] |
| 305 | + |
| 306 | + assert len(program) |
| 307 | + assert program["uuid"] == self.program["uuid"] |
| 308 | + assert program["title"] == self.program["title"] |
| 309 | + assert program["type"] == self.program["type"] |
| 310 | + assert program["authoring_organizations"] == self.program["authoring_organizations"] |
| 311 | + assert program["banner_image"] == self.program["banner_image"] |
| 312 | + assert program["progress"] == { |
| 313 | + "uuid": self.program["uuid"], |
| 314 | + "completed": 0, |
| 315 | + "in_progress": 0, |
| 316 | + "not_started": 1, |
| 317 | + "all_unenrolled": False, |
| 318 | + } |
| 319 | + |
| 320 | + @with_site_configuration(configuration={"COURSE_CATALOG_API_URL": "foo"}) |
| 321 | + def test_program_empty_list_if_no_enrollments(self): |
| 322 | + """ |
| 323 | + Verify API returns empty response if no enrollments exists for a learner. |
| 324 | + """ |
| 325 | + CourseEnrollment.objects.filter(user=self.user).delete() |
| 326 | + |
| 327 | + cache.set( |
| 328 | + SITE_PROGRAM_UUIDS_CACHE_KEY_TPL.format(domain=self.site.domain), |
| 329 | + [self.program_uuid], |
| 330 | + None, |
| 331 | + ) |
| 332 | + |
| 333 | + response = self.client.get(self.url) |
| 334 | + self.assertEqual(response.status_code, 200) |
| 335 | + self.assertEqual(response.data, []) |
0 commit comments