From 58d2b8d4edeb8503d9df807b7fafac0e08a89256 Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Tue, 6 Oct 2020 15:07:00 +0300 Subject: [PATCH] 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. --- dspace_statistics_api/items.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dspace_statistics_api/items.py b/dspace_statistics_api/items.py index 77d7b5b..874cd76 100644 --- a/dspace_statistics_api/items.py +++ b/dspace_statistics_api/items.py @@ -1,7 +1,6 @@ import requests from .config import SOLR_SERVER -from .util import get_statistics_shards 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 :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 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 :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 solr_items_string: str = " OR ".join(items).replace("-", r"\-") @@ -97,7 +102,4 @@ def get_downloads(solr_date_string: str, items: list): return data - -shards = get_statistics_shards() - # vim: set sw=4 ts=4 expandtab: