summaryrefslogtreecommitdiffstats
path: root/python/tests/import_arabesque.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/tests/import_arabesque.py')
-rw-r--r--python/tests/import_arabesque.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/python/tests/import_arabesque.py b/python/tests/import_arabesque.py
new file mode 100644
index 00000000..516b0ec2
--- /dev/null
+++ b/python/tests/import_arabesque.py
@@ -0,0 +1,52 @@
+
+import json
+import pytest
+from fatcat_tools.importers import ArabesqueMatchImporter, SqlitePusher
+from fixtures import api
+
+
+@pytest.fixture(scope="function")
+def arabesque_importer(api):
+ yield ArabesqueMatchImporter(api, extid_type="doi")
+
+# TODO: use API to check that entities actually created...
+def test_arabesque_importer_basic(arabesque_importer):
+ SqlitePusher(arabesque_importer, 'tests/files/arabesque_example.sqlite3', "crawl_result").run()
+
+def test_arabesque_importer(arabesque_importer):
+ last_index = arabesque_importer.api.get_changelog(limit=1)[0].index
+ arabesque_importer.bezerk_mode = True
+ counts = SqlitePusher(arabesque_importer, 'tests/files/arabesque_example.sqlite3', "crawl_result").run()
+ assert counts['insert'] == 1
+ assert counts['exists'] == 0
+ assert counts['skip'] == 490
+
+ # fetch most recent editgroup
+ change = arabesque_importer.api.get_changelog_entry(index=last_index+1)
+ eg = change.editgroup
+ assert eg.description
+ assert "identifier/url seedlist" in eg.description.lower()
+ assert eg.extra['git_rev']
+ assert "fatcat_tools.ArabesqueMatchImporter" in eg.extra['agent']
+
+ # re-insert; should skip
+ arabesque_importer.reset()
+ arabesque_importer.bezerk_mode = False
+ counts = SqlitePusher(arabesque_importer, 'tests/files/arabesque_example.sqlite3', "crawl_result").run()
+ assert counts['insert'] == 0
+ assert counts['exists'] == 1
+ assert counts['skip'] == 490
+
+def test_arabesque_dict_parse(arabesque_importer):
+ with open('tests/files/arabesque_example.json', 'r') as f:
+ raw = json.loads(f.readline())
+ f = arabesque_importer.parse_record(raw)
+ assert f.sha1 == "bdd78be55800bb1c9a5e47005bac5e4124793c7b"
+ assert f.mimetype == "application/pdf"
+ assert len(f.urls) == 2
+ for u in f.urls:
+ if u.rel == "web":
+ assert u.url.startswith("https://files.eccomasproceedia.org/")
+ if u.rel == "webarchive":
+ assert u.url.startswith("https://web.archive.org/")
+ assert len(f.release_ids) == 1