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
8162d547
Commit
8162d547
authored
Feb 26, 2013
by
Arthur Barrett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added more unit tests for module
parent
12b30c1b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
8 deletions
+72
-8
common/lib/xmodule/xmodule/annotatable_module.py
+4
-4
common/lib/xmodule/xmodule/tests/test_annotatable_module.py
+68
-4
No files found.
common/lib/xmodule/xmodule/annotatable_module.py
View file @
8162d547
...
...
@@ -29,14 +29,13 @@ class AnnotatableModule(XModule):
attr
=
{}
cls
=
[
'annotatable-span'
,
'highlight'
]
valid_colors
=
[
'yellow'
,
'orange'
,
'purple'
,
'blue'
,
'green'
]
highlight_key
=
'highlight'
color
=
el
.
get
(
highlight_key
)
if
color
is
not
None
and
color
in
valid_colors
:
if
color
is
not
None
:
if
color
in
self
.
highlight_colors
:
cls
.
append
(
'highlight-'
+
color
)
attr
[
'_delete'
]
=
highlight_key
attr
[
'value'
]
=
' '
.
join
(
cls
)
return
{
'class'
:
attr
}
...
...
@@ -120,6 +119,7 @@ class AnnotatableModule(XModule):
self
.
instructions
=
self
.
_extract_instructions
(
xmltree
)
self
.
content
=
etree
.
tostring
(
xmltree
,
encoding
=
'unicode'
)
self
.
element_id
=
self
.
location
.
html_id
()
self
.
highlight_colors
=
[
'yellow'
,
'orange'
,
'purple'
,
'blue'
,
'green'
]
class
AnnotatableDescriptor
(
RawDescriptor
):
module_class
=
AnnotatableModule
...
...
common/lib/xmodule/xmodule/tests/test_annotatable_module.py
View file @
8162d547
...
...
@@ -45,6 +45,70 @@ class AnnotatableModuleTestCase(unittest.TestCase):
'data-problem-id'
:
{
'value'
:
'0'
,
'_delete'
:
'problem'
}
}
data_attr
=
self
.
annotatable
.
_get_annotation_data_attr
(
0
,
el
)
self
.
assertTrue
(
type
(
data_attr
)
is
dict
)
self
.
assertDictEqual
(
expected_attr
,
data_attr
)
\ No newline at end of file
actual_attr
=
self
.
annotatable
.
_get_annotation_data_attr
(
0
,
el
)
self
.
assertTrue
(
type
(
actual_attr
)
is
dict
)
self
.
assertDictEqual
(
expected_attr
,
actual_attr
)
def
test_annotation_class_attr_default
(
self
):
xml
=
'<annotation title="x" body="y" problem="0">test</annotation>'
el
=
etree
.
fromstring
(
xml
)
expected_attr
=
{
'class'
:
{
'value'
:
'annotatable-span highlight'
}
}
actual_attr
=
self
.
annotatable
.
_get_annotation_class_attr
(
0
,
el
)
self
.
assertTrue
(
type
(
actual_attr
)
is
dict
)
self
.
assertDictEqual
(
expected_attr
,
actual_attr
)
def
test_annotation_class_attr_with_valid_highlight
(
self
):
xml
=
'<annotation title="x" body="y" problem="0" highlight="{highlight}">test</annotation>'
for
color
in
self
.
annotatable
.
highlight_colors
:
el
=
etree
.
fromstring
(
xml
.
format
(
highlight
=
color
))
value
=
'annotatable-span highlight highlight-{highlight}'
.
format
(
highlight
=
color
)
expected_attr
=
{
'class'
:
{
'value'
:
value
,
'_delete'
:
'highlight'
}
}
actual_attr
=
self
.
annotatable
.
_get_annotation_class_attr
(
0
,
el
)
self
.
assertTrue
(
type
(
actual_attr
)
is
dict
)
self
.
assertDictEqual
(
expected_attr
,
actual_attr
)
def
test_annotation_class_attr_with_invalid_highlight
(
self
):
xml
=
'<annotation title="x" body="y" problem="0" highlight="{highlight}">test</annotation>'
for
invalid_color
in
[
'rainbow'
,
'blink'
,
'invisible'
,
''
,
None
]:
el
=
etree
.
fromstring
(
xml
.
format
(
highlight
=
invalid_color
))
expected_attr
=
{
'class'
:
{
'value'
:
'annotatable-span highlight'
,
'_delete'
:
'highlight'
}
}
actual_attr
=
self
.
annotatable
.
_get_annotation_class_attr
(
0
,
el
)
self
.
assertTrue
(
type
(
actual_attr
)
is
dict
)
self
.
assertDictEqual
(
expected_attr
,
actual_attr
)
def
test_render_annotation
(
self
):
expected_html
=
'<span class="annotatable-span highlight highlight-yellow" data-comment-title="x" data-comment-body="y" data-problem-id="0">z</span>'
expected_el
=
etree
.
fromstring
(
expected_html
)
actual_el
=
etree
.
fromstring
(
'<annotation title="x" body="y" problem="0" highlight="yellow">z</annotation>'
)
self
.
annotatable
.
_render_annotation
(
0
,
actual_el
)
self
.
assertEqual
(
expected_el
.
tag
,
actual_el
.
tag
)
self
.
assertEqual
(
expected_el
.
text
,
actual_el
.
text
)
self
.
assertDictEqual
(
dict
(
expected_el
.
attrib
),
dict
(
actual_el
.
attrib
))
def
test_extract_instructions
(
self
):
xmltree
=
etree
.
fromstring
(
self
.
sample_text
)
expected_xml
=
u"<div>Read the text.</div>"
actual_xml
=
self
.
annotatable
.
_extract_instructions
(
xmltree
)
self
.
assertIsNotNone
(
actual_xml
)
self
.
assertEqual
(
expected_xml
.
strip
(),
actual_xml
.
strip
())
xmltree
=
etree
.
fromstring
(
'<annotatable>foo</annotatable>'
)
actual
=
self
.
annotatable
.
_extract_instructions
(
xmltree
)
self
.
assertIsNone
(
actual
)
\ 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