|
3 | 3 | """ |
4 | 4 |
|
5 | 5 | import itertools |
| 6 | +import json |
6 | 7 | from datetime import datetime, timedelta, timezone |
7 | | -from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory |
8 | | -from unittest.mock import Mock, patch # lint-amnesty, pylint: disable=wrong-import-order |
| 8 | +from unittest.mock import Mock, patch |
9 | 9 |
|
10 | | -import ddt # lint-amnesty, pylint: disable=wrong-import-order |
11 | | -import json # lint-amnesty, pylint: disable=wrong-import-order |
| 10 | +import ddt |
12 | 11 | from completion.models import BlockCompletion |
13 | | -from django.conf import settings # lint-amnesty, pylint: disable=wrong-import-order |
| 12 | +from django.conf import settings |
14 | 13 | from django.test import override_settings |
15 | | -from django.urls import reverse # lint-amnesty, pylint: disable=wrong-import-order |
16 | | -from edx_toggles.toggles.testutils import override_waffle_flag # lint-amnesty, pylint: disable=wrong-import-order |
| 14 | +from django.urls import reverse |
| 15 | +from edx_toggles.toggles.testutils import override_waffle_flag |
17 | 16 |
|
18 | 17 | from cms.djangoapps.contentstore.outlines import update_outline_from_modulestore |
19 | 18 | from common.djangoapps.course_modes.models import CourseMode |
20 | 19 | from common.djangoapps.course_modes.tests.factories import CourseModeFactory |
21 | 20 | from common.djangoapps.student.models import CourseEnrollment |
22 | 21 | from common.djangoapps.student.roles import CourseInstructorRole |
23 | 22 | from common.djangoapps.student.tests.factories import UserFactory |
| 23 | +from lms.djangoapps.course_home_api.toggles import COURSE_HOME_SEND_COURSE_PROGRESS_ANALYTICS_FOR_STUDENT |
24 | 24 | from lms.djangoapps.course_home_api.tests.utils import BaseCourseHomeTests |
| 25 | +from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory |
25 | 26 | from openedx.core.djangoapps.content.course_overviews.models import CourseOverview |
26 | 27 | from openedx.core.djangoapps.content.learning_sequences.api import replace_course_outline |
27 | 28 | from openedx.core.djangoapps.content.learning_sequences.data import CourseOutlineData, CourseVisibility |
|
33 | 34 | COURSE_ENABLE_UNENROLLED_ACCESS_FLAG, |
34 | 35 | ENABLE_COURSE_GOALS |
35 | 36 | ) |
36 | | -from openedx.features.discounts.applicability import ( |
37 | | - DISCOUNT_APPLICABILITY_FLAG, |
38 | | - FIRST_PURCHASE_DISCOUNT_OVERRIDE_FLAG |
| 37 | +from openedx.features.discounts.applicability import DISCOUNT_APPLICABILITY_FLAG, FIRST_PURCHASE_DISCOUNT_OVERRIDE_FLAG |
| 38 | +from xmodule.course_block import ( |
| 39 | + COURSE_VISIBILITY_PUBLIC, |
| 40 | + COURSE_VISIBILITY_PUBLIC_OUTLINE |
| 41 | +) |
| 42 | +from xmodule.modulestore.tests.factories import ( |
| 43 | + BlockFactory, |
| 44 | + CourseFactory |
39 | 45 | ) |
40 | | -from xmodule.course_block import COURSE_VISIBILITY_PUBLIC, COURSE_VISIBILITY_PUBLIC_OUTLINE # lint-amnesty, pylint: disable=wrong-import-order |
41 | | -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order |
42 | 46 |
|
43 | 47 |
|
44 | 48 | @ddt.ddt |
@@ -461,6 +465,25 @@ def test_cannot_enroll_if_full(self): |
461 | 465 | CourseEnrollment.enroll(UserFactory(), self.course.id) # grr, some rando took our spot! |
462 | 466 | self.assert_can_enroll(False) |
463 | 467 |
|
| 468 | + @override_waffle_flag(COURSE_HOME_SEND_COURSE_PROGRESS_ANALYTICS_FOR_STUDENT, active=True) |
| 469 | + @patch("lms.djangoapps.course_home_api.outline.views.collect_progress_for_user_in_course.delay") |
| 470 | + def test_course_progress_analytics_enabled(self, mock_task): |
| 471 | + """ |
| 472 | + Ensures that the `calculate_course_progress_for_user_in_course` task is enqueued, with the correct args, only |
| 473 | + if the feature is enabled. |
| 474 | + """ |
| 475 | + self.client.get(self.url) |
| 476 | + mock_task.assert_called_once_with(str(self.course.id), self.user.id) |
| 477 | + |
| 478 | + @override_waffle_flag(COURSE_HOME_SEND_COURSE_PROGRESS_ANALYTICS_FOR_STUDENT, active=False) |
| 479 | + @patch("lms.djangoapps.course_home_api.outline.views.collect_progress_for_user_in_course.delay") |
| 480 | + def test_course_progress_analytics_disabled(self, mock_task): |
| 481 | + """ |
| 482 | + Ensures that the `calculate_course_progress_for_user_in_course` task is not run if the feature is disabled. |
| 483 | + """ |
| 484 | + self.client.get(self.url) |
| 485 | + mock_task.assert_not_called() |
| 486 | + |
464 | 487 |
|
465 | 488 | @ddt.ddt |
466 | 489 | class SidebarBlocksTestViews(BaseCourseHomeTests): |
|
0 commit comments