Commit 1ec2cf61 by Bill DeRusha Committed by Peter Fogg

Update active courses to exclude runs whose end date has passed

parent bc610a50
......@@ -28,7 +28,8 @@ class AffiliateWindowViewSetTests(ElasticsearchTestMixin, SerializationMixin, AP
self.catalog = CatalogFactory(query='*:*', viewers=[self.user])
self.enrollment_end = datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=30)
self.course_run = CourseRunFactory(enrollment_end=self.enrollment_end)
self.course_end = datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=60)
self.course_run = CourseRunFactory(enrollment_end=self.enrollment_end, end=self.course_end)
self.seat_verified = SeatFactory(course_run=self.course_run, type=Seat.VERIFIED)
self.course = self.course_run.course
......
......@@ -28,7 +28,12 @@ class CatalogViewSetTests(ElasticsearchTestMixin, SerializationMixin, OAuth2Mixi
self.client.force_authenticate(self.user)
self.catalog = CatalogFactory(query='title:abc*')
enrollment_end = datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=30)
self.course_run = CourseRunFactory(enrollment_end=enrollment_end, course__title='ABC Test Course')
course_end = datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=60)
self.course_run = CourseRunFactory(
enrollment_end=enrollment_end,
end=course_end,
course__title='ABC Test Course'
)
self.course = self.course_run.course
self.refresh_index()
......
......@@ -11,6 +11,9 @@ class CourseQuerySet(models.QuerySet):
or will be open for enrollment in the future. """
return self.filter(
Q(course_runs__enrollment_end__gt=datetime.datetime.now(pytz.UTC)) |
Q(course_runs__enrollment_end__isnull=True)
Q(course_runs__end__gt=datetime.datetime.now(pytz.UTC)) &
(
Q(course_runs__enrollment_end__gt=datetime.datetime.now(pytz.UTC)) |
Q(course_runs__enrollment_end__isnull=True)
)
)
......@@ -11,15 +11,25 @@ class CourseQuerySetTests(TestCase):
def test_active(self):
""" Verify the method filters the Courses to those with active course runs. """
# Create an active course
enrollment_end = datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=30)
active_course = CourseRunFactory(enrollment_end=enrollment_end).course
now = datetime.datetime.now(pytz.UTC)
active_course_end = now + datetime.timedelta(days=60)
inactive_course_end = now - datetime.timedelta(days=15)
open_enrollment_end = now + datetime.timedelta(days=30)
closed_enrollment_end = now - datetime.timedelta(days=30)
# Create an inactive course
enrollment_end = datetime.datetime.now(pytz.UTC) - datetime.timedelta(days=30)
CourseRunFactory(enrollment_end=enrollment_end, course__title='ABC Test Course 2')
# Create an active enrollable course
active_course = CourseRunFactory(enrollment_end=open_enrollment_end, end=active_course_end).course
# Create a course with unrestricted enrollment
course_without_end = CourseRunFactory(enrollment_end=None).course
# Create an active unenrollable course
CourseRunFactory(enrollment_end=closed_enrollment_end, end=active_course_end, course__title='ABC Test Course 2')
# Create an inactive unenrollable course
CourseRunFactory(enrollment_end=closed_enrollment_end, end=inactive_course_end)
# Create an active course with unrestricted enrollment
course_without_end = CourseRunFactory(enrollment_end=None, end=active_course_end).course
# Create an inactive course with unrestricted enrollment
CourseRunFactory(enrollment_end=None, end=inactive_course_end)
self.assertEqual(set(Course.objects.active()), {active_course, course_without_end})
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