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
edc37a04
Commit
edc37a04
authored
Jan 30, 2015
by
Will Daly
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6816 from edx/aamir-khan/ECOM-763-invalidkeyerror
Aamir khan/ecom 763 invalidkeyerror
parents
704fd112
f3bf66c1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
1 deletions
+45
-1
common/djangoapps/enrollment/tests/test_views.py
+14
-0
common/djangoapps/enrollment/views.py
+8
-0
openedx/core/djangoapps/user_api/tests/test_views.py
+14
-0
openedx/core/djangoapps/user_api/views.py
+9
-1
No files found.
common/djangoapps/enrollment/tests/test_views.py
View file @
edc37a04
...
...
@@ -236,3 +236,17 @@ class EnrollmentTest(ModuleStoreTestCase, APITestCase):
self
.
assertEqual
(
'honor'
,
data
[
'mode'
])
self
.
assertTrue
(
data
[
'is_active'
])
return
resp
def
test_get_enrollment_with_invalid_key
(
self
):
resp
=
self
.
client
.
post
(
reverse
(
'courseenrollments'
),
{
'course_details'
:
{
'course_id'
:
'invalidcourse'
},
'user'
:
self
.
user
.
username
},
format
=
'json'
)
self
.
assertEqual
(
resp
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertIn
(
"No course "
,
resp
.
content
)
common/djangoapps/enrollment/views.py
View file @
edc37a04
...
...
@@ -3,6 +3,7 @@ The Enrollment API Views should be simple, lean HTTP endpoints for API access. T
consist primarily of authentication, request validation, and serialization.
"""
from
opaque_keys
import
InvalidKeyError
from
rest_framework
import
status
from
rest_framework.authentication
import
OAuth2Authentication
from
rest_framework
import
permissions
...
...
@@ -304,3 +305,10 @@ class EnrollmentListView(APIView):
)
.
format
(
user
=
user
,
course_id
=
course_id
)
}
)
except
InvalidKeyError
:
return
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
,
data
=
{
"message"
:
u"No course '{course_id}' found for enrollment"
.
format
(
course_id
=
course_id
)
}
)
openedx/core/djangoapps/user_api/tests/test_views.py
View file @
edc37a04
...
...
@@ -1533,3 +1533,17 @@ class UpdateEmailOptInTestCase(ApiTestCase):
user
=
self
.
user
,
org
=
self
.
course
.
id
.
org
,
key
=
"email-optin"
)
self
.
assertEquals
(
preference
.
value
,
u"True"
)
def
test_update_email_opt_with_invalid_course_key
(
self
):
"""
Test that with invalid key it returns bad request
and not update their email optin preference.
"""
response
=
self
.
client
.
post
(
self
.
url
,
{
"course_id"
:
'invalid'
,
"email_opt_in"
:
u"True"
})
self
.
assertHttpBadRequest
(
response
)
with
self
.
assertRaises
(
UserOrgTag
.
DoesNotExist
):
UserOrgTag
.
objects
.
get
(
user
=
self
.
user
,
org
=
self
.
course
.
id
.
org
,
key
=
"email-optin"
)
openedx/core/djangoapps/user_api/views.py
View file @
edc37a04
"""HTTP end-points for the User API. """
import
copy
from
opaque_keys
import
InvalidKeyError
import
third_party_auth
from
django.conf
import
settings
...
...
@@ -862,7 +863,14 @@ class UpdateEmailOptInPreference(APIView):
"""
course_id
=
request
.
DATA
[
'course_id'
]
org
=
locator
.
CourseLocator
.
from_string
(
course_id
)
.
org
try
:
org
=
locator
.
CourseLocator
.
from_string
(
course_id
)
.
org
except
InvalidKeyError
:
return
HttpResponse
(
status
=
400
,
content
=
"No course '{course_id}' found"
.
format
(
course_id
=
course_id
),
content_type
=
"text/plain"
)
# Only check for true. All other values are False.
email_opt_in
=
request
.
DATA
[
'email_opt_in'
]
.
lower
()
==
'true'
profile_api
.
update_email_opt_in
(
request
.
user
,
org
,
email_opt_in
)
...
...
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