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
f86f5998
Commit
f86f5998
authored
Jul 21, 2017
by
Brittney Exline
Committed by
GitHub
Jul 21, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15631 from open-craft/bdero/bulk-enroll-content-type
Patch the bulk_enroll request to use a form content type
parents
aecb7ea3
1990dc7f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
7 deletions
+25
-7
lms/djangoapps/bulk_enroll/tests/test_views.py
+19
-7
lms/djangoapps/bulk_enroll/views.py
+6
-0
No files found.
lms/djangoapps/bulk_enroll/tests/test_views.py
View file @
f86f5998
"""
Tests for the Bulk Enrollment views.
"""
import
ddt
import
json
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
...
...
@@ -25,6 +26,7 @@ from xmodule.modulestore.tests.factories import CourseFactory
@override_settings
(
ENABLE_BULK_ENROLLMENT_VIEW
=
True
)
@ddt.ddt
class
BulkEnrollmentTest
(
ModuleStoreTestCase
,
LoginEnrollmentTestCase
,
APITestCase
):
"""
Test the bulk enrollment endpoint
...
...
@@ -67,9 +69,13 @@ class BulkEnrollmentTest(ModuleStoreTestCase, LoginEnrollmentTestCase, APITestCa
self
.
about_path
=
'/courses/{}/about'
.
format
(
self
.
course
.
id
)
self
.
course_path
=
'/courses/{}/'
.
format
(
self
.
course
.
id
)
def
request_bulk_enroll
(
self
,
data
=
None
,
**
extra
):
def
request_bulk_enroll
(
self
,
data
=
None
,
use_json
=
False
,
**
extra
):
""" Make an authenticated request to the bulk enrollment API. """
request
=
self
.
request_factory
.
post
(
self
.
url
,
data
=
data
,
**
extra
)
content_type
=
None
if
use_json
:
content_type
=
'application/json'
data
=
json
.
dumps
(
data
)
request
=
self
.
request_factory
.
post
(
self
.
url
,
data
=
data
,
content_type
=
content_type
,
**
extra
)
force_authenticate
(
request
,
user
=
self
.
staff
)
response
=
self
.
view
(
request
)
response
.
render
()
...
...
@@ -221,14 +227,15 @@ class BulkEnrollmentTest(ModuleStoreTestCase, LoginEnrollmentTestCase, APITestCa
res_json
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
res_json
,
expected
)
def
test_enroll_with_email
(
self
):
@ddt.data
(
False
,
True
)
def
test_enroll_with_email
(
self
,
use_json
):
""" Test enrolling using a username as the identifier. """
response
=
self
.
request_bulk_enroll
({
'identifiers'
:
self
.
notenrolled_student
.
email
,
'action'
:
'enroll'
,
'email_students'
:
False
,
'courses'
:
self
.
course_key
,
})
}
,
use_json
=
use_json
)
self
.
assertEqual
(
response
.
status_code
,
200
)
# test that the user is now enrolled
...
...
@@ -274,10 +281,15 @@ class BulkEnrollmentTest(ModuleStoreTestCase, LoginEnrollmentTestCase, APITestCa
# Check the outbox
self
.
assertEqual
(
len
(
mail
.
outbox
),
0
)
def
test_unenroll
(
self
):
@ddt.data
(
False
,
True
)
def
test_unenroll
(
self
,
use_json
):
""" Test unenrolling a user. """
response
=
self
.
request_bulk_enroll
({
'identifiers'
:
self
.
enrolled_student
.
email
,
'action'
:
'unenroll'
,
'email_students'
:
False
,
'courses'
:
self
.
course_key
,
})
response
=
self
.
request_bulk_enroll
({
'identifiers'
:
self
.
enrolled_student
.
email
,
'action'
:
'unenroll'
,
'email_students'
:
False
,
'courses'
:
self
.
course_key
,
},
use_json
=
use_json
)
self
.
assertEqual
(
response
.
status_code
,
200
)
# test that the user is now unenrolled
...
...
lms/djangoapps/bulk_enroll/views.py
View file @
f86f5998
...
...
@@ -60,6 +60,12 @@ class BulkEnrollView(APIView):
def
post
(
self
,
request
):
serializer
=
BulkEnrollmentSerializer
(
data
=
request
.
data
)
if
serializer
.
is_valid
():
# Setting the content type to be form data makes Django Rest Framework v3.6.3 treat all passed JSON data as
# POST parameters. This is necessary because this request is forwarded on to the student_update_enrollment
# view, which requires all of the parameters to be passed in via POST parameters.
metadata
=
request
.
_request
.
META
# pylint: disable=protected-access
metadata
[
'CONTENT_TYPE'
]
=
'application/x-www-form-urlencoded'
response_dict
=
{
'auto_enroll'
:
serializer
.
data
.
get
(
'auto_enroll'
),
'email_students'
:
serializer
.
data
.
get
(
'email_students'
),
...
...
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