diff --git a/ckanext/datastore/plugin.py b/ckanext/datastore/plugin.py index d7546a52531..5afdd13c788 100644 --- a/ckanext/datastore/plugin.py +++ b/ckanext/datastore/plugin.py @@ -39,6 +39,18 @@ class DatastorePlugin(p.SingletonPlugin): legacy_mode = False resource_show_action = None + def __init__(self, *args, **kwargs): + idatastore_extensions = p.PluginImplementations(interfaces.IDatastore) + idatastore_extensions = idatastore_extensions.extensions() + + if idatastore_extensions and idatastore_extensions[0] != self: + msg = ('The "datastore" extension must be the first IDatastore ' + 'extension loaded. Change the order it is loaded in ' + '"ckan.plugins" in your CKAN .ini file and try again.') + raise DatastoreException(msg) + + super(self.__class__, self).__init__(*args, **kwargs) + def configure(self, config): self.config = config # check for ckan.datastore.write_url and ckan.datastore.read_url diff --git a/ckanext/datastore/tests/test_plugin.py b/ckanext/datastore/tests/test_plugin.py new file mode 100644 index 00000000000..0b97f673066 --- /dev/null +++ b/ckanext/datastore/tests/test_plugin.py @@ -0,0 +1,27 @@ +import nose + +import ckan.plugins as p +import ckanext.datastore.plugin as datastore + + +assert_raises = nose.tools.assert_raises + + +class TestPlugin(object): + @classmethod + def setup(cls): + if p.plugin_loaded('datastore'): + p.unload('datastore') + if p.plugin_loaded('sample_datastore_plugin'): + p.unload('sample_datastore_plugin') + + def test_loading_datastore_first_works(self): + p.load('datastore') + p.load('sample_datastore_plugin') + p.unload('sample_datastore_plugin') + p.unload('datastore') + + def test_loading_datastore_last_doesnt_work(self): + p.load('sample_datastore_plugin') + assert_raises(datastore.DatastoreException, p.load, 'datastore') + p.unload('sample_datastore_plugin')