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
a2ce7033
Commit
a2ce7033
authored
May 28, 2014
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't access course.id on ErrorDescriptors when listing courses from mongo
parent
c37e2412
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
1 deletions
+50
-1
cms/djangoapps/contentstore/tests/test_course_listing.py
+47
-1
cms/djangoapps/contentstore/views/course.py
+3
-0
No files found.
cms/djangoapps/contentstore/tests/test_course_listing.py
View file @
a2ce7033
...
...
@@ -3,7 +3,9 @@ Unit tests for getting the list of courses for a user through iterating all cour
by reversing group name formats.
"""
import
random
from
chrono
import
Timer
from
mock
import
patch
,
Mock
from
django.test
import
RequestFactory
...
...
@@ -11,11 +13,13 @@ from contentstore.views.course import _accessible_courses_list, _accessible_cour
from
contentstore.utils
import
delete_course_and_groups
,
reverse_course_url
from
contentstore.tests.utils
import
AjaxEnabledTestClient
from
student.tests.factories
import
UserFactory
from
student.roles
import
CourseInstructorRole
,
CourseStaffRole
from
student.roles
import
CourseInstructorRole
,
CourseStaffRole
,
GlobalStaff
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
from
xmodule.modulestore.locations
import
SlashSeparatedCourseKey
from
xmodule.modulestore.django
import
modulestore
from
xmodule.error_module
import
ErrorDescriptor
TOTAL_COURSES_COUNT
=
500
USER_COURSES_COUNT
=
50
...
...
@@ -79,6 +83,48 @@ class TestCourseListing(ModuleStoreTestCase):
# check both course lists have same courses
self
.
assertEqual
(
courses_list
,
courses_list_by_groups
)
def
test_errored_course_global_staff
(
self
):
"""
Test the course list for global staff when get_course returns an ErrorDescriptor
"""
GlobalStaff
()
.
add_users
(
self
.
user
)
course_key
=
SlashSeparatedCourseKey
(
'Org1'
,
'Course1'
,
'Run1'
)
self
.
_create_course_with_access_groups
(
course_key
,
self
.
user
)
with
patch
(
'xmodule.modulestore.mongo.base.MongoKeyValueStore'
,
Mock
(
side_effect
=
Exception
)):
self
.
assertIsInstance
(
modulestore
()
.
get_course
(
course_key
),
ErrorDescriptor
)
# get courses through iterating all courses
courses_list
=
_accessible_courses_list
(
self
.
request
)
self
.
assertEqual
(
courses_list
,
[])
# get courses by reversing group name formats
courses_list_by_groups
=
_accessible_courses_list_from_groups
(
self
.
request
)
self
.
assertEqual
(
courses_list_by_groups
,
[])
def
test_errored_course_regular_access
(
self
):
"""
Test the course list for regular staff when get_course returns an ErrorDescriptor
"""
GlobalStaff
()
.
remove_users
(
self
.
user
)
CourseStaffRole
(
SlashSeparatedCourseKey
(
'Non'
,
'Existent'
,
'Course'
))
.
add_users
(
self
.
user
)
course_key
=
SlashSeparatedCourseKey
(
'Org1'
,
'Course1'
,
'Run1'
)
self
.
_create_course_with_access_groups
(
course_key
,
self
.
user
)
with
patch
(
'xmodule.modulestore.mongo.base.MongoKeyValueStore'
,
Mock
(
side_effect
=
Exception
)):
self
.
assertIsInstance
(
modulestore
()
.
get_course
(
course_key
),
ErrorDescriptor
)
# get courses through iterating all courses
courses_list
=
_accessible_courses_list
(
self
.
request
)
self
.
assertEqual
(
courses_list
,
[])
# get courses by reversing group name formats
courses_list_by_groups
=
_accessible_courses_list_from_groups
(
self
.
request
)
self
.
assertEqual
(
courses_list_by_groups
,
[])
self
.
assertEqual
(
courses_list
,
courses_list_by_groups
)
def
test_get_course_list_with_invalid_course_location
(
self
):
"""
Test getting courses with invalid course location (course deleted from modulestore).
...
...
cms/djangoapps/contentstore/views/course.py
View file @
a2ce7033
...
...
@@ -163,6 +163,9 @@ def _accessible_courses_list(request):
"""
Get courses to which this user has access
"""
if
isinstance
(
course
,
ErrorDescriptor
):
return
False
if
GlobalStaff
()
.
has_user
(
request
.
user
):
return
course
.
location
.
course
!=
'templates'
...
...
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