Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
dad67cb9
Commit
dad67cb9
authored
Aug 22, 2013
by
Jason Bau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change error HTTP response codes to 400 where appropriate
parent
a0948668
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
5 deletions
+6
-5
lms/djangoapps/shoppingcart/tests/test_views.py
+2
-2
lms/djangoapps/shoppingcart/views.py
+4
-3
No files found.
lms/djangoapps/shoppingcart/tests/test_views.py
View file @
dad67cb9
...
...
@@ -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
,
40
4
)
self
.
assertEqual
(
resp
.
status_code
,
40
0
)
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
,
40
4
)
self
.
assertEqual
(
resp
.
status_code
,
40
0
)
self
.
assertIn
(
_
(
'You are already registered in course {0}.'
.
format
(
self
.
course_id
)),
resp
.
content
)
def
test_add_nonexistent_course_to_cart
(
self
):
...
...
lms/djangoapps/shoppingcart/views.py
View file @
dad67cb9
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
HttpResponse
NotFound
(
_
(
'The course {0} is already in your cart.'
.
format
(
course_id
)))
return
HttpResponse
BadRequest
(
_
(
'The course {0} is already in your cart.'
.
format
(
course_id
)))
if
CourseEnrollment
.
is_enrolled
(
user
=
request
.
user
,
course_id
=
course_id
):
return
HttpResponse
NotFound
(
_
(
'You are already registered in course {0}.'
.
format
(
course_id
)))
return
HttpResponse
BadRequest
(
_
(
'You are already registered in course {0}.'
.
format
(
course_id
)))
try
:
PaidCourseRegistration
.
add_to_order
(
cart
,
course_id
)
except
ItemNotFoundError
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment