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
43e161f6
Unverified
Commit
43e161f6
authored
Jul 14, 2017
by
Brandon DeRosier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the BulkEnrollSerializer courses field to internally behave with strings and lists
parent
a31855c9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
3 deletions
+21
-3
lms/djangoapps/bulk_enroll/serializers.py
+4
-3
lms/djangoapps/bulk_enroll/tests/test_views.py
+17
-0
No files found.
lms/djangoapps/bulk_enroll/serializers.py
View file @
43e161f6
...
@@ -8,10 +8,11 @@ from rest_framework import serializers
...
@@ -8,10 +8,11 @@ from rest_framework import serializers
class
StringListField
(
serializers
.
ListField
):
class
StringListField
(
serializers
.
ListField
):
def
to_internal_value
(
self
,
data
):
def
to_internal_value
(
self
,
data
):
try
:
if
not
data
:
return
data
[
0
]
.
split
(
','
)
except
IndexError
:
return
[]
return
[]
if
isinstance
(
data
,
list
):
data
=
data
[
0
]
return
data
.
split
(
','
)
class
BulkEnrollmentSerializer
(
serializers
.
Serializer
):
class
BulkEnrollmentSerializer
(
serializers
.
Serializer
):
...
...
lms/djangoapps/bulk_enroll/tests/test_views.py
View file @
43e161f6
...
@@ -9,6 +9,7 @@ from django.core.urlresolvers import reverse
...
@@ -9,6 +9,7 @@ from django.core.urlresolvers import reverse
from
django.test.utils
import
override_settings
from
django.test.utils
import
override_settings
from
rest_framework.test
import
APIRequestFactory
,
APITestCase
,
force_authenticate
from
rest_framework.test
import
APIRequestFactory
,
APITestCase
,
force_authenticate
from
bulk_enroll.serializers
import
BulkEnrollmentSerializer
from
bulk_enroll.views
import
BulkEnrollView
from
bulk_enroll.views
import
BulkEnrollView
from
courseware.tests.helpers
import
LoginEnrollmentTestCase
from
courseware.tests.helpers
import
LoginEnrollmentTestCase
from
microsite_configuration
import
microsite
from
microsite_configuration
import
microsite
...
@@ -74,6 +75,22 @@ class BulkEnrollmentTest(ModuleStoreTestCase, LoginEnrollmentTestCase, APITestCa
...
@@ -74,6 +75,22 @@ class BulkEnrollmentTest(ModuleStoreTestCase, LoginEnrollmentTestCase, APITestCa
response
.
render
()
response
.
render
()
return
response
return
response
def
test_course_list_serializer
(
self
):
"""
Test that the course serializer will work when passed a string or list.
Internally, DRF passes the data into the value conversion method as a list instead of
a string, so StringListField needs to work with both.
"""
for
key
in
[
self
.
course_key
,
[
self
.
course_key
]]:
serializer
=
BulkEnrollmentSerializer
(
data
=
{
'identifiers'
:
'percivaloctavius'
,
'action'
:
'enroll'
,
'email_students'
:
False
,
'courses'
:
key
,
})
self
.
assertTrue
(
serializer
.
is_valid
())
def
test_non_staff
(
self
):
def
test_non_staff
(
self
):
""" Test that non global staff users are forbidden from API use. """
""" Test that non global staff users are forbidden from API use. """
self
.
staff
.
is_staff
=
False
self
.
staff
.
is_staff
=
False
...
...
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