diff --git a/common/lib/xmodule/xmodule/modulestore/tests/factories.py b/common/lib/xmodule/xmodule/modulestore/tests/factories.py
index 9e71fad279..d648b404e3 100644
--- a/common/lib/xmodule/xmodule/modulestore/tests/factories.py
+++ b/common/lib/xmodule/xmodule/modulestore/tests/factories.py
@@ -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.
diff --git a/lms/djangoapps/staticbook/tests.py b/lms/djangoapps/staticbook/tests.py
index 92440656c7..deb13ffc9e 100644
--- a/lms/djangoapps/staticbook/tests.py
+++ b/lms/djangoapps/staticbook/tests.py
@@ -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('''\
+
+
+
+
+
+
+
+ ''')
+
+ 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')
diff --git a/lms/urls.py b/lms/urls.py
index b131bb8f0b..13d93f7e30 100644
--- a/lms/urls.py
+++ b/lms/urls.py
@@ -226,7 +226,7 @@ if settings.COURSEWARE_ENABLED:
url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/book/(?P\d+)/$',
'staticbook.views.index', name="book"),
url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/book/(?P\d+)/(?P\d+)$',
- 'staticbook.views.index'),
+ 'staticbook.views.index', name="book"),
url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/pdfbook/(?P\d+)/$',
'staticbook.views.pdf_index', name="pdf_book"),