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
1d5dfaa1
Commit
1d5dfaa1
authored
Jul 03, 2013
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for image books, and more tests for the other kinds too.
parent
959274c7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
4 deletions
+63
-4
common/lib/xmodule/xmodule/modulestore/tests/factories.py
+1
-0
lms/djangoapps/staticbook/tests.py
+61
-3
lms/urls.py
+1
-1
No files found.
common/lib/xmodule/xmodule/modulestore/tests/factories.py
View file @
1d5dfaa1
...
...
@@ -61,6 +61,7 @@ class XModuleCourseFactory(Factory):
# Update the data in the mongo datastore
store
.
update_metadata
(
new_course
.
location
.
url
(),
own_metadata
(
new_course
))
store
.
update_item
(
new_course
.
location
.
url
(),
new_course
.
_model_data
.
_kvs
.
_data
)
# update_item updates the the course as it exists in the modulestore, but doesn't
# update the instance we are working with, so have to refetch the course after updating it.
...
...
lms/djangoapps/staticbook/tests.py
View file @
1d5dfaa1
...
...
@@ -2,6 +2,11 @@
Test the lms/staticbook views.
"""
import
textwrap
import
mock
import
requests
from
django.test.utils
import
override_settings
from
django.core.urlresolvers
import
reverse
,
NoReverseMatch
...
...
@@ -11,6 +16,8 @@ from xmodule.modulestore.tests.factories import CourseFactory
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
IMAGE_BOOK
=
(
"An Image Textbook"
,
"http://example.com/the_book/"
)
PDF_BOOK
=
{
"tab_title"
:
"Textbook"
,
"title"
:
"A PDF Textbook"
,
...
...
@@ -60,6 +67,44 @@ class StaticBookTest(ModuleStoreTestCase):
return
url
class
StaticImageBookTest
(
StaticBookTest
):
"""
Test the image-based static book view.
"""
def
test_book
(
self
):
# We can access a book.
with
mock
.
patch
.
object
(
requests
,
'get'
)
as
mock_get
:
mock_get
.
return_value
.
text
=
textwrap
.
dedent
(
'''
\
<?xml version="1.0"?>
<table_of_contents>
<entry page="9" page_label="ix" name="Contents!?"/>
<entry page="1" page_label="i" name="Preamble">
<entry page="4" page_label="iv" name="About the Elephants"/>
</entry>
</table_of_contents>
'''
)
self
.
make_course
(
textbooks
=
[
IMAGE_BOOK
])
url
=
self
.
make_url
(
'book'
,
book_index
=
0
)
response
=
self
.
client
.
get
(
url
)
self
.
assertContains
(
response
,
"Contents!?"
)
self
.
assertContains
(
response
,
"About the Elephants"
)
def
test_bad_book_id
(
self
):
# A bad book id will be a 404.
self
.
make_course
(
textbooks
=
[
IMAGE_BOOK
])
with
self
.
assertRaises
(
NoReverseMatch
):
self
.
make_url
(
'book'
,
book_index
=
'fooey'
)
def
test_out_of_range_book_id
(
self
):
self
.
make_course
()
url
=
self
.
make_url
(
'book'
,
book_index
=
0
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
404
)
class
StaticPdfBookTest
(
StaticBookTest
):
"""
Test the PDF static book view.
...
...
@@ -102,6 +147,12 @@ class StaticPdfBookTest(StaticBookTest):
self
.
assertContains
(
response
,
"options.pageNum = 17;"
)
def
test_bad_book_id
(
self
):
# If the book id isn't an int, we'll get a 404.
self
.
make_course
(
pdf_textbooks
=
[
PDF_BOOK
])
with
self
.
assertRaises
(
NoReverseMatch
):
self
.
make_url
(
'pdf_book'
,
book_index
=
'fooey'
,
chapter
=
1
)
def
test_out_of_range_book_id
(
self
):
# If we have one book, asking for the second book will fail with a 404.
self
.
make_course
(
pdf_textbooks
=
[
PDF_BOOK
])
url
=
self
.
make_url
(
'pdf_book'
,
book_index
=
1
,
chapter
=
1
)
...
...
@@ -117,18 +168,25 @@ class StaticPdfBookTest(StaticBookTest):
def
test_chapter_xss
(
self
):
# The chapter in the URL used to go right on the page.
course
=
self
.
make_course
(
pdf_textbooks
=
[
PDF_BOOK
])
self
.
make_course
(
pdf_textbooks
=
[
PDF_BOOK
])
# It's no longer possible to use a non-integer chapter.
with
self
.
assertRaises
(
NoReverseMatch
):
self
.
make_url
(
'pdf_book'
,
book_index
=
0
,
chapter
=
'xyzzy'
)
def
test_page_xss
(
self
):
# The page in the URL used to go right on the page.
course
=
self
.
make_course
(
pdf_textbooks
=
[
PDF_BOOK
])
self
.
make_course
(
pdf_textbooks
=
[
PDF_BOOK
])
# It's no longer possible to use a non-integer page.
with
self
.
assertRaises
(
NoReverseMatch
):
self
.
make_url
(
'pdf_book'
,
book_index
=
0
,
page
=
'xyzzy'
)
def
test_chapter_page_xss
(
self
):
# The page in the URL used to go right on the page.
self
.
make_course
(
pdf_textbooks
=
[
PDF_BOOK
])
# It's no longer possible to use a non-integer page and a non-integer chapter.
with
self
.
assertRaises
(
NoReverseMatch
):
self
.
make_url
(
'pdf_book'
,
book_index
=
0
,
chapter
=
'fooey'
,
page
=
'xyzzy'
)
class
StaticHtmlBookTest
(
StaticBookTest
):
"""
...
...
@@ -167,7 +225,7 @@ class StaticHtmlBookTest(StaticBookTest):
def
test_chapter_xss
(
self
):
# The chapter in the URL used to go right on the page.
course
=
self
.
make_course
(
pdf_textbooks
=
[
HTML_BOOK
])
self
.
make_course
(
pdf_textbooks
=
[
HTML_BOOK
])
# It's no longer possible to use a non-integer chapter.
with
self
.
assertRaises
(
NoReverseMatch
):
self
.
make_url
(
'html_book'
,
book_index
=
0
,
chapter
=
'xyzzy'
)
lms/urls.py
View file @
1d5dfaa1
...
...
@@ -226,7 +226,7 @@ if settings.COURSEWARE_ENABLED:
url
(
r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/book/(?P<book_index>\d+)/$'
,
'staticbook.views.index'
,
name
=
"book"
),
url
(
r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/book/(?P<book_index>\d+)/(?P<page>\d+)$'
,
'staticbook.views.index'
),
'staticbook.views.index'
,
name
=
"book"
),
url
(
r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/pdfbook/(?P<book_index>\d+)/$'
,
'staticbook.views.pdf_index'
,
name
=
"pdf_book"
),
...
...
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