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
dc90736b
Commit
dc90736b
authored
Jul 25, 2013
by
Greg Price
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow user id filtering in user preference API
parent
6418a1cf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
1 deletions
+21
-1
lms/djangoapps/user_api/tests/test_views.py
+20
-0
lms/djangoapps/user_api/views.py
+1
-1
No files found.
lms/djangoapps/user_api/tests/test_views.py
View file @
dc90736b
...
...
@@ -262,6 +262,26 @@ class UserPreferenceViewSetTest(UserApiTestCase):
self
.
assertPrefIsValid
(
pref
)
self
.
assertEqual
(
pref
[
"key"
],
"key0"
)
def
test_get_list_filter_user_empty
(
self
):
def
test_id
(
user_id
):
result
=
self
.
get_json
(
self
.
LIST_URI
,
data
=
{
"user"
:
user_id
})
self
.
assertEqual
(
result
[
"count"
],
0
)
self
.
assertEqual
(
result
[
"results"
],
[])
test_id
(
self
.
users
[
2
]
.
id
)
# TODO: If the given id does not match a user, then the filter is a no-op
# test_id(42)
# test_id("asdf")
def
test_get_list_filter_user_nonempty
(
self
):
user_id
=
self
.
users
[
0
]
.
id
result
=
self
.
get_json
(
self
.
LIST_URI
,
data
=
{
"user"
:
user_id
})
self
.
assertEqual
(
result
[
"count"
],
2
)
prefs
=
result
[
"results"
]
self
.
assertEqual
(
len
(
prefs
),
2
)
for
pref
in
prefs
:
self
.
assertPrefIsValid
(
pref
)
self
.
assertEqual
(
pref
[
"user"
][
"id"
],
user_id
)
def
test_get_list_pagination
(
self
):
first_page
=
self
.
get_json
(
self
.
LIST_URI
,
data
=
{
"page_size"
:
2
})
self
.
assertEqual
(
first_page
[
"count"
],
3
)
...
...
lms/djangoapps/user_api/views.py
View file @
dc90736b
...
...
@@ -36,7 +36,7 @@ class UserPreferenceViewSet(viewsets.ReadOnlyModelViewSet):
permission_classes
=
(
ApiKeyHeaderPermission
,)
queryset
=
UserPreference
.
objects
.
all
()
filter_backends
=
(
filters
.
DjangoFilterBackend
,)
filter_fields
=
(
"key"
,)
filter_fields
=
(
"key"
,
"user"
)
serializer_class
=
UserPreferenceSerializer
paginate_by
=
10
paginate_by_param
=
"page_size"
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