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
099f499e
Commit
099f499e
authored
Aug 15, 2012
by
Bridger Maxwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed access methods for wiki nav. Added tests.
parent
4bc4e87a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
17 deletions
+61
-17
lms/djangoapps/course_wiki/course_nav.py
+4
-7
lms/djangoapps/course_wiki/tests/tests.py
+54
-7
lms/djangoapps/course_wiki/views.py
+2
-2
lms/djangoapps/courseware/tests/tests.py
+1
-1
No files found.
lms/djangoapps/course_wiki/course_nav.py
View file @
099f499e
...
...
@@ -4,7 +4,7 @@ from urlparse import urlparse
from
django.http
import
Http404
from
django.shortcuts
import
redirect
from
courseware.courses
import
check_course
from
courseware.courses
import
get_course_with_access
class
Middleware
(
object
):
...
...
@@ -21,8 +21,6 @@ class Middleware(object):
"""
def
process_request
(
self
,
request
):
#TODO: We should also redirect people who can't see the class to the regular wiki, so urls don't break
referer
=
request
.
META
.
get
(
'HTTP_REFERER'
)
try
:
...
...
@@ -40,7 +38,7 @@ class Middleware(object):
# See if we are able to view the course. If we are, redirect to it
try
:
course
=
check_course
(
request
.
user
,
course_id
)
course
=
get_course_with_access
(
request
.
user
,
course_id
,
'load'
)
return
redirect
(
"/courses/"
+
course
.
id
+
"/wiki/"
+
path_match
.
group
(
'wiki_path'
)
)
except
Http404
:
...
...
@@ -55,14 +53,13 @@ class Middleware(object):
course_id
=
course_match
.
group
(
'course_id'
)
# See if we are able to view the course. If we aren't, redirect to regular wiki
try
:
course
=
check_course
(
request
.
user
,
course_id
)
course
=
get_course_with_access
(
request
.
user
,
course_id
,
'load'
)
# Good, we can see the course. Carry on
return
None
except
Http404
:
# We can't see the course, so redirect to the regular wiki
return
redirect
(
"/wiki/"
+
course_match
.
group
(
'wiki_path'
))
return
None
def
context_processor
(
request
):
...
...
@@ -79,7 +76,7 @@ def context_processor(request):
course_id
=
match
.
group
(
'course_id'
)
try
:
course
=
check_course
(
request
.
user
,
course_id
)
course
=
get_course_with_access
(
request
.
user
,
course_id
,
'load'
)
return
{
'course'
:
course
}
except
Http404
:
# We couldn't access the course for whatever reason. It is too late to change
...
...
lms/djangoapps/course_wiki/tests/tests.py
View file @
099f499e
...
...
@@ -34,11 +34,13 @@ class WikiRedirectTestCase(PageLoader):
def
test_wiki_redirect
(
self
):
"""
Test that an enrolled in student going from /courses/edX/toy/2012_Fall/profile
Test that requesting wiki URLs redirect properly to or out of classes.
An enrolled in student going from /courses/edX/toy/2012_Fall/profile
to /wiki/some/fake/wiki/page/ will redirect to
/courses/edX/toy/2012_Fall/wiki/some/fake/wiki/page/
Test that a
n unenrolled student going to /courses/edX/toy/2012_Fall/wiki/some/fake/wiki/page/
A
n unenrolled student going to /courses/edX/toy/2012_Fall/wiki/some/fake/wiki/page/
will be redirected to /wiki/some/fake/wiki/page/
"""
...
...
@@ -57,16 +59,61 @@ class WikiRedirectTestCase(PageLoader):
self
.
assertEqual
(
resp
[
'Location'
],
'http://testserver'
+
redirected_to
)
# Now we test that the student will be redirected away from that page if the
y are unenrolled
# We do this in the same test because we want to make sure the redirected_to is
the same
# Now we test that the student will be redirected away from that page if the
course doesn't exist
# We do this in the same test because we want to make sure the redirected_to is
constructed correctly
self
.
unenroll
(
self
.
toy
)
# This is a location like /courses/*/wiki/* , but with an invalid course ID
bad_course_wiki_page
=
redirected_to
.
replace
(
self
.
toy
.
location
.
course
,
"bad_course"
)
resp
=
self
.
client
.
get
(
redirected_to
,
HTTP_REFERER
=
referer
)
print
"redirected_to"
,
redirected_to
resp
=
self
.
client
.
get
(
bad_course_wiki_page
,
HTTP_REFERER
=
referer
)
self
.
assertEqual
(
resp
.
status_code
,
302
)
self
.
assertEqual
(
resp
[
'Location'
],
'http://testserver'
+
destination
)
def
create_course_page
(
self
,
course
):
"""
Test that loading the course wiki page creates the wiki page.
The user must be enrolled in the course to see the page.
"""
course_wiki_home
=
reverse
(
'course_wiki'
,
kwargs
=
{
'course_id'
:
course
.
id
})
referer
=
reverse
(
"profile"
,
kwargs
=
{
'course_id'
:
self
.
toy
.
id
})
resp
=
self
.
client
.
get
(
course_wiki_home
,
follow
=
True
,
HTTP_REFERER
=
referer
)
course_wiki_page
=
referer
.
replace
(
'profile'
,
'wiki/'
+
self
.
toy
.
wiki_slug
+
"/"
)
ending_location
=
resp
.
redirect_chain
[
-
1
][
0
]
ending_status
=
resp
.
redirect_chain
[
-
1
][
1
]
self
.
assertEquals
(
ending_location
,
'http://testserver'
+
course_wiki_page
)
self
.
assertEquals
(
resp
.
status_code
,
200
)
self
.
has_course_navigator
(
resp
)
def
has_course_navigator
(
self
,
resp
):
"""
Ensure that the response has the course navigator.
"""
self
.
assertTrue
(
"course info"
in
resp
.
content
.
lower
()
)
self
.
assertTrue
(
"courseware"
in
resp
.
content
.
lower
()
)
def
test_course_navigator
(
self
):
""""
Test that going from a course page to a wiki page contains the course navigator.
"""
self
.
login
(
self
.
student
,
self
.
password
)
self
.
enroll
(
self
.
toy
)
self
.
create_course_page
(
self
.
toy
)
course_wiki_page
=
reverse
(
'wiki:get'
,
kwargs
=
{
'path'
:
self
.
toy
.
wiki_slug
+
'/'
})
referer
=
reverse
(
"courseware"
,
kwargs
=
{
'course_id'
:
self
.
toy
.
id
})
resp
=
self
.
client
.
get
(
course_wiki_page
,
follow
=
True
,
HTTP_REFERER
=
referer
)
self
.
has_course_navigator
(
resp
)
lms/djangoapps/course_wiki/views.py
View file @
099f499e
...
...
@@ -5,7 +5,7 @@ from django.shortcuts import redirect
from
wiki.core.exceptions
import
NoRootURL
from
wiki.models
import
URLPath
,
Article
from
courseware.courses
import
check_course
from
courseware.courses
import
get_course_by_id
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -25,7 +25,7 @@ def course_wiki_redirect(request, course_id):
as it's home page. A course's wiki must be an article on the root (for
example, "/6.002x") to keep things simple.
"""
course
=
check_course
(
request
.
user
,
course_id
)
course
=
get_course_by_id
(
course_id
)
course_slug
=
course
.
wiki_slug
...
...
lms/djangoapps/courseware/tests/tests.py
View file @
099f499e
...
...
@@ -187,7 +187,7 @@ class PageLoader(ActivateLoginTestCase):
def
unenroll
(
self
,
course
):
"""Unenroll the currently logged-in user, and check that it worked."""
resp
=
self
.
client
.
post
(
'/change_enrollment'
,
{
'enrollment_action'
:
'enroll'
,
'enrollment_action'
:
'
un
enroll'
,
'course_id'
:
course
.
id
,
})
data
=
parse_json
(
resp
)
...
...
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