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