Commits

Anonymous committed 3bc74c1

[plugins] Added test for plugin loading order

Comments (0)

Files changed (4)

ckan/tests/ckantestplugin/ckantestplugin.egg-info/entry_points.txt

 routes_plugin = ckantestplugin:RoutesPlugin
 mapper_plugin2 = ckantestplugin:MapperPlugin2
 mapper_plugin = ckantestplugin:MapperPlugin
+test_observer_plugin = ckantestplugin:PluginObserverPlugin
 

ckan/tests/ckantestplugin/ckantestplugin/__init__.py

-from ckan.plugins import SingletonPlugin, IMapperExtension, IRoutesExtension, implements
+from ckan.plugins import SingletonPlugin, implements
+from ckan.plugins import IMapperExtension, IRoutesExtension, IPluginObserver
+from ckan.tests.mock_plugin import MockSingletonPlugin
+
 
 class MapperPlugin(SingletonPlugin):
     implements(IMapperExtension, inherit=True)
     def after_add(self, map):
         self.calls_made.append('after_add')
         return map
+    
+class PluginObserverPlugin(MockSingletonPlugin):
+    implements(IPluginObserver)

ckan/tests/ckantestplugin/setup.py

             'routes_plugin=ckantestplugin:RoutesPlugin',
             'mapper_plugin=ckantestplugin:MapperPlugin',
             'mapper_plugin2=ckantestplugin:MapperPlugin2',
+            'test_observer_plugin=ckantestplugin:PluginObserverPlugin',
         ]
     }
 )

ckan/tests/test_plugins.py

         assert MapperPlugin2() not in iter(PluginMapperExtension.observers)
         assert RoutesPlugin() not in routing_plugins
 
+    def test_plugin_loading_order(self):
+        """
+        Check that plugins are loaded in the order specified in the config
+        """
+        from ckantestplugin import MapperPlugin, MapperPlugin2, PluginObserverPlugin
+
+        observerplugin = PluginObserverPlugin()
+
+        config['ckan.plugins'] = 'test_observer_plugin mapper_plugin mapper_plugin2'
+        expected_order = MapperPlugin, MapperPlugin2
+
+        plugins.load_all(config)
+        assert observerplugin.before_load.calls == [((p,), {}) for p in expected_order]
+        assert observerplugin.after_load.calls == [((p.__instance__,), {}) for p in (observerplugin,) + expected_order]
+
+        config['ckan.plugins'] = 'test_observer_plugin mapper_plugin2 mapper_plugin'
+        expected_order = MapperPlugin2, MapperPlugin
+        observerplugin.reset_calls()
+
+        plugins.load_all(config)
+        assert observerplugin.before_load.calls == [((p,), {}) for p in expected_order]
+        assert observerplugin.after_load.calls == [((p.__instance__,), {}) for p in (observerplugin,) + expected_order]
+
     def test_mapper_plugin_fired(self):
         config['ckan.plugins'] = 'mapper_plugin'
         plugins.load_all(config)