Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
6f7a0665
Commit
6f7a0665
authored
10 years ago
by
Clinton Blackburn
Browse files
Options
Downloads
Plain Diff
Merge pull request #7089 from edx/clintonb/cs-api-fix
Fixed Course List Endpoint
parents
8acdf532
0385a8b5
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lms/djangoapps/course_structure_api/v0/tests.py
+24
-1
24 additions, 1 deletion
lms/djangoapps/course_structure_api/v0/tests.py
lms/djangoapps/course_structure_api/v0/views.py
+11
-9
11 additions, 9 deletions
lms/djangoapps/course_structure_api/v0/views.py
with
35 additions
and
10 deletions
lms/djangoapps/course_structure_api/v0/tests.py
+
24
−
1
View file @
6f7a0665
...
...
@@ -7,12 +7,17 @@ from datetime import datetime
from
django.core.urlresolvers
import
reverse
from
django.test.utils
import
override_settings
from
mock
import
patch
,
Mock
from
oauth2_provider.tests.factories
import
AccessTokenFactory
,
ClientFactory
from
openedx.core.djangoapps.content.course_structures.models
import
CourseStructure
,
update_course_structure
from
opaque_keys.edx.locator
import
CourseLocator
from
xmodule.error_module
import
ErrorDescriptor
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
,
ItemFactory
from
xmodule.modulestore.xml
import
CourseLocationManager
from
xmodule.tests
import
get_test_system
from
courseware.tests.factories
import
GlobalStaffFactory
,
StaffFactory
from
openedx.core.djangoapps.content.course_structures.models
import
CourseStructure
,
update_course_structure
TEST_SERVER_HOST
=
'
http://testserver
'
...
...
@@ -260,6 +265,24 @@ class CourseListTests(CourseViewTestsMixin, ModuleStoreTestCase):
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertDictContainsSubset
({
'
count
'
:
0
,
u
'
results
'
:
[]},
response
.
data
)
def
test_course_error
(
self
):
"""
Ensure the view still returns results even if get_courses() returns an ErrorDescriptor. The ErrorDescriptor
should be filtered out.
"""
error_descriptor
=
ErrorDescriptor
.
from_xml
(
'
<course></course>
'
,
get_test_system
(),
CourseLocationManager
(
CourseLocator
(
org
=
'
org
'
,
course
=
'
course
'
,
run
=
'
run
'
)),
None
)
descriptors
=
[
error_descriptor
,
self
.
empty_course
,
self
.
course
]
with
patch
(
'
xmodule.modulestore.mixed.MixedModuleStore.get_courses
'
,
Mock
(
return_value
=
descriptors
)):
self
.
test_get
()
class
CourseDetailTests
(
CourseDetailMixin
,
CourseViewTestsMixin
,
ModuleStoreTestCase
):
view
=
'
course_structure_api:v0:detail
'
...
...
This diff is collapsed.
Click to expand it.
lms/djangoapps/course_structure_api/v0/views.py
+
11
−
9
View file @
6f7a0665
...
...
@@ -12,12 +12,12 @@ from rest_framework.response import Response
from
xmodule.modulestore.django
import
modulestore
from
opaque_keys.edx.keys
import
CourseKey
from
course_structure_api.v0
import
serializers
from
courseware
import
courses
from
courseware.access
import
has_access
from
openedx.core.djangoapps.content.course_structures
import
models
from
openedx.core.lib.api.permissions
import
IsAuthenticatedOrDebug
from
openedx.core.lib.api.serializers
import
PaginationSerializer
from
courseware
import
courses
from
course_structure_api.v0
import
serializers
from
student.roles
import
CourseInstructorRole
,
CourseStaffRole
...
...
@@ -115,22 +115,24 @@ class CourseList(CourseViewMixin, ListAPIView):
def
get_queryset
(
self
):
course_ids
=
self
.
request
.
QUERY_PARAMS
.
get
(
'
course_id
'
,
None
)
course_descriptor
s
=
[]
result
s
=
[]
if
course_ids
:
course_ids
=
course_ids
.
split
(
'
,
'
)
for
course_id
in
course_ids
:
course_key
=
CourseKey
.
from_string
(
course_id
)
course_descriptor
=
courses
.
get_course
(
course_key
)
course_descriptor
s
.
append
(
course_descriptor
)
result
s
.
append
(
course_descriptor
)
else
:
course_descriptor
s
=
modulestore
().
get_courses
()
result
s
=
modulestore
().
get_courses
()
results
=
[
course
for
course
in
course_descriptors
if
self
.
user_can_access_course
(
self
.
request
.
user
,
course
)]
# Ensure only course descriptors are returned.
results
=
(
course
for
course
in
results
if
course
.
scope_ids
.
block_type
==
'
course
'
)
#
Sort the results in a predictable man
ne
r
.
results
.
sort
(
key
=
attrgetter
(
'
id
'
))
#
Ensure only courses accessible by the user are retur
ne
d
.
results
=
(
course
for
course
in
results
if
self
.
user_can_access_course
(
self
.
request
.
user
,
course
))
return
results
# Sort the results in a predictable manner.
return
sorted
(
results
,
key
=
attrgetter
(
'
id
'
))
class
CourseDetail
(
CourseViewMixin
,
RetrieveAPIView
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment