Commit 7a0d9dd7 by tasawernawaz

query updated in CourseQuerySet to get courses with course run end date is NULL

ECOM-6168
parent 1efa3602
...@@ -12,11 +12,13 @@ class CourseQuerySet(models.QuerySet): ...@@ -12,11 +12,13 @@ class CourseQuerySet(models.QuerySet):
""" Filters Courses to those with CourseRuns that are either currently open for enrollment, """ Filters Courses to those with CourseRuns that are either currently open for enrollment,
or will be open for enrollment in the future. """ or will be open for enrollment in the future. """
now = datetime.datetime.now(pytz.UTC)
return self.filter( return self.filter(
Q(course_runs__end__gt=datetime.datetime.now(pytz.UTC)) &
( (
Q(course_runs__enrollment_end__gt=datetime.datetime.now(pytz.UTC)) | Q(course_runs__end__gt=now) | Q(course_runs__end__isnull=True)
Q(course_runs__enrollment_end__isnull=True) ) &
(
Q(course_runs__enrollment_end__gt=now) | Q(course_runs__enrollment_end__isnull=True)
) )
) )
......
...@@ -28,12 +28,18 @@ class CourseQuerySetTests(TestCase): ...@@ -28,12 +28,18 @@ class CourseQuerySetTests(TestCase):
CourseRunFactory(enrollment_end=closed_enrollment_end, end=inactive_course_end) CourseRunFactory(enrollment_end=closed_enrollment_end, end=inactive_course_end)
# Create an active course with unrestricted enrollment # Create an active course with unrestricted enrollment
course_without_end = CourseRunFactory(enrollment_end=None, end=active_course_end).course course_without_enrollment_end = CourseRunFactory(enrollment_end=None, end=active_course_end).course
# Create an inactive course with unrestricted enrollment # Create an inactive course with unrestricted enrollment
CourseRunFactory(enrollment_end=None, end=inactive_course_end) CourseRunFactory(enrollment_end=None, end=inactive_course_end)
self.assertEqual(set(Course.objects.active()), {active_course, course_without_end}) # Create course with end date is NULL
course_without_end = CourseRunFactory(enrollment_end=open_enrollment_end, end=None).course
self.assertEqual(
set(Course.objects.active()),
{active_course, course_without_enrollment_end, course_without_end}
)
@ddt.ddt @ddt.ddt
......
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