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
8d62fa14
Commit
8d62fa14
authored
Nov 21, 2013
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests for LMS-1532
parent
8d01a36e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
12 deletions
+73
-12
common/lib/xmodule/xmodule/tests/test_error_module.py
+73
-12
No files found.
common/lib/xmodule/xmodule/tests/test_error_module.py
View file @
8d62fa14
...
...
@@ -3,10 +3,13 @@ Tests for ErrorModule and NonStaffErrorModule
"""
import
unittest
from
xmodule.tests
import
get_test_system
import
xmodule.error_module
as
error_module
from
xmodule.error_module
import
ErrorDescriptor
,
ErrorModule
,
NonStaffErrorDescriptor
from
xmodule.modulestore
import
Location
from
xmodule.x_module
import
XModuleDescriptor
from
mock
import
MagicMock
from
xmodule.x_module
import
XModuleDescriptor
,
XModule
from
mock
import
MagicMock
,
Mock
,
patch
from
xblock.runtime
import
Runtime
,
UsageStore
from
xblock.field_data
import
FieldData
from
xblock.fields
import
ScopeIds
class
SetupTestErrorModules
():
...
...
@@ -27,9 +30,9 @@ class TestErrorModule(unittest.TestCase, SetupTestErrorModules):
SetupTestErrorModules
.
setUp
(
self
)
def
test_error_module_xml_rendering
(
self
):
descriptor
=
error_module
.
ErrorDescriptor
.
from_xml
(
descriptor
=
ErrorDescriptor
.
from_xml
(
self
.
valid_xml
,
self
.
system
,
self
.
org
,
self
.
course
,
self
.
error_msg
)
self
.
assertIsInstance
(
descriptor
,
error_module
.
ErrorDescriptor
)
self
.
assertIsInstance
(
descriptor
,
ErrorDescriptor
)
descriptor
.
xmodule_runtime
=
self
.
system
context_repr
=
self
.
system
.
render
(
descriptor
,
'student_view'
)
.
content
self
.
assertIn
(
self
.
error_msg
,
context_repr
)
...
...
@@ -41,9 +44,9 @@ class TestErrorModule(unittest.TestCase, SetupTestErrorModules):
location
=
self
.
location
,
_field_data
=
self
.
valid_xml
)
error_descriptor
=
error_module
.
ErrorDescriptor
.
from_descriptor
(
error_descriptor
=
ErrorDescriptor
.
from_descriptor
(
descriptor
,
self
.
error_msg
)
self
.
assertIsInstance
(
error_descriptor
,
error_module
.
ErrorDescriptor
)
self
.
assertIsInstance
(
error_descriptor
,
ErrorDescriptor
)
error_descriptor
.
xmodule_runtime
=
self
.
system
context_repr
=
self
.
system
.
render
(
error_descriptor
,
'student_view'
)
.
content
self
.
assertIn
(
self
.
error_msg
,
context_repr
)
...
...
@@ -58,12 +61,12 @@ class TestNonStaffErrorModule(unittest.TestCase, SetupTestErrorModules):
SetupTestErrorModules
.
setUp
(
self
)
def
test_non_staff_error_module_create
(
self
):
descriptor
=
error_module
.
NonStaffErrorDescriptor
.
from_xml
(
descriptor
=
NonStaffErrorDescriptor
.
from_xml
(
self
.
valid_xml
,
self
.
system
,
self
.
org
,
self
.
course
)
self
.
assertIsInstance
(
descriptor
,
error_module
.
NonStaffErrorDescriptor
)
self
.
assertIsInstance
(
descriptor
,
NonStaffErrorDescriptor
)
def
test_from_xml_render
(
self
):
descriptor
=
error_module
.
NonStaffErrorDescriptor
.
from_xml
(
descriptor
=
NonStaffErrorDescriptor
.
from_xml
(
self
.
valid_xml
,
self
.
system
,
self
.
org
,
self
.
course
)
descriptor
.
xmodule_runtime
=
self
.
system
context_repr
=
self
.
system
.
render
(
descriptor
,
'student_view'
)
.
content
...
...
@@ -76,10 +79,68 @@ class TestNonStaffErrorModule(unittest.TestCase, SetupTestErrorModules):
location
=
self
.
location
,
_field_data
=
self
.
valid_xml
)
error_descriptor
=
error_module
.
NonStaffErrorDescriptor
.
from_descriptor
(
error_descriptor
=
NonStaffErrorDescriptor
.
from_descriptor
(
descriptor
,
self
.
error_msg
)
self
.
assertIsInstance
(
error_descriptor
,
error_module
.
ErrorDescriptor
)
self
.
assertIsInstance
(
error_descriptor
,
ErrorDescriptor
)
error_descriptor
.
xmodule_runtime
=
self
.
system
context_repr
=
self
.
system
.
render
(
error_descriptor
,
'student_view'
)
.
content
self
.
assertNotIn
(
self
.
error_msg
,
context_repr
)
self
.
assertNotIn
(
str
(
descriptor
),
context_repr
)
class
BrokenModule
(
XModule
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
BrokenModule
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
raise
Exception
(
"This is a broken xmodule"
)
class
BrokenDescriptor
(
XModuleDescriptor
):
module_class
=
BrokenModule
class
TestException
(
Exception
):
"""An exception type to use to verify raises in tests"""
pass
class
TestErrorModuleConstruction
(
unittest
.
TestCase
):
"""
Test that error module construction happens correctly
"""
def
setUp
(
self
):
field_data
=
Mock
(
spec
=
FieldData
)
self
.
descriptor
=
BrokenDescriptor
(
Runtime
(
Mock
(
spec
=
UsageStore
),
field_data
),
field_data
,
ScopeIds
(
None
,
None
,
None
,
'i4x://org/course/broken/name'
)
)
self
.
descriptor
.
xmodule_runtime
=
Runtime
(
Mock
(
spec
=
UsageStore
),
field_data
)
self
.
descriptor
.
xmodule_runtime
.
error_descriptor_class
=
ErrorDescriptor
self
.
descriptor
.
xmodule_runtime
.
xmodule_instance
=
None
@unittest.expectedFailure
def
test_broken_module
(
self
):
"""
Test that when an XModule throws an error during __init__, we
get an ErrorModule back from XModuleDescriptor._xmodule
"""
module
=
self
.
descriptor
.
_xmodule
self
.
assertIsInstance
(
module
,
ErrorModule
)
@patch.object
(
ErrorDescriptor
,
'__init__'
,
Mock
(
side_effect
=
TestException
))
def
test_broken_error_descriptor
(
self
):
"""
Test that a broken error descriptor doesn't cause an infinite loop
"""
with
self
.
assertRaises
(
TestException
):
module
=
self
.
descriptor
.
_xmodule
@unittest.expectedFailure
@patch.object
(
ErrorModule
,
'__init__'
,
Mock
(
side_effect
=
TestException
))
def
test_broken_error_module
(
self
):
"""
Test that a broken error module doesn't cause an infinite loop
"""
with
self
.
assertRaises
(
TestException
):
module
=
self
.
descriptor
.
_xmodule
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