diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2020-07-27 18:35:57 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2020-07-30 18:28:03 -0700 |
commit | 8e6ab69b9cb3a88661f6ba13ded0d7afff8948a5 (patch) | |
tree | 9c07a0cdb344b58553939ebd8332c1039f764418 | |
parent | 5bbb493b94a63d66151a53837aa66f0d986df497 (diff) | |
download | fatcat-8e6ab69b9cb3a88661f6ba13ded0d7afff8948a5.tar.gz fatcat-8e6ab69b9cb3a88661f6ba13ded0d7afff8948a5.zip |
expand test coverage of new preservation views
-rw-r--r-- | python/tests/web_coverage.py | 137 |
1 files changed, 122 insertions, 15 deletions
diff --git a/python/tests/web_coverage.py b/python/tests/web_coverage.py index 41b04892..d446fba6 100644 --- a/python/tests/web_coverage.py +++ b/python/tests/web_coverage.py @@ -8,28 +8,105 @@ from fixtures import * def test_container_coverage(app, mocker): + # preservation by type histogram elastic_resp1 = { 'took': 294, 'timed_out': False, '_shards': {'total': 5, 'successful': 5, 'skipped': 0, 'failed': 0}, 'hits': {'total': 4327, 'max_score': 0.0, 'hits': []}, 'aggregations': { - 'year_in_ia': { - 'after_key': {'year': 2020.0, 'in_ia': True}, - 'buckets': [ - {'key': {'year': 2004.0, 'in_ia': False}, 'doc_count': 4}, - {'key': {'year': 2004.0, 'in_ia': True}, 'doc_count': 68}, - {'key': {'year': 2005.0, 'in_ia': False}, 'doc_count': 26}, - {'key': {'year': 2005.0, 'in_ia': True}, 'doc_count': 428}, - {'key': {'year': 2006.0, 'in_ia': False}, 'doc_count': 14}, - {'key': {'year': 2006.0, 'in_ia': True}, 'doc_count': 487}, - {'key': {'year': 2007.0, 'in_ia': False}, 'doc_count': 13}, - {'key': {'year': 2007.0, 'in_ia': True}, 'doc_count': 345}, - ], + 'type_preservation': { + 'buckets': [ + {'key': {'release_type': 'article-journal', 'preservation': 'bright'}, 'doc_count': 444}, + {'key': {'release_type': 'book', 'preservation': 'dark'}, 'doc_count': 111}, + ], + 'sum_other_doc_count': 0, }, }, } + # preservation by year histogram + elastic_resp2 = { + 'took': 294, + 'timed_out': False, + '_shards': {'total': 5, 'successful': 5, 'skipped': 0, 'failed': 0}, + 'hits': {'total': 4327, 'max_score': 0.0, 'hits': []}, + 'aggregations': { + 'year_preservation': { + 'buckets': [ + {'key': {'year': 2004.0, 'preservation': 'bright'}, 'doc_count': 444}, + {'key': {'year': 2005.0, 'preservation': 'dark'}, 'doc_count': 111}, + ], + 'sum_other_doc_count': 0, + }, + }, + } + + # preservation by volume histogram + elastic_resp3 = { + 'took': 294, + 'timed_out': False, + '_shards': {'total': 5, 'successful': 5, 'skipped': 0, 'failed': 0}, + 'hits': {'total': 4327, 'max_score': 0.0, 'hits': []}, + 'aggregations': { + 'volume_preservation': { + 'buckets': [ + {'key': {'volume': "12", 'preservation': 'bright'}, 'doc_count': 444}, + {'key': {'volume': "12", 'preservation': 'dark'}, 'doc_count': 111}, + ], + 'sum_other_doc_count': 0, + }, + }, + } + + es_raw = mocker.patch('elasticsearch.connection.Urllib3HttpConnection.perform_request') + es_raw.side_effect = [ + # status + (200, {}, json.dumps(ES_CONTAINER_STATS_RESP)), + # type preservation histogram + (200, {}, json.dumps(elastic_resp1)), + ] + + rv = app.get('/container/aaaaaaaaaaaaaeiraaaaaaaaam/coverage') + assert rv.status_code == 200 + + es_raw.side_effect = [(200, {}, json.dumps(elastic_resp2))] + rv = app.get('/container/aaaaaaaaaaaaaeiraaaaaaaaam/preservation_by_year.svg') + assert rv.status_code == 200 + + es_raw.side_effect = [(200, {}, json.dumps(elastic_resp2))] + rv = app.get('/container/aaaaaaaaaaaaaeiraaaaaaaaam/preservation_by_year.json') + assert rv.status_code == 200 + + es_raw.side_effect = [(200, {}, json.dumps(elastic_resp3))] + rv = app.get('/container/aaaaaaaaaaaaaeiraaaaaaaaam/preservation_by_volume.svg') + assert rv.status_code == 200 + + es_raw.side_effect = [(200, {}, json.dumps(elastic_resp3))] + rv = app.get('/container/aaaaaaaaaaaaaeiraaaaaaaaam/preservation_by_volume.json') + assert rv.status_code == 200 + + +def test_coverage_search(app, mocker): + + # preservation by year histogram + elastic_resp1 = { + 'took': 294, + 'timed_out': False, + '_shards': {'total': 5, 'successful': 5, 'skipped': 0, 'failed': 0}, + 'hits': {'total': 4327, 'max_score': 0.0, 'hits': []}, + 'aggregations': { + 'year_preservation': { + 'buckets': [ + {'key': {'year': 2004.0, 'preservation': 'bright'}, 'doc_count': 444}, + {'key': {'year': 2005.0, 'preservation': 'dark'}, 'doc_count': 111}, + ], + 'sum_other_doc_count': 0, + }, + }, + } + + # preservation by type histogram elastic_resp2 = { 'took': 294, 'timed_out': False, @@ -46,17 +123,46 @@ def test_container_coverage(app, mocker): }, } + es_raw = mocker.patch('elasticsearch.connection.Urllib3HttpConnection.perform_request') es_raw.side_effect = [ - # status + # counts summary (200, {}, json.dumps(ES_CONTAINER_STATS_RESP)), - # type preservation histogram + # by year + (200, {}, json.dumps(elastic_resp1)), + # by type (200, {}, json.dumps(elastic_resp2)), ] - rv = app.get('/container/aaaaaaaaaaaaaeiraaaaaaaaam/coverage') + rv = app.get('/coverage/search?q=*') assert rv.status_code == 200 + +def test_legacy_container_coverage(app, mocker): + + # legacy preservation by year + elastic_resp1 = { + 'took': 294, + 'timed_out': False, + '_shards': {'total': 5, 'successful': 5, 'skipped': 0, 'failed': 0}, + 'hits': {'total': 4327, 'max_score': 0.0, 'hits': []}, + 'aggregations': { + 'year_in_ia': { + 'after_key': {'year': 2020.0, 'in_ia': True}, + 'buckets': [ + {'key': {'year': 2004.0, 'in_ia': False}, 'doc_count': 4}, + {'key': {'year': 2004.0, 'in_ia': True}, 'doc_count': 68}, + {'key': {'year': 2005.0, 'in_ia': False}, 'doc_count': 26}, + {'key': {'year': 2005.0, 'in_ia': True}, 'doc_count': 428}, + {'key': {'year': 2006.0, 'in_ia': False}, 'doc_count': 14}, + {'key': {'year': 2006.0, 'in_ia': True}, 'doc_count': 487}, + {'key': {'year': 2007.0, 'in_ia': False}, 'doc_count': 13}, + {'key': {'year': 2007.0, 'in_ia': True}, 'doc_count': 345}, + ], + }, + }, + } + es_raw = mocker.patch('elasticsearch.connection.Urllib3HttpConnection.perform_request') es_raw.side_effect = [ (200, {}, json.dumps(elastic_resp1)), @@ -72,6 +178,7 @@ def test_container_coverage(app, mocker): rv = app.get('/container/aaaaaaaaaaaaaeiraaaaaaaaam/ia_coverage_years.svg') assert rv.status_code == 200 + def test_coverage_empty_years(app, mocker): elastic_resp = { |