-
Notifications
You must be signed in to change notification settings - Fork 4.2k
feat: add Waffle Flag to disable resetting self-paced deadlines by learners #32148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Agrendalath
merged 1 commit into
openedx:master
from
open-craft:agrendalath/enforce_relative_dates
May 4, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,18 +2,20 @@ | |
| Tests for reset deadlines endpoint. | ||
| """ | ||
| import datetime | ||
| import ddt | ||
|
|
||
| import ddt | ||
| from django.urls import reverse | ||
| from django.utils import timezone | ||
| from edx_toggles.toggles.testutils import override_waffle_flag | ||
|
|
||
| from common.djangoapps.course_modes.models import CourseMode | ||
| from common.djangoapps.student.models import CourseEnrollment | ||
| from common.djangoapps.util.testing import EventTestMixin | ||
| from lms.djangoapps.courseware.tests.helpers import MasqueradeMixin | ||
| from lms.djangoapps.course_home_api.tests.utils import BaseCourseHomeTests | ||
| from lms.djangoapps.courseware.tests.helpers import MasqueradeMixin | ||
| from openedx.core.djangoapps.schedules.models import Schedule | ||
| from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order | ||
| from openedx.features.course_experience import RELATIVE_DATES_DISABLE_RESET_FLAG, RELATIVE_DATES_FLAG | ||
| from xmodule.modulestore.tests.factories import CourseFactory | ||
|
|
||
|
|
||
| @ddt.ddt | ||
|
|
@@ -25,17 +27,22 @@ def setUp(self): # pylint: disable=arguments-differ | |
| # Need to supply tracker name for the EventTestMixin. Also, EventTestMixin needs to come | ||
| # first in class inheritance so the setUp call here appropriately works | ||
| super().setUp('openedx.features.course_experience.api.v1.views.tracker') | ||
| self.course = CourseFactory.create(self_paced=True, start=timezone.now() - datetime.timedelta(days=1000)) | ||
|
|
||
| def test_reset_deadlines(self): | ||
| CourseEnrollment.enroll(self.user, self.course.id, CourseMode.VERIFIED) | ||
| enrollment = CourseEnrollment.enroll(self.user, self.course.id, CourseMode.VERIFIED) | ||
| enrollment.schedule.start_date = timezone.now() - datetime.timedelta(days=100) | ||
| enrollment.schedule.save() | ||
| # Test body with incorrect body param (course_key is required) | ||
| response = self.client.post(reverse('course-experience-reset-course-deadlines'), {'course': self.course.id}) | ||
| assert response.status_code == 400 | ||
| assert enrollment.schedule == Schedule.objects.get(id=enrollment.schedule.id) | ||
| self.assert_no_events_were_emitted() | ||
|
|
||
| # Test correct post body | ||
| response = self.client.post(reverse('course-experience-reset-course-deadlines'), {'course_key': self.course.id}) | ||
| assert response.status_code == 200 | ||
| assert enrollment.schedule.start_date < Schedule.objects.get(id=enrollment.schedule.id).start_date | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test wasn't working correctly before. The course wasn't self-paced, so the schedule was never modified. |
||
| self.assert_event_emitted( | ||
| 'edx.ui.lms.reset_deadlines.clicked', | ||
| courserun_key=str(self.course.id), | ||
|
|
@@ -45,33 +52,44 @@ def test_reset_deadlines(self): | |
| user_id=self.user.id, | ||
| ) | ||
|
|
||
| @override_waffle_flag(RELATIVE_DATES_FLAG, active=True) | ||
| @override_waffle_flag(RELATIVE_DATES_DISABLE_RESET_FLAG, active=True) | ||
| def test_reset_deadlines_disabled(self): | ||
| enrollment = CourseEnrollment.enroll(self.user, self.course.id, CourseMode.VERIFIED) | ||
| enrollment.schedule.start_date = timezone.now() - datetime.timedelta(days=100) | ||
| enrollment.schedule.save() | ||
|
|
||
| response = self.client.post(reverse('course-experience-reset-course-deadlines'), {'course_key': self.course.id}) | ||
| assert response.status_code == 200 | ||
| assert enrollment.schedule == Schedule.objects.get(id=enrollment.schedule.id) | ||
| self.assert_no_events_were_emitted() | ||
|
|
||
| def test_reset_deadlines_with_masquerade(self): | ||
| """ Staff users should be able to masquerade as a learner and reset the learner's schedule """ | ||
| course = CourseFactory.create(self_paced=True, start=timezone.now() - datetime.timedelta(days=1)) | ||
| student_username = self.user.username | ||
| student_user_id = self.user.id | ||
| student_enrollment = CourseEnrollment.enroll(self.user, course.id) | ||
| student_enrollment = CourseEnrollment.enroll(self.user, self.course.id) | ||
| student_enrollment.schedule.start_date = timezone.now() - datetime.timedelta(days=100) | ||
| student_enrollment.schedule.save() | ||
|
|
||
| staff_enrollment = CourseEnrollment.enroll(self.staff_user, course.id) | ||
| staff_enrollment = CourseEnrollment.enroll(self.staff_user, self.course.id) | ||
| staff_enrollment.schedule.start_date = timezone.now() - datetime.timedelta(days=30) | ||
| staff_enrollment.schedule.save() | ||
|
|
||
| self.switch_to_staff() | ||
| self.update_masquerade(course=course, username=student_username) | ||
| self.update_masquerade(course=self.course, username=student_username) | ||
|
|
||
| self.client.post(reverse('course-experience-reset-course-deadlines'), {'course_key': course.id}) | ||
| self.client.post(reverse('course-experience-reset-course-deadlines'), {'course_key': self.course.id}) | ||
| updated_schedule = Schedule.objects.get(id=student_enrollment.schedule.id) | ||
| assert updated_schedule.start_date.date() == datetime.datetime.today().date() | ||
| updated_staff_schedule = Schedule.objects.get(id=staff_enrollment.schedule.id) | ||
| assert updated_staff_schedule.start_date == staff_enrollment.schedule.start_date | ||
| self.assert_event_emitted( | ||
| 'edx.ui.lms.reset_deadlines.clicked', | ||
| courserun_key=str(course.id), | ||
| courserun_key=str(self.course.id), | ||
| is_masquerading=True, | ||
| is_staff=False, | ||
| org_key=course.org, | ||
| org_key=self.course.org, | ||
| user_id=student_user_id, | ||
| ) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed days to
1000because of this check.