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
2b389a2d
Commit
2b389a2d
authored
Mar 25, 2014
by
zubiar-arbi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
raise ItemNotFoundError if course not found in modulestore (course_listing)
STUD-1455
parent
c3b8380d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
0 deletions
+52
-0
cms/djangoapps/contentstore/tests/test_course_listing.py
+49
-0
cms/djangoapps/contentstore/views/course.py
+3
-0
No files found.
cms/djangoapps/contentstore/tests/test_course_listing.py
View file @
2b389a2d
...
...
@@ -146,6 +146,43 @@ class TestCourseListing(ModuleStoreTestCase):
with
self
.
assertRaises
(
ItemNotFoundError
):
courses_list_by_groups
=
_accessible_courses_list_from_groups
(
request
)
def
test_get_course_list_with_invalid_course_location
(
self
):
"""
Test getting courses with invalid course location (course deleted from modulestore but
location exists in loc_mapper).
"""
request
=
self
.
factory
.
get
(
'/course'
)
request
.
user
=
self
.
user
course_location
=
Location
(
'i4x'
,
'Org'
,
'Course'
,
'course'
,
'Run'
)
self
.
_create_course_with_access_groups
(
course_location
,
'group_name_with_dots'
,
self
.
user
)
# get courses through iterating all courses
courses_list
=
_accessible_courses_list
(
request
)
self
.
assertEqual
(
len
(
courses_list
),
1
)
# get courses by reversing group name formats
courses_list_by_groups
=
_accessible_courses_list_from_groups
(
request
)
self
.
assertEqual
(
len
(
courses_list_by_groups
),
1
)
# check both course lists have same courses
self
.
assertEqual
(
courses_list
,
courses_list_by_groups
)
# now delete this course and re-add user to instructor group of this course
delete_course_and_groups
(
course_location
.
course_id
,
commit
=
True
)
course_locator
=
loc_mapper
()
.
translate_location
(
course_location
.
course_id
,
course_location
)
instructor_group_name
=
CourseInstructorRole
(
course_locator
)
.
_group_names
[
0
]
# pylint: disable=protected-access
group
,
__
=
Group
.
objects
.
get_or_create
(
name
=
instructor_group_name
)
self
.
user
.
groups
.
add
(
group
)
# test that get courses through iterating all courses now returns no course
courses_list
=
_accessible_courses_list
(
request
)
self
.
assertEqual
(
len
(
courses_list
),
0
)
# now test that get courses by reversing group name formats gives 'ItemNotFoundError'
with
self
.
assertRaises
(
ItemNotFoundError
):
_accessible_courses_list_from_groups
(
request
)
def
test_course_listing_performance
(
self
):
"""
Create large number of courses and give access of some of these courses to the user and
...
...
@@ -202,8 +239,11 @@ class TestCourseListing(ModuleStoreTestCase):
Test getting courses with same id but with different name case. Then try to delete one of them and
check that it is properly deleted and other one is accessible
"""
# create and log in a non-staff user
self
.
user
=
UserFactory
()
request
=
self
.
factory
.
get
(
'/course'
)
request
.
user
=
self
.
user
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
'test'
)
course_location_caps
=
Location
([
'i4x'
,
'Org'
,
'COURSE'
,
'course'
,
'Run'
])
self
.
_create_course_with_access_groups
(
course_location_caps
,
'group_name_with_dots'
,
self
.
user
)
...
...
@@ -239,6 +279,15 @@ class TestCourseListing(ModuleStoreTestCase):
group
,
__
=
Group
.
objects
.
get_or_create
(
name
=
instructor_group_name
)
self
.
user
.
groups
.
add
(
group
)
# test viewing the index page which creates missing courses loc_map entries
resp
=
self
.
client
.
get_html
(
'/course'
)
self
.
assertContains
(
resp
,
'<h1 class="page-header">My Courses</h1>'
,
status_code
=
200
,
html
=
True
)
# test that get courses through iterating all courses now returns one course
courses_list
=
_accessible_courses_list
(
request
)
self
.
assertEqual
(
len
(
courses_list
),
1
)
...
...
cms/djangoapps/contentstore/views/course.py
View file @
2b389a2d
...
...
@@ -220,6 +220,9 @@ def _accessible_courses_list_from_groups(request):
raise
ItemNotFoundError
(
course_id
)
course
=
modulestore
(
'direct'
)
.
get_course
(
course_location
.
course_id
)
if
course
is
None
:
raise
ItemNotFoundError
(
course_id
)
courses_list
.
append
(
course
)
return
courses_list
...
...
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