summaryrefslogtreecommitdiffstats
path: root/python/tests
diff options
context:
space:
mode:
Diffstat (limited to 'python/tests')
-rw-r--r--python/tests/files/container_jxqqgho7bncrvgfyfznramju3q.json1
-rw-r--r--python/tests/transform_elasticsearch.py47
-rw-r--r--python/tests/web_search.py10
3 files changed, 53 insertions, 5 deletions
diff --git a/python/tests/files/container_jxqqgho7bncrvgfyfznramju3q.json b/python/tests/files/container_jxqqgho7bncrvgfyfznramju3q.json
new file mode 100644
index 00000000..bb4d46f9
--- /dev/null
+++ b/python/tests/files/container_jxqqgho7bncrvgfyfznramju3q.json
@@ -0,0 +1 @@
+{"extra":{"abbrev":"Annu. Rev. Pharmacol. Toxicol.","country":"us","ezb":{"color":"red","ezb_id":"2460"},"ia":{"sim":{"peer_reviewed":true,"pub_type":"Scholarly Journals","scholarly_peer_reviewed":true,"sim_pubid":"5091","year_spans":[[1961,2009]]}},"issne":"1545-4304","issnp":"0362-1642","kbart":{"hathitrust":{"year_spans":[[1976,1992]]},"portico":{"year_spans":[[1961,1999],[2001,2001],[2003,2003],[2005,2006],[2008,2010],[2012,2019]]},"scholarsportal":{"year_spans":[[1961,2003],[2005,2019]]}},"languages":["en"],"sherpa_romeo":{"color":"yellow"},"urls":["https://www.annualreviews.org/journal/pharmtox","https://www.annualreviews.org/loi/pharmtox","http://arjournals.annualreviews.org/loi/pharmtox"]},"ident":"jxqqgho7bncrvgfyfznramju3q","issnl":"0362-1642","name":"Annual Review of Pharmacology and Toxicology","publisher":"Annual Reviews","revision":"ff56081b-9130-47a6-9e14-9901c2808502","state":"active"}
diff --git a/python/tests/transform_elasticsearch.py b/python/tests/transform_elasticsearch.py
index 9cf77d4a..ba2b7ea2 100644
--- a/python/tests/transform_elasticsearch.py
+++ b/python/tests/transform_elasticsearch.py
@@ -147,11 +147,48 @@ def test_elasticsearch_release_from_json():
def test_elasticsearch_container_transform(journal_metadata_importer):
with open('tests/files/journal_metadata.sample.json', 'r') as f:
- raw = json.loads(f.readline())
- c = journal_metadata_importer.parse_record(raw)
- c.state = 'active'
- es = container_to_elasticsearch(c)
- assert es['publisher'] == c.publisher
+ raw1 = json.loads(f.readline())
+ raw2 = json.loads(f.readline())
+ c1 = journal_metadata_importer.parse_record(raw1)
+ c1.state = 'active'
+ c2 = journal_metadata_importer.parse_record(raw2)
+ c2.state = 'active'
+
+ c1.extra['publisher_type'] = "big5"
+ c1.extra['discipline'] = "history"
+ es = container_to_elasticsearch(c1)
+ assert es['publisher'] == c1.publisher
+ assert es['discipline'] == c1.extra['discipline']
+ assert es['publisher_type'] == c1.extra['publisher_type']
+ assert es['keepers'] == []
+
+ stats = {
+ "ident": "en4qj5ijrbf5djxx7p5zzpjyoq",
+ "in_kbart": 11136,
+ "in_web": 9501,
+ "is_preserved": 11136,
+ "issnl": "2050-084X",
+ "preservation": {
+ "bright": 9501,
+ "dark": 1635,
+ "none": 0,
+ "shadows_only": 0,
+ "total": 11136
+ },
+ "release_type": {
+ "_unknown": 9,
+ "article-journal": 11124,
+ "editorial": 2,
+ "letter": 1
+ },
+ "total": 11136
+ }
+ es = container_to_elasticsearch(c2, stats=stats)
+ assert es['name'] == c2.name
+ assert es['publisher'] == c2.publisher
+ assert es['keepers'] == list(c2.extra['kbart'].keys()) == ["portico"]
+ assert es['any_kbart'] == True
+
def test_elasticsearch_file_transform(matched_importer):
f = entity_from_json(open('./tests/files/file_bcah4zp5tvdhjl5bqci2c2lgfa.json', 'r').read(), FileEntity)
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"