change error HTTP response codes to 400 where appropriate

This commit is contained in:
Jason Bau
2013-08-22 10:43:10 -07:00
parent a0948668f4
commit dad67cb90a
2 changed files with 6 additions and 5 deletions

View File

@@ -63,14 +63,14 @@ class ShoppingCartViewsTests(ModuleStoreTestCase):
PaidCourseRegistration.add_to_order(self.cart, self.course_id)
self.login_user()
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)
def test_add_course_to_cart_already_registered(self):
CourseEnrollment.enroll(self.user, self.course_id)
self.login_user()
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)
def test_add_nonexistent_course_to_cart(self):

View File

@@ -1,5 +1,6 @@
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.views.decorators.http import require_POST
from django.core.urlresolvers import reverse
@@ -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'))
cart = Order.get_cart_for_user(request.user)
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):
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:
PaidCourseRegistration.add_to_order(cart, course_id)
except ItemNotFoundError: