Commit 84f26e86 by Jeff LaJoie Committed by Jeff LaJoie

LEARNER-4337: Adds in a second seat to tests, and adds check to only compare non-audit course seats

parent 76d86911
......@@ -3011,8 +3011,27 @@ class CourseEditViewTests(SiteMixin, TestCase):
factories.CourseRunStateFactory(course_run=course_run, name=CourseRunStateChoices.Published)
factories.CourseUserRoleFactory(course=self.course, role=PublisherUserRole.Publisher)
factories.CourseUserRoleFactory(course=self.course, role=PublisherUserRole.ProjectCoordinator)
seat = factories.SeatFactory.create(course_run=course_run, type=Seat.VERIFIED, price=2)
# Test that this saves without seats after resetting this to Seat version
self.course.version = Course.SEAT_VERSION
self.course.save()
post_data['mode'] = Seat.PROFESSIONAL
post_data['price'] = 1
response = self.client.post(self.edit_page_url, data=post_data)
self.assertRedirects(
response,
expected_url=reverse('publisher:publisher_course_detail', kwargs={'pk': self.course.id}),
status_code=302,
target_status_code=200
)
verified_seat = factories.SeatFactory.create(course_run=course_run, type=Seat.VERIFIED, price=2)
factories.SeatFactory(course_run=course_run, type=Seat.AUDIT, price=0) # Create a seat, do not need to access
self.course.version = Course.SEAT_VERSION
self.course.save()
post_data['mode'] = ''
post_data['price'] = ''
response = self.client.post(self.edit_page_url, data=post_data)
# Assert that this saves for a SEAT_VERSION
self.assertRedirects(
......@@ -3037,8 +3056,8 @@ class CourseEditViewTests(SiteMixin, TestCase):
self.assertEqual(response.status_code, 400)
# Modify the Course to try and create CourseEntitlement the same as the Course Run and Seat type and price
post_data['mode'] = seat.type
post_data['price'] = seat.price # just a number different than what is used in the SeatFactory constructor
post_data['mode'] = verified_seat.type
post_data['price'] = verified_seat.price
response = self.client.post(self.edit_page_url, data=post_data)
self.assertRedirects(
response,
......
......@@ -426,21 +426,36 @@ class CourseEditView(mixins.PublisherPermissionMixin, UpdateView):
return render(request, self.template_name, context)
def _get_misconfigured_couse_runs(self, course, price, mode):
def _get_misconfigured_course_runs(self, course, price, mode):
misconfigured_seat_type_runs = set()
misconfigured_price_runs = set()
for course_run in course.publisher_course_runs.filter(end__gt=datetime.now()):
for seat in course_run.seats.all():
if seat.type != mode:
misconfigured_seat_type_runs.add('{type} - {start}'.format(
type=seat.course_run.get_pacing_type_display(),
start=seat.course_run.start.strftime("%B %d, %Y")
))
if seat.price != price:
misconfigured_price_runs.add('{type} - {start}'.format(
type=seat.course_run.get_pacing_type_display(),
start=seat.course_run.start.strftime("%B %d, %Y")
))
seats = course_run.seats.all()
type_is_valid = True
price_is_valid = True
if seats:
if mode == Seat.VERIFIED:
# There should be exactly two seats, one verified and one audit
type_is_valid = {Seat.AUDIT, Seat.VERIFIED} == set(seat.type for seat in seats)
verified_seat = seats.filter(type=Seat.VERIFIED).first()
if verified_seat:
price_is_valid = verified_seat.price == price
else:
# There should be exactly one matching seat with the same type/price
type_is_valid = len(seats) == 1 and seats[0].type == mode
price_is_valid = seats[0].price == price
if not type_is_valid:
misconfigured_seat_type_runs.add('{type} - {start}'.format(
type=course_run.get_pacing_type_display(),
start=course_run.start.strftime("%B %d, %Y")
))
if not price_is_valid:
misconfigured_price_runs.add('{type} - {start}'.format(
type=course_run.get_pacing_type_display(),
start=course_run.start.strftime("%B %d, %Y")
))
return misconfigured_price_runs, misconfigured_seat_type_runs
def _create_or_update_course_entitlement(self, course, entitlement_form):
......@@ -485,7 +500,7 @@ class CourseEditView(mixins.PublisherPermissionMixin, UpdateView):
# using entitlements check that there are no misconfigured runs
if self.object.version == Course.SEAT_VERSION:
if entitlement_mode:
type_misconfigurations, seat_misconfigurations = self._get_misconfigured_couse_runs(
type_misconfigurations, seat_misconfigurations = self._get_misconfigured_course_runs(
self.object, entitlement_price, entitlement_mode
)
if type_misconfigurations:
......
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