Unverified Commit 57bf89c8 by Tyler Hallada Committed by Gabe Mulley

Create schedule experience on schedule creation

parent 95d1e5c2
...@@ -12,6 +12,9 @@ from courseware.models import ( ...@@ -12,6 +12,9 @@ from courseware.models import (
OrgDynamicUpgradeDeadlineConfiguration OrgDynamicUpgradeDeadlineConfiguration
) )
from edx_ace.utils import date from edx_ace.utils import date
from openedx.core.djangoapps.schedules.exceptions import CourseUpdateDoesNotExist
from openedx.core.djangoapps.schedules.models import ScheduleExperience
from openedx.core.djangoapps.schedules.resolvers import get_week_highlights
from openedx.core.djangoapps.signals.signals import COURSE_START_DATE_CHANGED from openedx.core.djangoapps.signals.signals import COURSE_START_DATE_CHANGED
from openedx.core.djangoapps.theming.helpers import get_current_site from openedx.core.djangoapps.theming.helpers import get_current_site
from student.models import CourseEnrollment from student.models import CourseEnrollment
...@@ -53,14 +56,22 @@ def create_schedule(sender, **kwargs): ...@@ -53,14 +56,22 @@ def create_schedule(sender, **kwargs):
upgrade_deadline = _calculate_upgrade_deadline(enrollment.course_id, content_availability_date) upgrade_deadline = _calculate_upgrade_deadline(enrollment.course_id, content_availability_date)
Schedule.objects.create( schedule = Schedule.objects.create(
enrollment=enrollment, enrollment=enrollment,
start=content_availability_date, start=content_availability_date,
upgrade_deadline=upgrade_deadline upgrade_deadline=upgrade_deadline
) )
log.debug('Schedules: created a new schedule starting at %s with an upgrade deadline of %s', try:
content_availability_date, upgrade_deadline) get_week_highlights(enrollment.course_id, 1)
experience_type = ScheduleExperience.COURSE_UPDATES
except CourseUpdateDoesNotExist:
experience_type = ScheduleExperience.DEFAULT
ScheduleExperience(schedule=schedule, experience_type=experience_type).save()
log.debug('Schedules: created a new schedule starting at %s with an upgrade deadline of %s and experience type: %s',
content_availability_date, upgrade_deadline, ScheduleExperience.EXPERIENCES[experience_type][1])
@receiver(COURSE_START_DATE_CHANGED, dispatch_uid="update_schedules_on_course_start_changed") @receiver(COURSE_START_DATE_CHANGED, dispatch_uid="update_schedules_on_course_start_changed")
......
...@@ -6,6 +6,7 @@ from pytz import utc ...@@ -6,6 +6,7 @@ from pytz import utc
from course_modes.models import CourseMode from course_modes.models import CourseMode
from course_modes.tests.factories import CourseModeFactory from course_modes.tests.factories import CourseModeFactory
from courseware.models import DynamicUpgradeDeadlineConfiguration from courseware.models import DynamicUpgradeDeadlineConfiguration
from openedx.core.djangoapps.schedules.models import ScheduleExperience
from openedx.core.djangoapps.schedules.signals import CREATE_SCHEDULE_WAFFLE_FLAG from openedx.core.djangoapps.schedules.signals import CREATE_SCHEDULE_WAFFLE_FLAG
from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory
from openedx.core.djangoapps.waffle_utils.testutils import override_waffle_flag from openedx.core.djangoapps.waffle_utils.testutils import override_waffle_flag
...@@ -23,11 +24,12 @@ from ..tests.factories import ScheduleConfigFactory ...@@ -23,11 +24,12 @@ from ..tests.factories import ScheduleConfigFactory
@skip_unless_lms @skip_unless_lms
class CreateScheduleTests(SharedModuleStoreTestCase): class CreateScheduleTests(SharedModuleStoreTestCase):
def assert_schedule_created(self): def assert_schedule_created(self, experience_type=ScheduleExperience.DEFAULT):
course = _create_course_run(self_paced=True) course = _create_course_run(self_paced=True)
enrollment = CourseEnrollmentFactory(course_id=course.id, mode=CourseMode.AUDIT) enrollment = CourseEnrollmentFactory(course_id=course.id, mode=CourseMode.AUDIT)
self.assertIsNotNone(enrollment.schedule) self.assertIsNotNone(enrollment.schedule)
self.assertIsNone(enrollment.schedule.upgrade_deadline) self.assertIsNone(enrollment.schedule.upgrade_deadline)
self.assertEquals(enrollment.schedule.experience.experience_type, experience_type)
def assert_schedule_not_created(self): def assert_schedule_not_created(self):
course = _create_course_run(self_paced=True) course = _create_course_run(self_paced=True)
...@@ -78,6 +80,14 @@ class CreateScheduleTests(SharedModuleStoreTestCase): ...@@ -78,6 +80,14 @@ class CreateScheduleTests(SharedModuleStoreTestCase):
with self.assertRaises(Schedule.DoesNotExist): with self.assertRaises(Schedule.DoesNotExist):
enrollment.schedule enrollment.schedule
@override_waffle_flag(CREATE_SCHEDULE_WAFFLE_FLAG, True)
@patch('openedx.core.djangoapps.schedules.signals.get_week_highlights')
def test_create_schedule_course_updates_experience(self, mock_get_week_highlights, mock_get_current_site):
site = SiteFactory.create()
mock_get_week_highlights.return_value = True
mock_get_current_site.return_value = site
self.assert_schedule_created(experience_type=ScheduleExperience.COURSE_UPDATES)
@ddt.ddt @ddt.ddt
@skip_unless_lms @skip_unless_lms
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment