def test_import_module_raises_improperly_configured(self): """We can only import attributes from modules, not modules directly""" with self.assertRaises(ImproperlyConfigured) as cm: import_element('fiber') self.assertEqual( str(cm.exception), 'Error importing fiber: fiber doesn\'t look like a module path')
def test_import_invalid_module_raises_improperly_configured(self): """Fail trying to import a missing module""" with self.assertRaises(ImproperlyConfigured) as cm: import_element("fiber.missing_module.missing_attribute") self.assertEqual( str(cm.exception), "Error importing fiber.missing_module.missing_attribute: No module named missing_module" )
def test_import_invalid_module_raises_improperly_configured(self): """Fail trying to import a missing module""" with self.assertRaises(ImproperlyConfigured) as cm: import_element('fiber.missing_module.missing_attribute') self.assertRegexpMatches( str(cm.exception), r'Error importing fiber.missing_module.missing_attribute: No module named .+' )
def test_import_invalid_attribute_raises_improperly_configured(self): """Fail trying to import a missing attribute""" with self.assertRaises(ImproperlyConfigured) as cm: import_element("fiber.missing_attribute") self.assertEqual( str(cm.exception), 'Error importing fiber.missing_attribute: Module "fiber.missing_attribute" does not define a "missing_attribute" attribute/class', )
def test_import_invalid_attribute_raises_improperly_configured(self): """Fail trying to import a missing attribute""" with self.assertRaises(ImproperlyConfigured) as cm: import_element('fiber.missing_attribute') msgs = [ 'Error importing fiber.missing_attribute: Module "fiber.missing_attribute" does not define a "missing_attribute" attribute/class', 'Error importing fiber.missing_attribute: Module "fiber" does not define a "missing_attribute" attribute/class', # Django 1.8 and later ] self.assertIn(str(cm.exception), msgs)
def __init__(self, *args, **kwargs): super(AdminPageMiddleware, self).__init__(*args, **kwargs) self.editor_settings = import_element(EDITOR)
def __init__(self): self.editor_settings = import_element(EDITOR)
from fiber.utils.import_util import import_element from fiber.app_settings import EDITOR editor = import_element(EDITOR) renderer = editor.get('renderer', None) def get_editor_field_name(html_field_name): """ Returns markup or html field name, depending on editor. Input is html field_name: get_editor_field_name('content_html') returns: 'content_html' or 'content_markup' """ if renderer: return html_field_name.replace('_html', '_markup') else: return html_field_name
def test_import_module_raises_improperly_configured(self): """We can only import attributes from modules, not modules directly""" with self.assertRaises(ImproperlyConfigured) as cm: import_element('fiber') self.assertEqual(str(cm.exception), 'Error importing fiber: fiber doesn\'t look like a module path')
def test_import_element(self): """Import TestClass by name""" path = '.'.join([self.__module__, 'TestClass']) self.assertEqual(import_element(path), TestClass)
from fiber.app_settings import EDITOR from fiber.utils.import_util import import_element editor = import_element(EDITOR) renderer = editor.get('renderer', None) def get_editor_field_name(html_field_name): """ Returns markup or html field name, depending on editor. Input is html field_name: get_editor_field_name('content_html') returns: 'content_html' or 'content_markup' """ if renderer: return html_field_name.replace('_html', '_markup') else: return html_field_name