Commit da50e3fd by E. Kolpakov

Added some safeguards for theme config + tests

parent 51030839
......@@ -122,6 +122,7 @@ class TextThemableXBlockMixin(unittest.TestCase):
patched_resource_loader.assert_called_with(package_name)
@ddt.data(
('dummy_block', ['']),
('dummy_block', ['public/themes/lms.css']),
('other_block', ['public/themes/lms.css', 'public/themes/lms.part2.css']),
('dummy_app.dummy_block', ['typography.css', 'icons.css']),
......@@ -138,3 +139,13 @@ class TextThemableXBlockMixin(unittest.TestCase):
patched_load_unicode.assert_any_call(location)
self.assertEqual(patched_load_unicode.call_count, len(locations))
@ddt.data(None, {}, {'locations': ['red.css']})
def test_invalid_default_theme_config(self, theme_config):
xblock = DummyXBlockWithSettings(self.runtime_mock, scope_ids=Mock())
xblock.default_theme_config = theme_config
self.service_mock.get_settings_bucket = Mock(return_value={})
fragment = MagicMock()
with patch("xblockutils.settings.ResourceLoader.load_unicode") as patched_load_unicode:
xblock.include_theme_files(fragment)
patched_load_unicode.assert_not_called()
......@@ -82,6 +82,10 @@ class ThemableXBlockMixin(object):
Gets theme configuration and renders theme css into fragment
"""
theme = self.get_theme()
theme_package, theme_files = theme['package'], theme['locations']
if not theme or 'package' not in theme:
return
theme_package, theme_files = theme.get('package', None), theme.get('locations', [])
resource_loader = ResourceLoader(theme_package)
for theme_file in theme_files:
fragment.add_css(ResourceLoader(theme_package).load_unicode(theme_file))
fragment.add_css(resource_loader.load_unicode(theme_file))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment