summaryrefslogtreecommitdiffstats
path: root/python/tests/web_search.py
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-04-04 19:21:10 -0700
committerBryan Newbold <bnewbold@robocracy.org>2019-04-04 19:21:10 -0700
commitfc443013d4a004d69c53be3286e33dd30921879e (patch)
tree7ae87d9be5ec06d0612203f153302c496c3743d4 /python/tests/web_search.py
parentab649adac04086817c69113fa075f1cb9bdc6d0f (diff)
downloadfatcat-fc443013d4a004d69c53be3286e33dd30921879e.tar.gz
fatcat-fc443013d4a004d69c53be3286e33dd30921879e.zip
improve test coverage
Diffstat (limited to 'python/tests/web_search.py')
-rw-r--r--python/tests/web_search.py82
1 files changed, 80 insertions, 2 deletions
diff --git a/python/tests/web_search.py b/python/tests/web_search.py
index 4e7cb2e0..43be9f01 100644
--- a/python/tests/web_search.py
+++ b/python/tests/web_search.py
@@ -33,8 +33,86 @@ def test_container_search(app):
assert b"European Instructional Course Lectures" in rv.data
assert b"British Editorial Society of Bone and Joint Surger" in rv.data
-# TODO: entity stats
+elastic_resp1 = {
+ 'timed_out': False,
+ 'aggregations': {
+ 'release_ref_count': {'value': 8031459}},
+ 'hits': {'total': 80578584, 'hits': [], 'max_score': 0.0},
+ '_shards': {'successful': 5, 'total': 5, 'skipped': 0, 'failed': 0},
+ 'took': 0
+}
+elastic_resp2 = {
+ 'timed_out': False,
+ 'aggregations': {
+ 'paper_like': {'buckets': {
+ 'is_oa': {'doc_count': 8031459},
+ 'in_kbart': {'doc_count': 51594200},
+ 'in_web': {'doc_count': 10925092},
+ 'in_web_not_kbart': {'doc_count': 5160359}}}},
+ 'hits': {'total': 80578584, 'hits': [], 'max_score': 0.0},
+ '_shards': {'successful': 5, 'total': 5, 'skipped': 0, 'failed': 0},
+ 'took': 0
+}
+elastic_resp3 = {
+ 'timed_out': False,
+ 'hits': {'total': 80578584, 'hits': [], 'max_score': 0.0},
+ '_shards': {'successful': 5, 'total': 5, 'skipped': 0, 'failed': 0},
+ 'took': 0
+}
+
+@responses.activate
+def test_stats(app):
+
+ responses.add(responses.GET,
+ 'http://localhost:9200/fatcat_release/_search?request_cache=true',
+ json=elastic_resp1.copy(), status=200)
+ responses.add(responses.GET,
+ 'http://localhost:9200/fatcat_release/_search?request_cache=true',
+ json=elastic_resp2.copy(), status=200)
+ responses.add(responses.GET,
+ 'http://localhost:9200/fatcat_container/_search?request_cache=true',
+ json=elastic_resp3.copy(), status=200)
+ rv = app.get('/stats')
+ assert rv.status_code == 200
+ # TODO: probe these reponses better
+
+@responses.activate
+def test_stats_json(app):
+
+ responses.add(responses.GET,
+ 'http://localhost:9200/fatcat_release/_search?request_cache=true',
+ json=elastic_resp1.copy(), status=200)
+ responses.add(responses.GET,
+ 'http://localhost:9200/fatcat_release/_search?request_cache=true',
+ json=elastic_resp2.copy(), status=200)
+ responses.add(responses.GET,
+ 'http://localhost:9200/fatcat_container/_search?request_cache=true',
+ json=elastic_resp3.copy(), status=200)
+ rv = app.get('/stats.json')
+ assert rv.status_code == 200
+
+@responses.activate
+def test_container_stats(app):
+
+ elastic_resp = {
+ 'timed_out': False,
+ 'aggregations': {
+ 'container_stats': {'buckets': {
+ 'is_preserved': {'doc_count': 461939},
+ 'in_web': {'doc_count': 2797}}}},
+ 'hits': {'total': 461939, 'hits': [], 'max_score': 0.0},
+ '_shards': {'successful': 5, 'total': 5, 'skipped': 0, 'failed': 0},
+ 'took': 50
+ }
+
+ responses.add(responses.GET,
+ 'http://localhost:9200/fatcat_release/_search?request_cache=true',
+ json=elastic_resp, status=200)
+ rv = app.get('/container/issnl/1234-5678/stats.json')
+ assert rv.status_code == 200
+ # TODO: probe this reponse better
+
# TODO: container stats
# TODO: container ISSN-L query
# TODO: release DOI query
-# TODO: release fulltext query
+# TODO: release fulltext (filter) query