From 169477c39dc772c0eb1d45f8097215e73f0f6044 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 12 Nov 2019 21:18:27 -0800 Subject: test for ingest transform --- python/tests/transform_ingest.py | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 python/tests/transform_ingest.py (limited to 'python') diff --git a/python/tests/transform_ingest.py b/python/tests/transform_ingest.py new file mode 100644 index 00000000..2d5652b8 --- /dev/null +++ b/python/tests/transform_ingest.py @@ -0,0 +1,57 @@ + +import json +import pytest +from fatcat_tools.transforms import release_ingest_request +from fatcat_openapi_client import * +from fixtures import api + +from import_crossref import crossref_importer + +def test_basic_ingest_release(crossref_importer): + with open('tests/files/crossref-works.single.json', 'r') as f: + # not a single line + raw = json.loads(f.read()) + r = crossref_importer.parse_record(raw) + r.state = 'active' + req = release_ingest_request(r) + assert req is not None + +def test_rich_ingest_release(): + r = ReleaseEntity( + title="something", + ident="iznnn644szdwva7khyxqzc5555", + release_year=1234, + license_slug="CC-BY-NC", + ext_ids=ReleaseExtIds(doi="10.123/456"), + refs=[ + ReleaseRef(), + ReleaseRef(target_release_id="iznnn644szdwva7khyxqzc73bi"), + ], + ) + r.state = 'active' + r.container = ContainerEntity( + name="dummy journal", + extra={ + "ia": { + "sim": { + "year_spans": [[1000, 1100]], + }, + }, + "kbart": { + "lockss": { + "year_spans": [[1200, 1300]], + }, + "jstor": { + "year_spans": [[1950, 1960], [1980, 2005]], + }, + }, + "sherpa_romeo": {"color": "blue"}, + "doaj": {"as_of": "2010-02-03"}, + }, + ) + ir = release_ingest_request(r) + assert ir is not None + assert ir['base_url'] == 'https://doi.org/10.123/456' + assert ir['ext_ids']['doi'] == '10.123/456' + assert ir['ext_ids'].get('pmcid') is None + -- cgit v1.2.3