Merge pull request #26409 from edx/AA-304
[AA-304] Create backend for three day streak celebration
This commit is contained in:
@@ -12,6 +12,7 @@ from django.conf import settings
|
||||
from django.test.client import RequestFactory
|
||||
from django.urls import reverse # lint-amnesty, pylint: disable=unused-import
|
||||
|
||||
from edx_toggles.toggles.testutils import override_waffle_flag
|
||||
from lms.djangoapps.certificates.api import get_certificate_url
|
||||
from lms.djangoapps.certificates.tests.factories import (
|
||||
GeneratedCertificateFactory, LinkedInAddToProfileConfigurationFactory
|
||||
@@ -19,8 +20,15 @@ from lms.djangoapps.certificates.tests.factories import (
|
||||
from lms.djangoapps.courseware.access_utils import ACCESS_DENIED, ACCESS_GRANTED
|
||||
from lms.djangoapps.courseware.tabs import ExternalLinkCourseTab
|
||||
from lms.djangoapps.courseware.tests.helpers import MasqueradeMixin
|
||||
from lms.djangoapps.courseware.toggles import (
|
||||
COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES,
|
||||
COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES_STREAK_CELEBRATION,
|
||||
REDIRECT_TO_COURSEWARE_MICROFRONTEND
|
||||
)
|
||||
from lms.djangoapps.verify_student.services import IDVerificationService
|
||||
from common.djangoapps.student.models import CourseEnrollment, CourseEnrollmentCelebration
|
||||
from common.djangoapps.student.models import (
|
||||
CourseEnrollment, CourseEnrollmentCelebration
|
||||
)
|
||||
from common.djangoapps.student.tests.factories import CourseEnrollmentCelebrationFactory, UserFactory
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase
|
||||
@@ -68,6 +76,9 @@ class BaseCoursewareTests(SharedModuleStoreTestCase):
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
@override_waffle_flag(REDIRECT_TO_COURSEWARE_MICROFRONTEND, active=True)
|
||||
@override_waffle_flag(COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES, active=True)
|
||||
@override_waffle_flag(COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES_STREAK_CELEBRATION, active=True)
|
||||
class CourseApiTestViews(BaseCoursewareTests):
|
||||
"""
|
||||
Tests for the courseware REST API
|
||||
@@ -169,6 +180,13 @@ class CourseApiTestViews(BaseCoursewareTests):
|
||||
else:
|
||||
assert not response.data['can_load_courseware']['has_access']
|
||||
|
||||
def test_streak_data_in_response(self):
|
||||
""" Test that metadata endpoint returns data for the streak celebration """
|
||||
CourseEnrollment.enroll(self.user, self.course.id, 'audit')
|
||||
response = self.client.get(self.url, content_type='application/json')
|
||||
celebrations = response.json()['celebrations']
|
||||
assert 'streak_length_to_celebrate' in celebrations
|
||||
|
||||
|
||||
class SequenceApiTestViews(BaseCoursewareTests):
|
||||
"""
|
||||
|
||||
@@ -45,7 +45,10 @@ from openedx.features.content_type_gating.models import ContentTypeGatingConfig
|
||||
from openedx.features.course_duration_limits.access import get_access_expiration_data
|
||||
from openedx.features.discounts.utils import generate_offer_data
|
||||
from common.djangoapps.student.models import (
|
||||
CourseEnrollment, CourseEnrollmentCelebration, LinkedInAddToProfileConfiguration
|
||||
CourseEnrollment,
|
||||
CourseEnrollmentCelebration,
|
||||
LinkedInAddToProfileConfiguration,
|
||||
UserCelebration
|
||||
)
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from xmodule.modulestore.search import path_to_location
|
||||
@@ -76,7 +79,7 @@ class CoursewareMeta:
|
||||
self.request.user = self.effective_user
|
||||
self.is_staff = has_access(self.effective_user, 'staff', self.overview).has_access
|
||||
self.enrollment_object = CourseEnrollment.get_enrollment(self.effective_user, self.course_key,
|
||||
select_related=['celebration'])
|
||||
select_related=['celebration', 'user__celebration'])
|
||||
|
||||
def __getattr__(self, name):
|
||||
return getattr(self.overview, name)
|
||||
@@ -202,8 +205,12 @@ class CoursewareMeta:
|
||||
"""
|
||||
Returns a list of celebrations that should be performed.
|
||||
"""
|
||||
browser_timezone = self.request.query_params.get('browser_timezone', None)
|
||||
return {
|
||||
'first_section': CourseEnrollmentCelebration.should_celebrate_first_section(self.enrollment_object),
|
||||
'streak_length_to_celebrate': UserCelebration.perform_streak_updates(
|
||||
self.effective_user, self.course_key, browser_timezone
|
||||
),
|
||||
}
|
||||
|
||||
@property
|
||||
|
||||
Reference in New Issue
Block a user