diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2019-05-15 17:12:35 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2019-05-21 11:41:29 -0700 |
commit | 8c6a7e326881d1944ebcd56ac1b528cb76b3d3e9 (patch) | |
tree | 9a18f6fdb2702409a1c4d050a6eb99adb3818ef6 /python/tests/import_jstor.py | |
parent | 91879651d7aa8a18a5fbd2b57dd60c171d6c8fba (diff) | |
download | fatcat-8c6a7e326881d1944ebcd56ac1b528cb76b3d3e9.tar.gz fatcat-8c6a7e326881d1944ebcd56ac1b528cb76b3d3e9.zip |
missing jstor import test (and fix typo)
Diffstat (limited to 'python/tests/import_jstor.py')
-rw-r--r-- | python/tests/import_jstor.py | 77 |
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 |