-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds student_view_data to Image Explorer Block
adds student_view_data tests bump version
- Loading branch information
Showing
5 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import unittest | ||
from lxml import etree | ||
|
||
from xblock.field_data import DictFieldData | ||
|
||
from image_explorer.image_explorer import ImageExplorerBlock | ||
from ..utils import MockRuntime | ||
|
||
class TestImageExplorerBlock(unittest.TestCase): | ||
""" | ||
Tests for XBlock Image Explorer. | ||
""" | ||
def setUp(self): | ||
""" | ||
Test case setup | ||
""" | ||
super(TestImageExplorerBlock, self).setUp() | ||
self.runtime = MockRuntime() | ||
self.image_url = 'http://example.com/test.jpg' | ||
self.image_explorer_description = '<p>Test Descrption</p>' | ||
self.image_explorer_xml = """ | ||
<image_explorer schema_version='1'> | ||
<background src='{0}' /> | ||
<description>{1}</description> | ||
<hotspots> | ||
<hotspot x='370' y='20' item-id='hotspotA'> | ||
<feedback width='300' height='240'> | ||
<header><p>Test Header</p></header> | ||
<body><p>Test Body</p></body> | ||
</feedback> | ||
</hotspot> | ||
</hotspots> | ||
</image_explorer> | ||
""".format(self.image_url, self.image_explorer_description) | ||
|
||
self.image_explorer_data = {'data': self.image_explorer_xml} | ||
self.image_explorer_block = ImageExplorerBlock( | ||
self.runtime, | ||
DictFieldData(self.image_explorer_data), | ||
None | ||
) | ||
|
||
def test_student_view_data(self): | ||
""" | ||
Test the student_view_data results. | ||
""" | ||
xmltree = etree.fromstring(self.image_explorer_xml) | ||
hotspots = self.image_explorer_block._get_hotspots(xmltree) | ||
expected_image_explorer_data = { | ||
'description': self.image_explorer_description, | ||
'background': { | ||
'src': self.image_url, | ||
'height': None, | ||
'width': None | ||
}, | ||
'hotspots': hotspots, | ||
} | ||
|
||
student_view_data = self.image_explorer_block.student_view_data() | ||
self.assertEqual(student_view_data, expected_image_explorer_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Test mocks and helpers | ||
from xblock.runtime import DictKeyValueStore, KvsFieldData | ||
from xblock.test.tools import TestRuntime | ||
|
||
|
||
class MockRuntime(TestRuntime): | ||
""" | ||
Provides a mock XBlock runtime object. | ||
""" | ||
def __init__(self, **kwargs): | ||
field_data = kwargs.get('field_data', KvsFieldData(DictKeyValueStore())) | ||
super(MockRuntime, self).__init__(field_data=field_data) |