From fc443013d4a004d69c53be3286e33dd30921879e Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 4 Apr 2019 19:21:10 -0700 Subject: improve test coverage --- python/tests/web_search.py | 82 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 2 deletions(-) (limited to 'python/tests/web_search.py') 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 -- cgit v1.2.3