Ejemplo n.º 1
0
    def run_validation(self, value):
        if not isinstance(value, (list, tuple)):
            raise ValidationError(
                'Invalid Plugins configuration. Expected a list of plugins', )
        plgins = plugins.PluginCollection()
        for item in value:
            if isinstance(item, dict):
                if len(item) > 1:
                    raise ValidationError('Invalid Plugins configuration')
                name, cfg = item.popitem()
                cfg = cfg or {}  # Users may define a null (None) config
                if not isinstance(cfg, dict):
                    raise ValidationError(
                        'Invalid config options for '
                        'the "{}" plugin.'.format(name), )
                item = name
            else:
                cfg = {}

            if not isinstance(item, str):
                raise ValidationError('Invalid Plugins configuration')

            plgins[item] = self.load_plugin(item, cfg)

        return plgins
Ejemplo n.º 2
0
 def test_set_plugin_on_collection(self):
     collection = plugins.PluginCollection()
     plugin = DummyPlugin()
     collection['foo'] = plugin
     self.assertEqual(
         [(k, v) for k, v in collection.items()],
         [('foo', plugin)],
     )
Ejemplo n.º 3
0
 def test_run_unknown_event_on_collection(self):
     collection = plugins.PluginCollection()
     self.assertRaises(
         KeyError,
         collection.run_event,
         'unknown',
         'page content',
     )
Ejemplo n.º 4
0
 def test_run_undefined_event_on_collection(self):
     collection = plugins.PluginCollection()
     self.assertEqual(
         collection.run_event(
             'pre_page',
             'page content',
         ),
         'page content',
     )
Ejemplo n.º 5
0
 def test_event_empty_item(self):
     collection = plugins.PluginCollection()
     plugin = DummyPlugin()
     plugin.load_config({'foo': 'new'})
     collection['foo'] = plugin
     self.assertEqual(
         collection.run_event('page_read_source', ),
         'new source',
     )
Ejemplo n.º 6
0
 def test_run_event_twice_on_collection(self):
     collection = plugins.PluginCollection()
     plugin1 = DummyPlugin()
     plugin1.load_config({'foo': 'new'})
     collection['foo'] = plugin1
     plugin2 = DummyPlugin()
     plugin2.load_config({'foo': 'second'})
     collection['bar'] = plugin2
     self.assertEqual(
         collection.run_event('pre_page', 'page content'),
         'second new page content',
     )
Ejemplo n.º 7
0
 def test_run_event_on_collection(self):
     collection = plugins.PluginCollection()
     plugin = DummyPlugin()
     plugin.load_config({'foo': 'new'})
     collection['foo'] = plugin
     self.assertEqual(
         collection.run_event(
             'pre_page',
             'page content',
         ),
         'new page content',
     )
Ejemplo n.º 8
0
 def test_set_multiple_plugins_on_collection(self):
     collection = plugins.PluginCollection()
     plugin1 = DummyPlugin()
     collection['foo'] = plugin1
     plugin2 = DummyPlugin()
     collection['bar'] = plugin2
     self.assertEqual(
         [(k, v) for k, v in collection.items()],
         [
             ('foo', plugin1),
             ('bar', plugin2),
         ],
     )
Ejemplo n.º 9
0
 def test_event_empty_item_returns_None(self):
     collection = plugins.PluginCollection()
     plugin = DummyPlugin()
     plugin.load_config({'foo': 'new'})
     collection['foo'] = plugin
     self.assertEqual(collection.run_event('pre_build'), None)
Ejemplo n.º 10
0
 def test_event_returns_None(self):
     collection = plugins.PluginCollection()
     plugin = DummyPlugin()
     plugin.load_config({'foo': 'new'})
     collection['foo'] = plugin
     self.assertEqual(collection.run_event('nav', 'nav item'), 'nav item')