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
4c56c242
Commit
4c56c242
authored
Sep 28, 2016
by
Christopher Lee
Committed by
GitHub
Sep 28, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13589 from proversity-org/proversity/feature-mobile-org-filter
mobile api filter enrollments by org
parents
1473bd61
1b985a5c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
5 deletions
+38
-5
lms/djangoapps/mobile_api/testutils.py
+4
-4
lms/djangoapps/mobile_api/users/tests.py
+26
-0
lms/djangoapps/mobile_api/users/views.py
+8
-1
No files found.
lms/djangoapps/mobile_api/testutils.py
View file @
4c56c242
...
...
@@ -72,13 +72,13 @@ class MobileAPITestCase(ModuleStoreTestCase, APITestCase):
self
.
login
()
self
.
enroll
(
course_id
)
def
api_response
(
self
,
reverse_args
=
None
,
expected_response_code
=
200
,
**
kwargs
):
def
api_response
(
self
,
reverse_args
=
None
,
expected_response_code
=
200
,
data
=
None
,
**
kwargs
):
"""
Helper method for calling endpoint, verifying and returning response.
If expected_response_code is None, doesn't verify the response' status_code.
"""
url
=
self
.
reverse_url
(
reverse_args
,
**
kwargs
)
response
=
self
.
url_method
(
url
,
**
kwargs
)
response
=
self
.
url_method
(
url
,
data
=
data
,
**
kwargs
)
if
expected_response_code
is
not
None
:
self
.
assertEqual
(
response
.
status_code
,
expected_response_code
)
return
response
...
...
@@ -92,9 +92,9 @@ class MobileAPITestCase(ModuleStoreTestCase, APITestCase):
reverse_args
.
update
({
'username'
:
kwargs
.
get
(
'username'
,
self
.
user
.
username
)})
return
reverse
(
self
.
REVERSE_INFO
[
'name'
],
kwargs
=
reverse_args
)
def
url_method
(
self
,
url
,
**
kwargs
):
# pylint: disable=unused-argument
def
url_method
(
self
,
url
,
data
=
None
,
**
kwargs
):
# pylint: disable=unused-argument
"""Base implementation that returns response from the GET method of the URL."""
return
self
.
client
.
get
(
url
)
return
self
.
client
.
get
(
url
,
data
=
data
)
class
MobileAuthTestMixin
(
object
):
...
...
lms/djangoapps/mobile_api/users/tests.py
View file @
4c56c242
...
...
@@ -274,6 +274,32 @@ class TestUserEnrollmentApi(UrlResetMixin, MobileAPITestCase, MobileAuthUserTest
response_discussion_url
=
response
.
data
[
0
][
'course'
][
'discussion_url'
]
# pylint: disable=E1101
self
.
assertIn
(
'/api/discussion/v1/courses/{}'
.
format
(
self
.
course
.
id
),
response_discussion_url
)
def
test_org_query
(
self
):
self
.
login
()
# Create list of courses with various organizations
courses
=
[
CourseFactory
.
create
(
org
=
'edX'
,
mobile_available
=
True
),
CourseFactory
.
create
(
org
=
'edX'
,
mobile_available
=
True
),
CourseFactory
.
create
(
org
=
'edX'
,
mobile_available
=
True
,
visible_to_staff_only
=
True
),
CourseFactory
.
create
(
org
=
'Proversity.org'
,
mobile_available
=
True
),
CourseFactory
.
create
(
org
=
'MITx'
,
mobile_available
=
True
),
CourseFactory
.
create
(
org
=
'HarvardX'
,
mobile_available
=
True
),
]
# Enroll in all the courses
for
course
in
courses
:
self
.
enroll
(
course
.
id
)
response
=
self
.
api_response
(
data
=
{
'org'
:
'edX'
})
# Test for 3 expected courses
self
.
assertEqual
(
len
(
response
.
data
),
3
)
# Verify only edX courses are returned
for
entry
in
response
.
data
:
self
.
assertEqual
(
entry
[
'course'
][
'org'
],
'edX'
)
@attr
(
shard
=
2
)
class
CourseStatusAPITestCase
(
MobileAPITestCase
):
...
...
lms/djangoapps/mobile_api/users/views.py
View file @
4c56c242
...
...
@@ -270,14 +270,21 @@ class UserCourseEnrollmentsList(generics.ListAPIView):
# the default behavior by setting the pagination_class to None.
pagination_class
=
None
def
is_org
(
self
,
check_org
,
course_org
):
"""
Check course org matches request org param or no param provided
"""
return
check_org
is
None
or
(
check_org
.
lower
()
==
course_org
.
lower
())
def
get_queryset
(
self
):
enrollments
=
self
.
queryset
.
filter
(
user__username
=
self
.
kwargs
[
'username'
],
is_active
=
True
)
.
order_by
(
'created'
)
.
reverse
()
org
=
self
.
request
.
query_params
.
get
(
'org'
,
None
)
return
[
enrollment
for
enrollment
in
enrollments
if
enrollment
.
course_overview
and
if
enrollment
.
course_overview
and
self
.
is_org
(
org
,
enrollment
.
course_overview
.
org
)
and
is_mobile_available_for_user
(
self
.
request
.
user
,
enrollment
.
course_overview
)
]
...
...
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