Skip to content

Commit

Permalink
Improve test for openurl - we no longer get the redirect back encoded.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven-Eardley committed Sep 25, 2024
1 parent b66b70a commit 468e5fd
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 81 deletions.
6 changes: 3 additions & 3 deletions doajtest/unit/test_openurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
156 changes: 78 additions & 78 deletions doajtest/unit/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
}
}
}
Expand All @@ -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}

Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions portality/lib/plugin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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

class PluginException(Exception):
pass


def load_class_raw(classpath):
modpath = ".".join(classpath.split(".")[:-1])
classname = classpath.split(".")[-1]
Expand All @@ -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)
Expand All @@ -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]
Expand All @@ -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))
Expand Down

0 comments on commit 468e5fd

Please sign in to comment.