Fixed CourseMode Filtering Bug

Commerce code has now been updated to exclude CourseMode objects with SKU set to empty string (in addition to null).
This commit is contained in:
Clinton Blackburn
2015-03-18 10:59:21 -04:00
parent 40ae5d2e1c
commit 783fb23fe2
2 changed files with 27 additions and 10 deletions

View File

@@ -203,17 +203,10 @@ class OrdersViewTests(ModuleStoreTestCase):
# TODO Eventually we should NOT be enrolling users directly from this view.
self.assertTrue(CourseEnrollment.is_enrolled(self.user, self.course.id))
@httpretty.activate
def test_course_without_sku(self):
def _test_course_without_sku(self):
"""
If the course does NOT have a SKU, the user should be enrolled in the course (under the honor mode) and
redirected to the user dashboard.
Validates the view bypasses the E-Commerce API when the course has no CourseModes with SKUs.
"""
# Remove SKU from all course modes
for course_mode in CourseMode.objects.filter(course_id=self.course.id):
course_mode.sku = None
course_mode.save()
# Place an order
self._mock_ecommerce_api()
response = self._post_to_view()
@@ -228,6 +221,19 @@ class OrdersViewTests(ModuleStoreTestCase):
self.assertTrue(CourseEnrollment.is_enrolled(self.user, self.course.id))
self.assertIsInstance(httpretty.last_request(), HTTPrettyRequestEmpty)
@httpretty.activate
def test_course_without_sku(self):
"""
If the course does NOT have a SKU, the user should be enrolled in the course (under the honor mode) and
redirected to the user dashboard.
"""
# Remove SKU from all course modes
for course_mode in CourseMode.objects.filter(course_id=self.course.id):
course_mode.sku = None
course_mode.save()
self._test_course_without_sku()
@httpretty.activate
@override_settings(ECOMMERCE_API_URL=None, ECOMMERCE_API_SIGNING_KEY=None)
def test_no_settings(self):
@@ -245,3 +251,13 @@ class OrdersViewTests(ModuleStoreTestCase):
# Ensure that the user is not enrolled and that no calls were made to the E-Commerce API
self.assertTrue(CourseEnrollment.is_enrolled(self.user, self.course.id))
self.assertIsInstance(httpretty.last_request(), HTTPrettyRequestEmpty)
@httpretty.activate
def test_empty_sku(self):
""" If the CourseMode has an empty string for a SKU, the API should not be used. """
# Set SKU to empty string for all modes.
for course_mode in CourseMode.objects.filter(course_id=self.course.id):
course_mode.sku = ''
course_mode.save()
self._test_course_without_sku()

View File

@@ -91,7 +91,8 @@ class OrdersView(APIView):
# Default to honor mode. In the future we may expand this view to support additional modes.
mode = CourseMode.DEFAULT_MODE_SLUG
course_modes = CourseMode.objects.filter(course_id=course_key, mode_slug=mode, sku__isnull=False)
course_modes = CourseMode.objects.filter(course_id=course_key, mode_slug=mode)\
.exclude(sku__isnull=True).exclude(sku__exact='')
# If there are no course modes with SKUs, enroll the user without contacting the external API.
if not course_modes.exists():