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
4ed83222
Commit
4ed83222
authored
Oct 21, 2013
by
Don Mitchell
Committed by
David Baumgold
Oct 22, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test that instructors can access courses
parent
5730f6e3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
8 deletions
+55
-8
cms/djangoapps/contentstore/tests/test_course_index.py
+54
-7
cms/djangoapps/contentstore/tests/utils.py
+1
-1
No files found.
cms/djangoapps/contentstore/tests/test_course_index.py
View file @
4ed83222
"""
Unit tests for getting the list of courses and the course outline.
"""
from
django.core.urlresolvers
import
reverse
import
json
import
lxml
from
django.core.urlresolvers
import
reverse
from
contentstore.tests.utils
import
CourseTestCase
from
xmodule.modulestore.django
import
loc_mapper
from
django.core.exceptions
import
PermissionDenied
from
xmodule.modulestore.tests.factories
import
CourseFactory
from
xmodule.modulestore
import
parsers
class
TestCourseIndex
(
CourseTestCase
):
"""
Unit tests for getting the list of courses and the course outline.
"""
def
test_index
(
self
):
def
setUp
(
self
):
"""
Add a course with odd characters in the fields
"""
super
(
TestCourseIndex
,
self
)
.
setUp
()
# had a problem where index showed course but has_access failed to retrieve it for non-staff
self
.
odd_course
=
CourseFactory
.
create
(
org
=
'test.org_1-2'
,
number
=
'test-2.3_course'
,
display_name
=
'dotted.course.name-2'
,
)
def
check_index_and_outline
(
self
,
authed_client
):
"""
Test getting the list of courses and then pulling up their outlines
"""
index_url
=
reverse
(
'contentstore.views.index'
)
index_response
=
self
.
client
.
get
(
index_url
,
{},
HTTP_ACCEPT
=
'text/html'
)
index_response
=
authed_
client
.
get
(
index_url
,
{},
HTTP_ACCEPT
=
'text/html'
)
parsed_html
=
lxml
.
html
.
fromstring
(
index_response
.
content
)
course_link_eles
=
parsed_html
.
find_class
(
'course-link'
)
self
.
assertGreaterEqual
(
len
(
course_link_eles
),
2
)
for
link
in
course_link_eles
:
self
.
assertRegexpMatches
(
link
.
get
(
"href"
),
r'course/\w+\.\w+\.\w+.*/branch/\w+/block/.*'
)
self
.
assertRegexpMatches
(
link
.
get
(
"href"
),
r'course/{0}+/branch/{0}+/block/{0}+'
.
format
(
parsers
.
ALLOWED_ID_CHARS
)
)
# now test that url
outline_response
=
self
.
client
.
get
(
link
.
get
(
"href"
),
{},
HTTP_ACCEPT
=
'text/html'
)
outline_response
=
authed_
client
.
get
(
link
.
get
(
"href"
),
{},
HTTP_ACCEPT
=
'text/html'
)
# ensure it has the expected 2 self referential links
outline_parsed
=
lxml
.
html
.
fromstring
(
outline_response
.
content
)
outline_link
=
outline_parsed
.
find_class
(
'course-link'
)[
0
]
...
...
@@ -31,6 +50,12 @@ class TestCourseIndex(CourseTestCase):
course_menu_link
=
outline_parsed
.
find_class
(
'nav-course-courseware-outline'
)[
0
]
self
.
assertEqual
(
course_menu_link
.
find
(
"a"
)
.
get
(
"href"
),
link
.
get
(
"href"
))
def
test_is_staff_access
(
self
):
"""
Test that people with is_staff see the courses and can navigate into them
"""
self
.
check_index_and_outline
(
self
.
client
)
def
test_negative_conditions
(
self
):
"""
Test the error conditions for the access
...
...
@@ -38,6 +63,28 @@ class TestCourseIndex(CourseTestCase):
locator
=
loc_mapper
()
.
translate_location
(
self
.
course
.
location
.
course_id
,
self
.
course
.
location
,
False
,
True
)
outline_url
=
reverse
(
'contentstore.views.course_handler'
,
kwargs
=
{
'course_url'
:
unicode
(
locator
)})
# register a non-staff member and try to delete the course branch
non_staff_client
=
self
.
createNonStaffAuthedUserClient
()
non_staff_client
,
_
=
self
.
createNonStaffAuthedUserClient
()
response
=
non_staff_client
.
delete
(
outline_url
,
{},
HTTP_ACCEPT
=
'application/json'
)
self
.
assertEqual
(
response
.
status_code
,
403
)
def
test_course_staff_access
(
self
):
"""
Make and register an course_staff and ensure they can access the courses
"""
course_staff_client
,
course_staff
=
self
.
createNonStaffAuthedUserClient
()
for
course
in
[
self
.
course
,
self
.
odd_course
]:
permission_url
=
reverse
(
"course_team_user"
,
kwargs
=
{
"org"
:
course
.
location
.
org
,
"course"
:
course
.
location
.
course
,
"name"
:
course
.
location
.
name
,
"email"
:
course_staff
.
email
,
})
self
.
client
.
post
(
permission_url
,
data
=
json
.
dumps
({
"role"
:
"staff"
}),
content_type
=
"application/json"
,
HTTP_ACCEPT
=
"application/json"
,
)
# test access
self
.
check_index_and_outline
(
course_staff_client
)
cms/djangoapps/contentstore/tests/utils.py
View file @
4ed83222
...
...
@@ -78,4 +78,4 @@ class CourseTestCase(ModuleStoreTestCase):
client
=
Client
()
client
.
login
(
username
=
uname
,
password
=
password
)
return
client
return
client
,
nonstaff
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