diff --git a/doajtest/unit/test_openurl.py b/doajtest/unit/test_openurl.py index 08bed5dc6..e47e71a8b 100644 --- a/doajtest/unit/test_openurl.py +++ b/doajtest/unit/test_openurl.py @@ -6,9 +6,9 @@ from portality import app, models from urllib.parse import urlparse -QUERY = 'url_ver=Z39.88-2004' \ - '&url_ctx_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Actx' \ - '&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal' +QUERY = ('url_ver=Z39.88-2004' + '&url_ctx_fmt=info:ofi/fmt:kev:mtx:ctx' + '&rft_val_fmt=info:ofi/fmt:kev:mtx:journal') class TestOpenURL(DoajTestCase): diff --git a/doajtest/unit/test_query.py b/doajtest/unit/test_query.py index 4b853c65d..0779449fa 100644 --- a/doajtest/unit/test_query.py +++ b/doajtest/unit/test_query.py @@ -11,68 +11,68 @@ from portality.bll import exceptions QUERY_ROUTE = { - "query" : { - "article" : { - "auth" : False, - "role" : None, - "query_filters" : ["only_in_doaj"], - "result_filters" : ["public_result_filter"], - "dao" : "portality.models.Article" + "query": { + "article": { + "auth": False, + "role": None, + "query_filters": ["only_in_doaj"], + "result_filters": ["public_result_filter"], + "dao": "portality.models.Article" } }, - "publisher_query" : { - "journal" : { - "auth" : True, - "role" : "publisher", - "query_filters" : ["owner", "only_in_doaj"], - "result_filters" : ["publisher_result_filter"], - "dao" : "portality.models.Journal" + "publisher_query": { + "journal": { + "auth": True, + "role": "publisher", + "query_filters": ["owner", "only_in_doaj"], + "result_filters": ["publisher_result_filter"], + "dao": "portality.models.Journal" } }, - "admin_query" : { - "journal" : { - "auth" : True, - "role" : "admin", - "dao" : "portality.models.Journal" + "admin_query": { + "journal": { + "auth": True, + "role": "admin", + "dao": "portality.models.Journal" }, - "suggestion" : { - "auth" : True, - "role" : "admin", - "dao" : "portality.models.Application" + "suggestion": { + "auth": True, + "role": "admin", + "dao": "portality.models.Application" }, }, - "api_query" : { - "article" : { - "auth" : False, - "role" : None, - "query_filters" : ["only_in_doaj", "public_source"], - "result_filters" : ["public_result_filter"], - "dao" : "portality.models.Article", - "page_size" : 1 + "api_query": { + "article": { + "auth": False, + "role": None, + "query_filters": ["only_in_doaj", "public_source"], + "result_filters": ["public_result_filter"], + "dao": "portality.models.Article", + "page_size": 1 }, - "journal" : { - "auth" : False, - "role" : None, - "query_filters" : ["only_in_doaj", "public_source"], - "dao" : "portality.models.Journal" + "journal": { + "auth": False, + "role": None, + "query_filters": ["only_in_doaj", "public_source"], + "dao": "portality.models.Journal" }, - "suggestion" : { - "auth" : True, - "role" : None, - "query_filters" : ["owner", "private_source"], - "dao" : "portality.models.Suggestion" + "suggestion": { + "auth": True, + "role": None, + "query_filters": ["owner", "private_source"], + "dao": "portality.models.Suggestion" } }, - "editor_query" : { - "journal" : { - "auth" : True, - "role" : "editor", - "dao" : "portality.models.Journal" + "editor_query": { + "journal": { + "auth": True, + "role": "editor", + "dao": "portality.models.Journal" }, - "suggestion" : { - "auth" : True, - "role" : "editor", - "dao" : "portality.models.Application" + "suggestion": { + "auth": True, + "role": "editor", + "dao": "portality.models.Application" } }, "associate_query": { @@ -81,49 +81,49 @@ "role": "associate_editor", "dao": "portality.models.Journal" }, - "suggestion" : { - "auth" : True, - "role" : "associate_editor", - "dao" : "portality.models.Application" + "suggestion": { + "auth": True, + "role": "associate_editor", + "dao": "portality.models.Application" } } } SEARCH_ALL_QUERY_ROUTE = { - "query" : { - "journal" : { - "auth" : False, - "role" : None, - "query_filters" : ["search_all_meta"], - "dao" : "portality.models.Journal" + "query": { + "journal": { + "auth": False, + "role": None, + "query_filters": ["search_all_meta"], + "dao": "portality.models.Journal" } }, - "editor_query" : { - "journal" : { - "auth" : True, - "role" : "editor", - "query_filters" : ["search_all_meta"], - "dao" : "portality.models.Journal" + "editor_query": { + "journal": { + "auth": True, + "role": "editor", + "query_filters": ["search_all_meta"], + "dao": "portality.models.Journal" }, - "suggestion" : { - "auth" : False, - "role" : "editor", - "query_filters" : ["search_all_meta"], - "dao" : "portality.models.Application" + "suggestion": { + "auth": False, + "role": "editor", + "query_filters": ["search_all_meta"], + "dao": "portality.models.Application" } }, "associate_query": { "journal": { "auth": False, "role": "associate_editor", - "query_filters" : ["search_all_meta"], + "query_filters": ["search_all_meta"], "dao": "portality.models.Journal" }, - "suggestion" : { - "auth" : False, - "role" : "associate_editor", - "query_filters" : ["search_all_meta"], - "dao" : "portality.models.Application" + "suggestion": { + "auth": False, + "role": "associate_editor", + "query_filters": ["search_all_meta"], + "dao": "portality.models.Application" } } } @@ -147,6 +147,7 @@ "search_all_meta" : "portality.lib.query_filters.search_all_meta", } + def without_keys(d, keys): return {x: d[x] for x in d if x not in keys} @@ -248,7 +249,6 @@ def test_02_query_gen(self): q.add_include(["last_updated", "id"]) assert sorted(q.as_dict()) == sorted({'track_total_hits' : True, "query": {"match_all": {}},"_source": {"includes": ["last_updated", "id"]}}) or sorted(q.as_dict()) == sorted({"query": {"match_all": {}},"_source": {"include": ["last_updated", "id"]}}), sorted(q.as_dict()) - def test_03_query_svc_get_config(self): qsvc = QueryService() cfg = qsvc._get_config_for_search('query', 'article', account=None) diff --git a/portality/lib/plugin.py b/portality/lib/plugin.py index b826cd042..848ee95de 100644 --- a/portality/lib/plugin.py +++ b/portality/lib/plugin.py @@ -1,5 +1,6 @@ import importlib + # Note that we delay import of app to the functions which need it, # since we may want to load plugins during app creation too, and otherwise # we'd get circular import problems @@ -7,6 +8,7 @@ class PluginException(Exception): pass + def load_class_raw(classpath): modpath = ".".join(classpath.split(".")[:-1]) classname = classpath.split(".")[-1] @@ -17,6 +19,7 @@ def load_class_raw(classpath): klazz = getattr(mod, classname, None) return klazz + def load_class(classpath, cache_class_ref=True): from portality.core import app klazz = app.config.get("PLUGIN_CLASS_REFS", {}).get(classpath) @@ -35,9 +38,11 @@ def load_class(classpath, cache_class_ref=True): return klazz + def load_module(modpath): return importlib.import_module(modpath) + def load_function_raw(fnpath): modpath = ".".join(fnpath.split(".")[:-1]) fnname = fnpath.split(".")[-1] @@ -48,12 +53,16 @@ def load_function_raw(fnpath): fn = getattr(mod, fnname, None) return fn + def load_function(fnpath, cache_fn_ref=True): from portality.core import app fn = app.config.get("PLUGIN_FN_REFS", {}).get(fnpath) if fn is not None: return fn + if isinstance(fnpath, str): + print(type(fnpath)) + fn = load_function_raw(fnpath) if fn is None: app.logger.info("Could not load function {x}".format(x=fnpath))