aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2021-04-06 20:05:05 -0700
committerBryan Newbold <bnewbold@robocracy.org>2021-04-06 21:58:54 -0700
commit0e171b5aeb77690ead3bb896be196fdcc5c69a39 (patch)
treef7512d394f38586a6d3a081e120a623b65f18f87 /python
parent2e781738937efecbfc527a47ade6c3deaba64247 (diff)
downloadfatcat-0e171b5aeb77690ead3bb896be196fdcc5c69a39.tar.gz
fatcat-0e171b5aeb77690ead3bb896be196fdcc5c69a39.zip
search container stats: changes to be called from index code path
Eg, allowing injection of more config values
Diffstat (limited to 'python')
-rw-r--r--python/fatcat_web/search.py13
-rw-r--r--python/tests/web_search.py10
2 files changed, 20 insertions, 3 deletions
diff --git a/python/fatcat_web/search.py b/python/fatcat_web/search.py
index 0cdb604a..2811b9a0 100644
--- a/python/fatcat_web/search.py
+++ b/python/fatcat_web/search.py
@@ -424,7 +424,7 @@ def get_elastic_search_coverage(query: ReleaseQuery) -> dict:
return stats
-def get_elastic_container_stats(ident, issnl=None):
+def get_elastic_container_stats(ident, issnl=None, es_client=None, es_index=None, merge_shadows=None):
"""
Returns dict:
ident
@@ -435,7 +435,14 @@ def get_elastic_container_stats(ident, issnl=None):
preserved
"""
- search = Search(using=app.es_client, index=app.config['ELASTICSEARCH_RELEASE_INDEX'])
+ if not es_client:
+ es_client = app.es_client
+ if not es_index:
+ es_index = app.config['ELASTICSEARCH_RELEASE_INDEX']
+ if merge_shadows is None:
+ merge_shadows = app.config['FATCAT_MERGE_SHADOW_PRESERVATION']
+
+ search = Search(using=es_client, index=es_index)
search = search.query(
'term',
container_id=ident,
@@ -479,7 +486,7 @@ def get_elastic_container_stats(ident, issnl=None):
for k in ('bright', 'dark', 'shadows_only', 'none'):
if not k in preservation_bucket:
preservation_bucket[k] = 0
- if app.config['FATCAT_MERGE_SHADOW_PRESERVATION']:
+ if merge_shadows:
preservation_bucket['none'] += preservation_bucket['shadows_only']
preservation_bucket['shadows_only'] = 0
release_type_bucket = agg_to_dict(resp.aggregations.release_type)
diff --git a/python/tests/web_search.py b/python/tests/web_search.py
index a7bf7ec7..8df01466 100644
--- a/python/tests/web_search.py
+++ b/python/tests/web_search.py
@@ -165,6 +165,16 @@ def test_container_stats(app, mocker):
]
rv = app.get('/container/issnl/1234-5678/stats.json')
assert rv.status_code == 200
+ stats = rv.json
+ assert isinstance(stats['total'], int)
+ assert isinstance(stats['release_type'], dict)
+ assert isinstance(stats['preservation']['total'], int)
+ assert isinstance(stats['preservation']['bright'], int)
+ assert isinstance(stats['preservation']['dark'], int)
+ assert isinstance(stats['preservation']['none'], int)
rv = app.get('/container/aaaaaaaaaaaaaeiraaaaaaaaam/stats.json')
assert rv.status_code == 200
+ stats = rv.json
+ assert isinstance(stats['total'], int)
+ assert stats['ident'] == "aaaaaaaaaaaaaeiraaaaaaaaam"