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
f6b0ffd0
Commit
f6b0ffd0
authored
Jul 01, 2013
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make some helpers for the tests.
parent
4ff2de69
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
24 deletions
+38
-24
lms/djangoapps/staticbook/tests.py
+38
-24
No files found.
lms/djangoapps/staticbook/tests.py
View file @
f6b0ffd0
"""
Test the /staticbook views.
Test the
lms
/staticbook views.
"""
from
django.test.utils
import
override_settings
...
...
@@ -35,15 +35,29 @@ class StaticBookTest(ModuleStoreTestCase):
Helpers for the static book tests.
"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
StaticBookTest
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
course
=
None
def
make_course
(
self
,
**
kwargs
):
"""
Make a course with an enrolled logged-in student.
"""
course
=
CourseFactory
.
create
(
**
kwargs
)
self
.
course
=
CourseFactory
.
create
(
**
kwargs
)
user
=
UserFactory
.
create
()
CourseEnrollmentFactory
.
create
(
user
=
user
,
course_id
=
course
.
id
)
CourseEnrollmentFactory
.
create
(
user
=
user
,
course_id
=
self
.
course
.
id
)
self
.
client
.
login
(
username
=
user
.
username
,
password
=
'test'
)
return
course
def
make_url
(
self
,
url_name
,
**
kwargs
):
"""
Make a URL for a `url_name` using keyword args for url slots.
Automatically provides the course id.
"""
kwargs
[
'course_id'
]
=
self
.
course
.
id
url
=
reverse
(
url_name
,
kwargs
=
kwargs
)
return
url
class
StaticPdfBookTest
(
StaticBookTest
):
...
...
@@ -53,8 +67,8 @@ class StaticPdfBookTest(StaticBookTest):
def
test_book
(
self
):
# We can access a book.
course
=
self
.
make_course
(
pdf_textbooks
=
[
PDF_BOOK
])
url
=
reverse
(
'pdf_book'
,
kwargs
=
{
'course_id'
:
course
.
id
,
'book_index'
:
0
}
)
self
.
make_course
(
pdf_textbooks
=
[
PDF_BOOK
])
url
=
self
.
make_url
(
'pdf_book'
,
book_index
=
0
)
response
=
self
.
client
.
get
(
url
)
self
.
assertContains
(
response
,
"Chapter 1 for PDF"
)
self
.
assertNotContains
(
response
,
"options.chapterNum ="
)
...
...
@@ -62,8 +76,8 @@ class StaticPdfBookTest(StaticBookTest):
def
test_book_chapter
(
self
):
# We can access a book at a particular chapter.
course
=
self
.
make_course
(
pdf_textbooks
=
[
PDF_BOOK
])
url
=
reverse
(
'pdf_book'
,
kwargs
=
{
'course_id'
:
course
.
id
,
'book_index'
:
0
,
'chapter'
:
2
}
)
self
.
make_course
(
pdf_textbooks
=
[
PDF_BOOK
])
url
=
self
.
make_url
(
'pdf_book'
,
book_index
=
0
,
chapter
=
2
)
response
=
self
.
client
.
get
(
url
)
self
.
assertContains
(
response
,
"Chapter 2 for PDF"
)
self
.
assertContains
(
response
,
"options.chapterNum = 2;"
)
...
...
@@ -71,8 +85,8 @@ class StaticPdfBookTest(StaticBookTest):
def
test_book_page
(
self
):
# We can access a book at a particular page.
course
=
self
.
make_course
(
pdf_textbooks
=
[
PDF_BOOK
])
url
=
reverse
(
'pdf_book'
,
kwargs
=
{
'course_id'
:
course
.
id
,
'book_index'
:
0
,
'page'
:
17
}
)
self
.
make_course
(
pdf_textbooks
=
[
PDF_BOOK
])
url
=
self
.
make_url
(
'pdf_book'
,
book_index
=
0
,
page
=
17
)
response
=
self
.
client
.
get
(
url
)
self
.
assertContains
(
response
,
"Chapter 1 for PDF"
)
self
.
assertNotContains
(
response
,
"options.chapterNum ="
)
...
...
@@ -80,8 +94,8 @@ class StaticPdfBookTest(StaticBookTest):
def
test_book_chapter_page
(
self
):
# We can access a book at a particular chapter and page.
course
=
self
.
make_course
(
pdf_textbooks
=
[
PDF_BOOK
])
url
=
reverse
(
'pdf_book'
,
kwargs
=
{
'course_id'
:
course
.
id
,
'book_index'
:
0
,
'chapter'
:
2
,
'page'
:
17
}
)
self
.
make_course
(
pdf_textbooks
=
[
PDF_BOOK
])
url
=
self
.
make_url
(
'pdf_book'
,
book_index
=
0
,
chapter
=
2
,
page
=
17
)
response
=
self
.
client
.
get
(
url
)
self
.
assertContains
(
response
,
"Chapter 2 for PDF"
)
self
.
assertContains
(
response
,
"options.chapterNum = 2;"
)
...
...
@@ -89,15 +103,15 @@ class StaticPdfBookTest(StaticBookTest):
def
test_bad_book_id
(
self
):
# If we have one book, asking for the second book will fail with a 404.
course
=
self
.
make_course
(
pdf_textbooks
=
[
PDF_BOOK
])
url
=
reverse
(
'pdf_book'
,
kwargs
=
{
'course_id'
:
course
.
id
,
'book_index'
:
1
,
'chapter'
:
1
}
)
self
.
make_course
(
pdf_textbooks
=
[
PDF_BOOK
])
url
=
self
.
make_url
(
'pdf_book'
,
book_index
=
1
,
chapter
=
1
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
404
)
def
test_no_book
(
self
):
# If we have no books, asking for the first book will fail with a 404.
course
=
self
.
make_course
()
url
=
reverse
(
'pdf_book'
,
kwargs
=
{
'course_id'
:
course
.
id
,
'book_index'
:
0
,
'chapter'
:
1
}
)
self
.
make_course
()
url
=
self
.
make_url
(
'pdf_book'
,
book_index
=
0
,
chapter
=
1
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
404
)
...
...
@@ -109,30 +123,30 @@ class StaticHtmlBookTest(StaticBookTest):
def
test_book
(
self
):
# We can access a book.
course
=
self
.
make_course
(
html_textbooks
=
[
HTML_BOOK
])
url
=
reverse
(
'html_book'
,
kwargs
=
{
'course_id'
:
course
.
id
,
'book_index'
:
0
}
)
self
.
make_course
(
html_textbooks
=
[
HTML_BOOK
])
url
=
self
.
make_url
(
'html_book'
,
book_index
=
0
)
response
=
self
.
client
.
get
(
url
)
self
.
assertContains
(
response
,
"Chapter 1 for HTML"
)
self
.
assertNotContains
(
response
,
"options.chapterNum ="
)
def
test_book_chapter
(
self
):
# We can access a book at a particular chapter.
course
=
self
.
make_course
(
html_textbooks
=
[
HTML_BOOK
])
url
=
reverse
(
'html_book'
,
kwargs
=
{
'course_id'
:
course
.
id
,
'book_index'
:
0
,
'chapter'
:
2
}
)
self
.
make_course
(
html_textbooks
=
[
HTML_BOOK
])
url
=
self
.
make_url
(
'html_book'
,
book_index
=
0
,
chapter
=
2
)
response
=
self
.
client
.
get
(
url
)
self
.
assertContains
(
response
,
"Chapter 2 for HTML"
)
self
.
assertContains
(
response
,
"options.chapterNum = 2;"
)
def
test_bad_book_id
(
self
):
# If we have one book, asking for the second book will fail with a 404.
course
=
self
.
make_course
(
html_textbooks
=
[
HTML_BOOK
])
url
=
reverse
(
'html_book'
,
kwargs
=
{
'course_id'
:
course
.
id
,
'book_index'
:
1
,
'chapter'
:
1
}
)
self
.
make_course
(
html_textbooks
=
[
HTML_BOOK
])
url
=
self
.
make_url
(
'html_book'
,
book_index
=
1
,
chapter
=
1
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
404
)
def
test_no_book
(
self
):
# If we have no books, asking for the first book will fail with a 404.
course
=
self
.
make_course
()
url
=
reverse
(
'html_book'
,
kwargs
=
{
'course_id'
:
course
.
id
,
'book_index'
:
0
,
'chapter'
:
1
}
)
self
.
make_course
()
url
=
self
.
make_url
(
'html_book'
,
book_index
=
0
,
chapter
=
1
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
404
)
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