Commit dad67cb9 by Jason Bau

change error HTTP response codes to 400 where appropriate

parent a0948668
...@@ -63,14 +63,14 @@ class ShoppingCartViewsTests(ModuleStoreTestCase): ...@@ -63,14 +63,14 @@ class ShoppingCartViewsTests(ModuleStoreTestCase):
PaidCourseRegistration.add_to_order(self.cart, self.course_id) PaidCourseRegistration.add_to_order(self.cart, self.course_id)
self.login_user() self.login_user()
resp = self.client.post(reverse('shoppingcart.views.add_course_to_cart', args=[self.course_id])) resp = self.client.post(reverse('shoppingcart.views.add_course_to_cart', args=[self.course_id]))
self.assertEqual(resp.status_code, 404) self.assertEqual(resp.status_code, 400)
self.assertIn(_('The course {0} is already in your cart.'.format(self.course_id)), resp.content) self.assertIn(_('The course {0} is already in your cart.'.format(self.course_id)), resp.content)
def test_add_course_to_cart_already_registered(self): def test_add_course_to_cart_already_registered(self):
CourseEnrollment.enroll(self.user, self.course_id) CourseEnrollment.enroll(self.user, self.course_id)
self.login_user() self.login_user()
resp = self.client.post(reverse('shoppingcart.views.add_course_to_cart', args=[self.course_id])) resp = self.client.post(reverse('shoppingcart.views.add_course_to_cart', args=[self.course_id]))
self.assertEqual(resp.status_code, 404) self.assertEqual(resp.status_code, 400)
self.assertIn(_('You are already registered in course {0}.'.format(self.course_id)), resp.content) self.assertIn(_('You are already registered in course {0}.'.format(self.course_id)), resp.content)
def test_add_nonexistent_course_to_cart(self): def test_add_nonexistent_course_to_cart(self):
......
import logging import logging
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound, HttpResponseForbidden, Http404 from django.http import (HttpResponse, HttpResponseRedirect, HttpResponseNotFound,
HttpResponseBadRequest, HttpResponseForbidden, Http404)
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.views.decorators.http import require_POST from django.views.decorators.http import require_POST
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
...@@ -19,9 +20,9 @@ def add_course_to_cart(request, course_id): ...@@ -19,9 +20,9 @@ def add_course_to_cart(request, course_id):
return HttpResponseForbidden(_('You must be logged-in to add to a shopping cart')) return HttpResponseForbidden(_('You must be logged-in to add to a shopping cart'))
cart = Order.get_cart_for_user(request.user) cart = Order.get_cart_for_user(request.user)
if PaidCourseRegistration.part_of_order(cart, course_id): if PaidCourseRegistration.part_of_order(cart, course_id):
return HttpResponseNotFound(_('The course {0} is already in your cart.'.format(course_id))) return HttpResponseBadRequest(_('The course {0} is already in your cart.'.format(course_id)))
if CourseEnrollment.is_enrolled(user=request.user, course_id=course_id): if CourseEnrollment.is_enrolled(user=request.user, course_id=course_id):
return HttpResponseNotFound(_('You are already registered in course {0}.'.format(course_id))) return HttpResponseBadRequest(_('You are already registered in course {0}.'.format(course_id)))
try: try:
PaidCourseRegistration.add_to_order(cart, course_id) PaidCourseRegistration.add_to_order(cart, course_id)
except ItemNotFoundError: except ItemNotFoundError:
......
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