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
84edced1
Commit
84edced1
authored
Jan 08, 2015
by
E. Kolpakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Render tests for library content block preview and author views
parent
d0919c93
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
20 deletions
+61
-20
common/lib/xmodule/xmodule/tests/test_library_content.py
+47
-5
common/lib/xmodule/xmodule/tests/test_library_root.py
+14
-15
No files found.
common/lib/xmodule/xmodule/tests/test_library_content.py
View file @
84edced1
...
...
@@ -5,6 +5,12 @@ Basic unit tests for LibraryContentModule
Higher-level tests are in `cms/djangoapps/contentstore/tests/test_libraries.py`.
"""
import
ddt
from
mock
import
patch
from
xblock.fragment
import
Fragment
from
xblock.runtime
import
Runtime
as
VanillaRuntime
from
xmodule.x_module
import
AUTHOR_VIEW
,
STUDENT_VIEW
from
xmodule.library_content_module
import
LibraryVersionReference
,
ANY_CAPA_TYPE_VALUE
,
LibraryContentDescriptor
from
xmodule.modulestore.tests.factories
import
LibraryFactory
,
CourseFactory
,
ItemFactory
from
xmodule.modulestore.tests.utils
import
MixedSplitTestCase
...
...
@@ -12,13 +18,15 @@ from xmodule.tests import get_test_system
from
xmodule.validation
import
StudioValidationMessage
@ddt.ddt
class
TestLibraries
(
MixedSplitTestCase
):
_dummy_render
=
lambda
block
,
_
:
Fragment
(
block
.
data
)
class
BaseTestLibraryContainer
(
MixedSplitTestCase
):
"""
Bas
ic unit tests for LibraryContentModule (library_content_module.py)
Bas
e class for TestLibraryContainer and TestLibraryContainerRender
"""
def
setUp
(
self
):
super
(
TestLibraries
,
self
)
.
setUp
()
super
(
BaseTestLibraryContainer
,
self
)
.
setUp
()
self
.
library
=
LibraryFactory
.
create
(
modulestore
=
self
.
store
)
self
.
lib_blocks
=
[
...
...
@@ -62,7 +70,7 @@ class TestLibraries(MixedSplitTestCase):
}
)
def
_bind_course_module
(
self
,
module
):
def
_bind_course_module
(
self
,
module
,
render
=
None
):
"""
Bind a module (part of self.course) so we can access student-specific data.
"""
...
...
@@ -108,6 +116,11 @@ class TestLibraries(MixedSplitTestCase):
modulestore
=
self
.
store
,
)
@ddt.ddt
class
TestLibraryContainer
(
BaseTestLibraryContainer
):
"""
Basic unit tests for LibraryContentModule (library_content_module.py)
"""
def
test_lib_content_block
(
self
):
"""
Test that blocks from a library are copied and added as children
...
...
@@ -250,3 +263,31 @@ class TestLibraries(MixedSplitTestCase):
non_editable_metadata_fields
=
self
.
lc_block
.
non_editable_metadata_fields
self
.
assertIn
(
LibraryContentDescriptor
.
mode
,
non_editable_metadata_fields
)
self
.
assertNotIn
(
LibraryContentDescriptor
.
display_name
,
non_editable_metadata_fields
)
@patch
(
'xmodule.modulestore.split_mongo.caching_descriptor_system.CachingDescriptorSystem.render'
,
VanillaRuntime
.
render
)
@patch
(
'xmodule.html_module.HtmlModule.author_view'
,
_dummy_render
,
create
=
True
)
@patch
(
'xmodule.html_module.HtmlModule.student_view'
,
_dummy_render
,
create
=
True
)
@patch
(
'xmodule.x_module.DescriptorSystem.applicable_aside_types'
,
lambda
self
,
block
:
[])
class
TestLibraryContentRender
(
BaseTestLibraryContainer
):
"""
Rendering unit tests for LibraryContentModule (library_content_module.py)
"""
def
test_preivew_view
(
self
):
""" Test preview view rendering """
self
.
lc_block
.
refresh_children
()
self
.
lc_block
=
self
.
store
.
get_item
(
self
.
lc_block
.
location
)
self
.
assertEqual
(
len
(
self
.
lc_block
.
children
),
len
(
self
.
lib_blocks
))
self
.
_bind_course_module
(
self
.
lc_block
)
rendered
=
self
.
lc_block
.
render
(
AUTHOR_VIEW
,
{
'root_xblock'
:
self
.
lc_block
})
self
.
assertIn
(
"Hello world from block 1"
,
rendered
.
content
)
def
test_author_view
(
self
):
""" Test author view rendering """
self
.
lc_block
.
refresh_children
()
self
.
lc_block
=
self
.
store
.
get_item
(
self
.
lc_block
.
location
)
self
.
assertEqual
(
len
(
self
.
lc_block
.
children
),
len
(
self
.
lib_blocks
))
self
.
_bind_course_module
(
self
.
lc_block
)
rendered
=
self
.
lc_block
.
render
(
AUTHOR_VIEW
,
{})
self
.
assertEqual
(
""
,
rendered
.
content
)
# content should be empty
self
.
assertEqual
(
"LibraryContentAuthorView"
,
rendered
.
js_init_fn
)
# but some js initialization should happen
\ No newline at end of file
common/lib/xmodule/xmodule/tests/test_library_root.py
View file @
84edced1
...
...
@@ -7,9 +7,13 @@ from xmodule.x_module import AUTHOR_VIEW
from
xmodule.modulestore.tests.factories
import
LibraryFactory
,
CourseFactory
,
ItemFactory
from
xmodule.modulestore.tests.utils
import
MixedSplitTestCase
_dummy_render
=
lambda
block
,
_
:
Fragment
(
block
.
data
)
@patch
(
'xmodule.modulestore.split_mongo.caching_descriptor_system.CachingDescriptorSystem.render'
,
VanillaRuntime
.
render
)
@patch
(
'xmodule.html_module.HtmlDescriptor.author_view'
,
_dummy_render
,
create
=
True
)
@patch
(
'xmodule.x_module.DescriptorSystem.applicable_aside_types'
,
lambda
self
,
block
:
[])
class
TestLibraryRoot
(
MixedSplitTestCase
):
@patch
(
'xmodule.modulestore.split_mongo.caching_descriptor_system.CachingDescriptorSystem.render'
,
VanillaRuntime
.
render
)
def
test_library_author_view
(
self
):
"""
Test that LibraryRoot.author_view can run and includes content from its
...
...
@@ -17,6 +21,7 @@ class TestLibraryRoot(MixedSplitTestCase):
We have to patch the runtime (module system) in order to be able to
render blocks in our test environment.
"""
message
=
u"Hello world"
library
=
LibraryFactory
.
create
(
modulestore
=
self
.
store
)
# Add one HTML block to the library:
ItemFactory
.
create
(
...
...
@@ -25,19 +30,16 @@ class TestLibraryRoot(MixedSplitTestCase):
user_id
=
self
.
user_id
,
publish_item
=
False
,
modulestore
=
self
.
store
,
data
=
message
)
library
=
self
.
store
.
get_library
(
library
.
location
.
library_key
)
context
=
{
'reorderable_items'
:
set
(),
}
# Patch the HTML block to always render "Hello world"
message
=
u"Hello world"
hello_render
=
lambda
_
,
context
:
Fragment
(
message
)
with
patch
(
'xmodule.html_module.HtmlDescriptor.author_view'
,
hello_render
,
create
=
True
):
with
patch
(
'xmodule.x_module.DescriptorSystem.applicable_aside_types'
,
lambda
self
,
block
:
[]):
result
=
library
.
render
(
AUTHOR_VIEW
,
context
)
result
=
library
.
render
(
AUTHOR_VIEW
,
context
)
self
.
assertIn
(
message
,
result
.
content
)
@patch
(
'xmodule.modulestore.split_mongo.caching_descriptor_system.CachingDescriptorSystem.render'
,
VanillaRuntime
.
render
)
def
test_library_author_view_with_paging
(
self
):
"""
Test that LibraryRoot.author_view can apply paging
...
...
@@ -67,10 +69,7 @@ class TestLibraryRoot(MixedSplitTestCase):
for
expected_block
in
expected_blocks
:
self
.
assertIn
(
expected_block
.
data
,
result
.
content
)
hello_render
=
lambda
block
,
_
:
Fragment
(
block
.
data
)
with
patch
(
'xmodule.html_module.HtmlDescriptor.author_view'
,
hello_render
,
create
=
True
):
with
patch
(
'xmodule.x_module.DescriptorSystem.applicable_aside_types'
,
lambda
self
,
block
:
[]):
render_and_check_contents
(
0
,
3
)
render_and_check_contents
(
1
,
3
)
render_and_check_contents
(
0
,
2
)
render_and_check_contents
(
1
,
2
)
\ No newline at end of file
render_and_check_contents
(
0
,
3
)
render_and_check_contents
(
1
,
3
)
render_and_check_contents
(
0
,
2
)
render_and_check_contents
(
1
,
2
)
\ No newline at end of file
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