summaryrefslogtreecommitdiffstats
path: root/python/tests/import_datacite.py
diff options
context:
space:
mode:
authorMartin Czygan <martin.czygan@gmail.com>2020-01-02 17:35:54 +0100
committerMartin Czygan <martin.czygan@gmail.com>2020-01-02 17:35:54 +0100
commit96e38edde79735b4080ec08d57e9f54759e97b61 (patch)
tree2798719086819b747adab8d48adbb0c59b5ac9f5 /python/tests/import_datacite.py
parentb87ba235c0a7da15d70c5ab7fa367d7b9c1fb981 (diff)
downloadfatcat-96e38edde79735b4080ec08d57e9f54759e97b61.tar.gz
fatcat-96e38edde79735b4080ec08d57e9f54759e97b61.zip
datacite: add conversion fixtures
The `test_datacite_conversions` function will compare an input (datacite) document to an expected output (release entity as JSON). This way, it should not be too hard to add more cases by adding: input, output - and by increasing the counter in the range loop within the test. To view input and result side by side with vim, change into the test directory and run: tests/files/datacite $ ./caseview.sh 18
Diffstat (limited to 'python/tests/import_datacite.py')
-rw-r--r--python/tests/import_datacite.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/python/tests/import_datacite.py b/python/tests/import_datacite.py
index bc47a185..cdc165d7 100644
--- a/python/tests/import_datacite.py
+++ b/python/tests/import_datacite.py
@@ -7,7 +7,8 @@ import datetime
import pytest
import gzip
from fatcat_tools.importers import DataciteImporter, JsonLinePusher
-from fatcat_tools.importers.datacite import find_original_language_title, parse_datacite_titles, parse_datacite_dates
+from fatcat_tools.importers.datacite import find_original_language_title, parse_datacite_titles, parse_datacite_dates, clean_doi
+from fatcat_tools.transforms import entity_to_dict
from fixtures import api
import json
@@ -270,3 +271,26 @@ def test_datacite_dict_parse(datacite_importer):
assert r.contribs[0].given_name == None
assert r.contribs[0].surname == None
assert len(r.refs) == 0
+
+def test_clean_doi():
+ assert clean_doi("10.25513/1812-3996.2017.1.34\u201342") == "10.25513/1812-3996.2017.1.34-42"
+ assert "123" == clean_doi("123")
+
+def test_datacite_conversions(datacite_importer):
+ """
+ Datacite JSON to release entity JSON representation. The count is hardcoded
+ for now.
+ """
+ datacite_importer.debug = True
+ for i in range(24):
+ src = 'tests/files/datacite/datacite_doc_{0:02d}.json'.format(i)
+ dst = 'tests/files/datacite/datacite_result_{0:02d}.json'.format(i)
+ print('testing mapping from {} => {}'.format(src, dst))
+ with open(src, 'r') as f:
+ re = datacite_importer.parse_record(json.load(f))
+ result = entity_to_dict(re)
+ with open(dst, 'r') as f:
+ expected = json.loads(f.read())
+
+ assert result == expected
+