Commit f5332d1b by Clinton Blackburn Committed by Clinton Blackburn

Fixed bug in Program.enrollable_seats

This method should not care about course run start dates. That date is irrelevant to determining if a course run is enrollable.

LEARNER-1151
parent ea718364
...@@ -9,7 +9,6 @@ import pytz ...@@ -9,7 +9,6 @@ import pytz
import waffle import waffle
from django.db import models, transaction from django.db import models, transaction
from django.db.models.query_utils import Q from django.db.models.query_utils import Q
from django.utils import timezone
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django_extensions.db.fields import AutoSlugField from django_extensions.db.fields import AutoSlugField
...@@ -450,12 +449,9 @@ class CourseRun(TimeStampedModel): ...@@ -450,12 +449,9 @@ class CourseRun(TimeStampedModel):
Returns: Returns:
List of Seats List of Seats
""" """
now = timezone.now() now = datetime.datetime.now(pytz.UTC)
enrollable_seats = [] enrollable_seats = []
if self.start and self.start > now:
return enrollable_seats
if self.end and now > self.end: if self.end and now > self.end:
return enrollable_seats return enrollable_seats
......
...@@ -78,6 +78,14 @@ class CourseRunTests(TestCase): ...@@ -78,6 +78,14 @@ class CourseRunTests(TestCase):
[verified_seat, professional_seat] [verified_seat, professional_seat]
) )
# The method should not care about the course run's start date.
course_run.start = datetime.datetime.utcnow() + datetime.timedelta(days=1)
course_run.save()
self.assertEqual(
course_run.enrollable_seats([Seat.VERIFIED, Seat.PROFESSIONAL]),
[verified_seat, professional_seat]
)
def test_str(self): def test_str(self):
""" Verify casting an instance to a string returns a string containing the key and title. """ """ Verify casting an instance to a string returns a string containing the key and title. """
course_run = self.course_run course_run = self.course_run
...@@ -453,12 +461,12 @@ class ProgramTests(TestCase): ...@@ -453,12 +461,12 @@ class ProgramTests(TestCase):
return factories.ProgramFactory(type=program_type, courses=[course_run.course]) return factories.ProgramFactory(type=program_type, courses=[course_run.course])
def assert_one_click_purchase_ineligible_program(self, start=None, end=None, enrollment_start=None, def assert_one_click_purchase_ineligible_program(
enrollment_end=None, seat_type=Seat.VERIFIED, self, end=None, enrollment_start=None, enrollment_end=None, seat_type=Seat.VERIFIED,
upgrade_deadline=None, one_click_purchase_enabled=True, upgrade_deadline=None, one_click_purchase_enabled=True, excluded_course_runs=None, program_type=None
excluded_course_runs=None, program_type=None,): ):
course_run = factories.CourseRunFactory( course_run = factories.CourseRunFactory(
start=start, end=end, enrollment_start=enrollment_start, enrollment_end=enrollment_end end=end, enrollment_start=enrollment_start, enrollment_end=enrollment_end
) )
factories.SeatFactory(course_run=course_run, type=seat_type, upgrade_deadline=upgrade_deadline) factories.SeatFactory(course_run=course_run, type=seat_type, upgrade_deadline=upgrade_deadline)
program = factories.ProgramFactory( program = factories.ProgramFactory(
...@@ -515,8 +523,8 @@ class ProgramTests(TestCase): ...@@ -515,8 +523,8 @@ class ProgramTests(TestCase):
def test_one_click_purchase_ineligible(self): def test_one_click_purchase_ineligible(self):
""" Verify that program is one click purchase ineligible. """ """ Verify that program is one click purchase ineligible. """
yesterday = datetime.datetime.now() - datetime.timedelta(days=1) yesterday = datetime.datetime.utcnow() - datetime.timedelta(days=1)
tomorrow = datetime.datetime.now() + datetime.timedelta(days=1) tomorrow = datetime.datetime.utcnow() + datetime.timedelta(days=1)
verified_seat_type, __ = SeatType.objects.get_or_create(name=Seat.VERIFIED) verified_seat_type, __ = SeatType.objects.get_or_create(name=Seat.VERIFIED)
program_type = factories.ProgramTypeFactory(applicable_seat_types=[verified_seat_type]) program_type = factories.ProgramTypeFactory(applicable_seat_types=[verified_seat_type])
...@@ -552,13 +560,6 @@ class ProgramTests(TestCase): ...@@ -552,13 +560,6 @@ class ProgramTests(TestCase):
self.assertFalse(program.is_program_eligible_for_one_click_purchase) self.assertFalse(program.is_program_eligible_for_one_click_purchase)
# Program has one_click_purchase_enabled set to True, one course # Program has one_click_purchase_enabled set to True, one course
# with one course run, course run start date not passed
self.assert_one_click_purchase_ineligible_program(
start=tomorrow,
program_type=program_type,
)
# Program has one_click_purchase_enabled set to True, one course
# with one course run, course run end date passed # with one course run, course run end date passed
self.assert_one_click_purchase_ineligible_program( self.assert_one_click_purchase_ineligible_program(
end=yesterday, end=yesterday,
...@@ -722,10 +723,13 @@ class ProgramTests(TestCase): ...@@ -722,10 +723,13 @@ class ProgramTests(TestCase):
factories.SeatFactory(type='verified', currency=currency, course_run=course_run, price=10) factories.SeatFactory(type='verified', currency=currency, course_run=course_run, price=10)
day_separation = 1 day_separation = 1
now = datetime.datetime.utcnow()
for course_run in course_runs_same_course: for course_run in course_runs_same_course:
if set_all_dates or day_separation < 2: if set_all_dates or day_separation < 2:
course_run.enrollment_start = datetime.datetime.now() - datetime.timedelta(days=day_separation) date_delta = datetime.timedelta(days=day_separation)
course_run.end = datetime.datetime.now() + datetime.timedelta(weeks=day_separation) course_run.enrollment_start = now - date_delta
course_run.end = now + datetime.timedelta(weeks=day_separation)
else: else:
course_run.enrollment_start = None course_run.enrollment_start = None
course_run.end = None course_run.end = None
......
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