From 9d939cba94cb448f4ecb38b06a22d47b55ea260f Mon Sep 17 00:00:00 2001 From: Arthur Barrett Date: Tue, 26 Feb 2013 17:49:18 -0500 Subject: [PATCH] added more unit tests to module --- .../lib/xmodule/xmodule/annotatable_module.py | 2 ++ .../xmodule/tests/test_annotatable_module.py | 21 ++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/common/lib/xmodule/xmodule/annotatable_module.py b/common/lib/xmodule/xmodule/annotatable_module.py index 665be210e4..0cc567f7a1 100644 --- a/common/lib/xmodule/xmodule/annotatable_module.py +++ b/common/lib/xmodule/xmodule/annotatable_module.py @@ -81,6 +81,8 @@ class AnnotatableModule(XModule): """ Renders annotatable content with annotation spans and returns HTML. """ xmltree = etree.fromstring(self.content) xmltree.tag = 'div' + if 'display_name' in xmltree.attrib: + del xmltree.attrib['display_name'] index = 0 for el in xmltree.findall('.//annotation'): diff --git a/common/lib/xmodule/xmodule/tests/test_annotatable_module.py b/common/lib/xmodule/xmodule/tests/test_annotatable_module.py index 3a470879e8..3f9fe349a0 100644 --- a/common/lib/xmodule/xmodule/tests/test_annotatable_module.py +++ b/common/lib/xmodule/xmodule/tests/test_annotatable_module.py @@ -12,7 +12,7 @@ from . import test_system class AnnotatableModuleTestCase(unittest.TestCase): location = Location(["i4x", "edX", "toy", "annotatable", "guided_discussion"]) - sample_text = ''' + sample_xml = ''' Read the text.

@@ -28,7 +28,7 @@ class AnnotatableModuleTestCase(unittest.TestCase): The Iliad of Homer by Samuel Butler ''' - definition = { 'data': sample_text } + definition = { 'data': sample_xml } descriptor = Mock() instance_state = None shared_state = None @@ -101,8 +101,23 @@ class AnnotatableModuleTestCase(unittest.TestCase): self.assertEqual(expected_el.text, actual_el.text) self.assertDictEqual(dict(expected_el.attrib), dict(actual_el.attrib)) + def test_render_content(self): + content = self.annotatable._render_content() + el = etree.fromstring(content) + + self.assertEqual('div', el.tag, 'root tag is a div') + + expected_num_annotations = 5 + actual_num_annotations = el.xpath('count(//span[contains(@class,"annotatable-span")])') + self.assertEqual(expected_num_annotations, actual_num_annotations, 'check number of annotations') + + def test_get_html(self): + context = self.annotatable.get_html() + for key in ['display_name', 'element_id', 'content_html', 'instructions_html']: + self.assertIn(key, context) + def test_extract_instructions(self): - xmltree = etree.fromstring(self.sample_text) + xmltree = etree.fromstring(self.sample_xml) expected_xml = u"

Read the text.
" actual_xml = self.annotatable._extract_instructions(xmltree)