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
003a9453
Commit
003a9453
authored
Feb 20, 2015
by
Akiva Leffert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert enrollment already exists errors to success.
JIRA:
https://openedx.atlassian.net/browse/MA-290
parent
b5b14165
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
3 deletions
+17
-3
common/djangoapps/enrollment/data.py
+2
-1
common/djangoapps/enrollment/errors.py
+5
-1
common/djangoapps/enrollment/tests/test_views.py
+5
-0
common/djangoapps/enrollment/views.py
+5
-1
No files found.
common/djangoapps/enrollment/data.py
View file @
003a9453
...
...
@@ -97,7 +97,8 @@ def create_course_enrollment(username, course_id, mode, is_active):
except
CourseFullError
as
err
:
raise
CourseEnrollmentFullError
(
err
.
message
)
except
AlreadyEnrolledError
as
err
:
raise
CourseEnrollmentExistsError
(
err
.
message
)
enrollment
=
get_course_enrollment
(
username
,
course_id
)
raise
CourseEnrollmentExistsError
(
err
.
message
,
enrollment
)
def
update_course_enrollment
(
username
,
course_id
,
mode
=
None
,
is_active
=
None
):
...
...
common/djangoapps/enrollment/errors.py
View file @
003a9453
...
...
@@ -30,7 +30,11 @@ class CourseEnrollmentFullError(CourseEnrollmentError):
class
CourseEnrollmentExistsError
(
CourseEnrollmentError
):
pass
enrollment
=
None
def
__init__
(
self
,
message
,
enrollment
):
super
(
CourseEnrollmentExistsError
,
self
)
.
__init__
(
message
)
self
.
enrollment
=
enrollment
class
CourseModeNotFoundError
(
CourseEnrollmentError
):
...
...
common/djangoapps/enrollment/tests/test_views.py
View file @
003a9453
...
...
@@ -255,6 +255,11 @@ class EnrollmentTest(ModuleStoreTestCase, APITestCase):
self
.
assertTrue
(
data
[
'is_active'
])
return
resp
def
test_enrollment_already_enrolled
(
self
):
response
=
self
.
_create_enrollment
()
repeat_response
=
self
.
_create_enrollment
()
self
.
assertEqual
(
json
.
loads
(
response
.
content
),
json
.
loads
(
repeat_response
.
content
))
def
test_get_enrollment_with_invalid_key
(
self
):
resp
=
self
.
client
.
post
(
reverse
(
'courseenrollments'
),
...
...
common/djangoapps/enrollment/views.py
View file @
003a9453
...
...
@@ -17,7 +17,9 @@ from rest_framework.views import APIView
from
opaque_keys.edx.keys
import
CourseKey
from
opaque_keys
import
InvalidKeyError
from
enrollment
import
api
from
enrollment.errors
import
CourseNotFoundError
,
CourseEnrollmentError
,
CourseModeNotFoundError
from
enrollment.errors
import
(
CourseNotFoundError
,
CourseEnrollmentError
,
CourseModeNotFoundError
,
CourseEnrollmentExistsError
)
from
embargo
import
api
as
embargo_api
from
util.authentication
import
SessionAuthenticationAllowInactiveUser
from
util.disable_rate_limit
import
can_disable_rate_limit
...
...
@@ -339,6 +341,8 @@ class EnrollmentListView(APIView):
"message"
:
u"No course '{course_id}' found for enrollment"
.
format
(
course_id
=
course_id
)
}
)
except
CourseEnrollmentExistsError
as
error
:
return
Response
(
data
=
error
.
enrollment
)
except
CourseEnrollmentError
:
return
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
,
...
...
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