aboutsummaryrefslogtreecommitdiffstats
path: root/python/tests
diff options
context:
space:
mode:
Diffstat (limited to 'python/tests')
-rw-r--r--python/tests/import_jstor.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/python/tests/import_jstor.py b/python/tests/import_jstor.py
new file mode 100644
index 00000000..b1b86a44
--- /dev/null
+++ b/python/tests/import_jstor.py
@@ -0,0 +1,77 @@
+
+import json, gzip
+import pytest
+from fatcat_tools.importers import JstorImporter, Bs4XmlFilePusher
+from fixtures import api
+from bs4 import BeautifulSoup
+
+
+@pytest.fixture(scope="function")
+def jstor_importer(api):
+ with open('tests/files/ISSN-to-ISSN-L.snip.txt', 'r') as issn_file:
+ yield JstorImporter(api, issn_file, extid_map_file='tests/files/example_map.sqlite3', bezerk_mode=True)
+
+@pytest.fixture(scope="function")
+def jstor_importer_existing(api):
+ with open('tests/files/ISSN-to-ISSN-L.snip.txt', 'r') as issn_file:
+ yield JstorImporter(api, issn_file, extid_map_file='tests/files/example_map.sqlite3', bezerk_mode=False)
+
+def test_jstor_importer(jstor_importer):
+ last_index = jstor_importer.api.get_changelog(limit=1)[0].index
+ with open('tests/files/jstor-article-10.2307_111039.xml', 'r') as f:
+ jstor_importer.bezerk_mode = True
+ counts = Bs4XmlFilePusher(jstor_importer, f, "article").run()
+ assert counts['insert'] == 1
+ assert counts['exists'] == 0
+ assert counts['skip'] == 0
+
+ # fetch most recent editgroup
+ change = jstor_importer.api.get_changelog_entry(index=last_index+1)
+ eg = change.editgroup
+ assert eg.description
+ assert "jstor" in eg.description.lower()
+ assert eg.extra['git_rev']
+ assert "fatcat_tools.JstorImporter" in eg.extra['agent']
+
+ last_index = jstor_importer.api.get_changelog(limit=1)[0].index
+ with open('tests/files/jstor-article-10.2307_111039.xml', 'r') as f:
+ jstor_importer.bezerk_mode = False
+ jstor_importer.reset()
+ counts = Bs4XmlFilePusher(jstor_importer, f, "article").run()
+ assert counts['insert'] == 0
+ assert counts['exists'] == 1
+ assert counts['skip'] == 0
+ assert last_index == jstor_importer.api.get_changelog(limit=1)[0].index
+
+def test_jstor_xml_parse(jstor_importer):
+ with open('tests/files/jstor-article-10.2307_111039.xml', 'r') as f:
+ soup = BeautifulSoup(f, "xml")
+ r = jstor_importer.parse_record(soup.find_all("article")[0])
+
+ print(r.extra)
+ assert r.title == "On the Universal Law of Attraction, Including that of Gravitation, as a Particular Case of Approximation Deducible from the Principle that Equal and Similar Particles of Matter Move Similarly, Relatively to Each other. [Abstract]"
+ assert r.subtitle == None
+ assert r.original_title == None
+ assert r.publisher == "The Royal Society"
+ assert r.release_type == "abstract"
+ assert r.release_stage == "published"
+ assert r.license_slug == None
+ # XXX: assert r.ext_ids.doi == "10.2307/111039"
+ assert r.ext_ids.jstor == "111039"
+ assert r.language == "en"
+ assert r.volume == "5"
+ assert r.issue == None
+ assert r.pages == "831-832"
+ # TODO: None if published jan 1st?
+ assert str(r.release_date) == "1843-01-01"
+ assert r.release_year == 1843
+ # matched by ISSN, so shouldn't be in there?
+ #assert extra['container_name'] == "Abstracts of the Papers Communicated to the Royal Society of London"
+ assert len(r.contribs) == 1
+ # XXX: extra['jstor'] stuff
+
+ assert r.contribs[0].raw_name == "John Kinnersley Smythies"
+ assert r.contribs[0].given_name == "John Kinnersley"
+ assert r.contribs[0].surname == "Smythies"
+
+ assert not r.refs