import json, gzip import pytest from fatcat_tools.importers import JalcImporter, Bs4XmlFilePusher, Bs4XmlLinesPusher from fixtures import api from bs4 import BeautifulSoup @pytest.fixture(scope="function") def jalc_importer(api): with open('tests/files/ISSN-to-ISSN-L.snip.txt', 'r') as issn_file: yield JalcImporter(api, issn_file, extid_map_file='tests/files/example_map.sqlite3', bezerk_mode=True) @pytest.fixture(scope="function") def jalc_importer_existing(api): with open('tests/files/ISSN-to-ISSN-L.snip.txt', 'r') as issn_file: yield JalcImporter(api, issn_file, extid_map_file='tests/files/example_map.sqlite3', bezerk_mode=False) def test_jalc_importer(jalc_importer): last_index = jalc_importer.api.get_changelog(limit=1)[0].index with open('tests/files/jalc_lod_sample.xml', 'r') as f: jalc_importer.bezerk_mode = True counts = Bs4XmlFilePusher(jalc_importer, f, "Description").run() assert counts['insert'] == 2 assert counts['exists'] == 0 assert counts['skip'] == 0 # fetch most recent editgroup change = jalc_importer.api.get_changelog_entry(index=last_index+1) eg = change.editgroup assert eg.description assert "jalc" in eg.description.lower() assert eg.extra['git_rev'] assert "fatcat_tools.JalcImporter" in eg.extra['agent'] last_index = jalc_importer.api.get_changelog(limit=1)[0].index with open('tests/files/jalc_lod_sample.xml', 'r') as f: jalc_importer.bezerk_mode = False jalc_importer.reset() counts = Bs4XmlFilePusher(jalc_importer, f, "Description").run() assert counts['insert'] == 0 assert counts['exists'] == 2 assert counts['skip'] == 0 assert last_index == jalc_importer.api.get_changelog(limit=1)[0].index def test_jalc_importer_lines(jalc_importer): last_index = jalc_importer.api.get_changelog(limit=1)[0].index with open('tests/files/jalc_rdf_sample_100.xml', 'r') as f: jalc_importer.bezerk_mode = True counts = Bs4XmlLinesPusher(jalc_importer, f, "