only query due_dates for courses in progress (#23823)

This commit is contained in:
Zachary Hancock
2020-04-29 12:15:03 -04:00
committed by GitHub
parent d23393d76a
commit cb44075ace
2 changed files with 35 additions and 19 deletions

View File

@@ -1619,6 +1619,13 @@ class ProgramCourseEnrollmentOverviewGetTests(
cls.yesterday = timezone.now() - timedelta(1)
cls.tomorrow = timezone.now() + timedelta(1)
cls.modulestore_course = ModulestoreCourseFactory.create(
org="edX",
course="ToyX",
run="Toy_Course",
start=cls.yesterday,
end=cls.tomorrow,
)
cls.relative_certificate_download_url = '/download-the-certificates'
cls.absolute_certificate_download_url = 'http://www.certificates.com/'
@@ -1797,17 +1804,18 @@ class ProgramCourseEnrollmentOverviewGetTests(
self.assertEqual(status.HTTP_200_OK, response.status_code)
assert [] == response.data['course_runs'][0]['due_dates']
def test_due_dates(self):
course = ModulestoreCourseFactory.create(
org="edX",
course="ToyX",
run="Toy_Course",
)
@ddt.data(
('2018-12-01', False),
('2019-01-01', True),
('2019-01-09', False),
)
@ddt.unpack
def test_due_dates(self, now_time, course_in_progress):
section_1 = ItemFactory.create(
category='chapter',
start=self.yesterday,
due=self.tomorrow,
parent=course,
parent=self.modulestore_course,
display_name='section 1'
)
@@ -1839,7 +1847,7 @@ class ProgramCourseEnrollmentOverviewGetTests(
)
mock_path = 'lms.djangoapps.course_api.api.get_dates_for_course'
with mock.patch(mock_path) as mock_get_dates:
with mock.patch(mock_path) as mock_get_dates, freeze_time(now_time):
mock_get_dates.return_value = {
(section_1.location, 'due'): section_1.due,
(section_1.location, 'start'): section_1.start,
@@ -1880,8 +1888,11 @@ class ProgramCourseEnrollmentOverviewGetTests(
]
due_dates = response.data['course_runs'][0]['due_dates']
for block in block_data:
self.assertIn(block, due_dates)
if course_in_progress:
for block in block_data:
self.assertIn(block, due_dates)
else:
assert due_dates == []
@mock.patch.object(CourseOverview, 'has_ended')
def test_course_run_status_instructor_paced_completed(self, mock_has_ended):

View File

@@ -54,7 +54,7 @@ from student.models import CourseEnrollment
from student.roles import CourseInstructorRole, CourseStaffRole, UserBasedRole
from util.query import read_replica_or_default
from .constants import ENABLE_ENROLLMENT_RESET_FLAG, MAX_ENROLLMENT_RECORDS
from .constants import CourseRunProgressStatuses, ENABLE_ENROLLMENT_RESET_FLAG, MAX_ENROLLMENT_RECORDS
from .serializers import (
CourseRunOverviewListSerializer,
ProgramCourseEnrollmentRequestSerializer,
@@ -360,14 +360,14 @@ class ProgramEnrollmentsView(
return self.handle_write_request()
@verify_program_exists
def patch(self, request, program_uuid=None): # pylint: disable=unused-argument
def patch(self, request, program_uuid=None):
"""
Update program enrollments for a list of learners
"""
return self.handle_write_request()
@verify_program_exists
def put(self, request, program_uuid=None): # pylint: disable=unused-argument
def put(self, request, program_uuid=None):
"""
Create/update program enrollments for a list of learners
"""
@@ -508,7 +508,6 @@ class ProgramCourseEnrollmentsView(
return self.handle_write_request()
@verify_course_exists_and_in_program
# pylint: disable=unused-argument
def patch(self, request, program_uuid=None, course_id=None):
"""
Modify the program course enrollments of a list of learners
@@ -516,7 +515,6 @@ class ProgramCourseEnrollmentsView(
return self.handle_write_request()
@verify_course_exists_and_in_program
# pylint: disable=unused-argument
def put(self, request, program_uuid=None, course_id=None):
"""
Create or Update the program course enrollments of a list of learners
@@ -816,8 +814,9 @@ class ProgramCourseEnrollmentOverviewView(
if absent, the bulk email feature is either not enable at the platform
level or is not enabled for the course; if True or False, bulk email
feature is enabled, and value represents whether or not user wants
to receive emails due_dates: a list of subsection due dates for the
course run:
to receive emails
* due_dates: a list of subsection due dates for the
course run. Due dates are only returned if the course run is in progress.
** name: name of the subsection
** url: deep link to the subsection
** date: due date for the subsection
@@ -911,14 +910,20 @@ class ProgramCourseEnrollmentOverviewView(
certificate_info = get_certificate_for_user(user.username, enrollment.course_id) or {}
course_run_status = get_course_run_status(overview, certificate_info)
if course_run_status == CourseRunProgressStatuses.IN_PROGRESS:
due_dates = get_due_dates(request, enrollment.course_id, user)
else:
due_dates = []
course_run_dict = {
'course_run_id': enrollment.course_id,
'display_name': overview.display_name_with_default,
'course_run_status': get_course_run_status(overview, certificate_info),
'course_run_status': course_run_status,
'course_run_url': get_course_run_url(request, enrollment.course_id),
'start_date': overview.start,
'end_date': overview.end,
'due_dates': get_due_dates(request, enrollment.course_id, user),
'due_dates': due_dates,
}
emails_enabled = get_emails_enabled(user, enrollment.course_id)