1
0
mirror of https://github.com/ilri/dspace-statistics-api.git synced 2024-11-25 23:58:18 +01:00

dspace_statistics_api/items.py: Move util import

Move util import from global scope because it causes tests to fail.
We don't need the set up the Solr connection unless we're actually
trying to use the get_views and get_downloads methods, either when
running the API in production or during tests where the connection
has been set up.
This commit is contained in:
Alan Orth 2020-10-06 15:07:00 +03:00
parent e6572d9469
commit 58d2b8d4ed
Signed by: alanorth
GPG Key ID: 0FB860CC9C45B1B9

View File

@ -1,7 +1,6 @@
import requests import requests
from .config import SOLR_SERVER from .config import SOLR_SERVER
from .util import get_statistics_shards
def get_views(solr_date_string: str, items: list): def get_views(solr_date_string: str, items: list):
@ -12,6 +11,9 @@ def get_views(solr_date_string: str, items: list):
:parameter items (list): a list of item IDs :parameter items (list): a list of item IDs
:returns: A dict of item IDs and views :returns: A dict of item IDs and views
""" """
from .util import get_statistics_shards
shards = get_statistics_shards()
# Join the UUIDs with "OR" and escape the hyphens for Solr # Join the UUIDs with "OR" and escape the hyphens for Solr
solr_items_string: str = " OR ".join(items).replace("-", r"\-") solr_items_string: str = " OR ".join(items).replace("-", r"\-")
@ -59,6 +61,9 @@ def get_downloads(solr_date_string: str, items: list):
:parameter items (list): a list of item IDs :parameter items (list): a list of item IDs
:returns: A dict of item IDs and downloads :returns: A dict of item IDs and downloads
""" """
from .util import get_statistics_shards
shards = get_statistics_shards()
# Join the UUIDs with "OR" and escape the hyphens for Solr # Join the UUIDs with "OR" and escape the hyphens for Solr
solr_items_string: str = " OR ".join(items).replace("-", r"\-") solr_items_string: str = " OR ".join(items).replace("-", r"\-")
@ -97,7 +102,4 @@ def get_downloads(solr_date_string: str, items: list):
return data return data
shards = get_statistics_shards()
# vim: set sw=4 ts=4 expandtab: # vim: set sw=4 ts=4 expandtab: