aboutsummaryrefslogtreecommitdiffstats
path: root/python/tests
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-01-08 16:28:27 -0800
committerBryan Newbold <bnewbold@robocracy.org>2019-01-08 16:28:27 -0800
commit16f2e78298dbd2231f5f337ea17c89a6a131a052 (patch)
tree6e72581e625e73c97cbab72d0f9c35665c99e5d7 /python/tests
parenteb40a5f274f3608db34309cfd16739a7642ef5e7 (diff)
parentffb721f90c5d97ee80885209bf45feb85ca9625c (diff)
downloadfatcat-16f2e78298dbd2231f5f337ea17c89a6a131a052.tar.gz
fatcat-16f2e78298dbd2231f5f337ea17c89a6a131a052.zip
Merge branch 'bnewbold-crude-auth'
Fixed a conflict in: python/fatcat_export.py
Diffstat (limited to 'python/tests')
-rwxr-xr-xpython/tests/cli.sh26
-rw-r--r--python/tests/codegen_tests/test_auth_oidc.py40
-rw-r--r--python/tests/codegen_tests/test_auth_oidc_result.py40
-rw-r--r--python/tests/codegen_tests/test_default_api.py18
-rw-r--r--python/tests/fixtures.py5
-rw-r--r--python/tests/import_crossref.py16
-rw-r--r--python/tests/import_grobid_metadata.py13
-rw-r--r--python/tests/import_issn.py13
-rw-r--r--python/tests/import_matched.py13
-rw-r--r--python/tests/import_orcid.py13
-rw-r--r--python/tests/importer.py9
-rw-r--r--python/tests/transform_tests.py1
12 files changed, 191 insertions, 16 deletions
diff --git a/python/tests/cli.sh b/python/tests/cli.sh
new file mode 100755
index 00000000..eba6d3a7
--- /dev/null
+++ b/python/tests/cli.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+set -eu -o pipefail
+set -x
+
+# This is a helper script to at least partially exersize the fatcat_*.py
+# scripts. It expects to be run from the top-level directory, inside a 'pipenv
+# shell' or 'pipenv run' invocation.
+
+./fatcat_export.py changelog --start 1 --end 10 - > /dev/null
+
+# no easy way to run this without harvest a whole day (at the moment)
+./fatcat_harvest.py crossref -h
+
+./fatcat_import.py crossref tests/files/crossref-works.2018-01-21.badsample.json tests/files/ISSN-to-ISSN-L.snip.txt
+./fatcat_import.py orcid tests/files/0000-0001-8254-7103.json
+./fatcat_import.py issn tests/files/journal_extra_metadata.snip.csv
+./fatcat_import.py matched tests/files/matched_sample.json
+./fatcat_import.py matched tests/files/example_matched.json
+./fatcat_import.py grobid-metadata tests/files/example_grobid_metadata_lines.tsv
+
+./fatcat_webface.py -h
+./fatcat_worker.py -h
+
+set +x
+echo "Done running CLI examples (SUCCESS)"
diff --git a/python/tests/codegen_tests/test_auth_oidc.py b/python/tests/codegen_tests/test_auth_oidc.py
new file mode 100644
index 00000000..f799da55
--- /dev/null
+++ b/python/tests/codegen_tests/test_auth_oidc.py
@@ -0,0 +1,40 @@
+# coding: utf-8
+
+"""
+ fatcat
+
+ A scalable, versioned, API-oriented catalog of bibliographic entities and file metadata # noqa: E501
+
+ OpenAPI spec version: 0.1.0
+
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
+"""
+
+
+from __future__ import absolute_import
+
+import unittest
+
+import fatcat_client
+from fatcat_client.models.auth_oidc import AuthOidc # noqa: E501
+from fatcat_client.rest import ApiException
+
+
+class TestAuthOidc(unittest.TestCase):
+ """AuthOidc unit test stubs"""
+
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def testAuthOidc(self):
+ """Test AuthOidc"""
+ # FIXME: construct object with mandatory attributes with example values
+ # model = fatcat_client.models.auth_oidc.AuthOidc() # noqa: E501
+ pass
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/python/tests/codegen_tests/test_auth_oidc_result.py b/python/tests/codegen_tests/test_auth_oidc_result.py
new file mode 100644
index 00000000..d99ef446
--- /dev/null
+++ b/python/tests/codegen_tests/test_auth_oidc_result.py
@@ -0,0 +1,40 @@
+# coding: utf-8
+
+"""
+ fatcat
+
+ A scalable, versioned, API-oriented catalog of bibliographic entities and file metadata # noqa: E501
+
+ OpenAPI spec version: 0.1.0
+
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
+"""
+
+
+from __future__ import absolute_import
+
+import unittest
+
+import fatcat_client
+from fatcat_client.models.auth_oidc_result import AuthOidcResult # noqa: E501
+from fatcat_client.rest import ApiException
+
+
+class TestAuthOidcResult(unittest.TestCase):
+ """AuthOidcResult unit test stubs"""
+
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def testAuthOidcResult(self):
+ """Test AuthOidcResult"""
+ # FIXME: construct object with mandatory attributes with example values
+ # model = fatcat_client.models.auth_oidc_result.AuthOidcResult() # noqa: E501
+ pass
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/python/tests/codegen_tests/test_default_api.py b/python/tests/codegen_tests/test_default_api.py
index ebc66cda..9a632824 100644
--- a/python/tests/codegen_tests/test_default_api.py
+++ b/python/tests/codegen_tests/test_default_api.py
@@ -35,6 +35,18 @@ class TestDefaultApi(unittest.TestCase):
"""
pass
+ def test_auth_check(self):
+ """Test case for auth_check
+
+ """
+ pass
+
+ def test_auth_oidc(self):
+ """Test case for auth_oidc
+
+ """
+ pass
+
def test_create_container(self):
"""Test case for create_container
@@ -515,6 +527,12 @@ class TestDefaultApi(unittest.TestCase):
"""
pass
+ def test_update_editor(self):
+ """Test case for update_editor
+
+ """
+ pass
+
def test_update_file(self):
"""Test case for update_file
diff --git a/python/tests/fixtures.py b/python/tests/fixtures.py
index 567e9132..6a880c48 100644
--- a/python/tests/fixtures.py
+++ b/python/tests/fixtures.py
@@ -4,12 +4,14 @@ import time
import json
import signal
import pytest
+from dotenv import load_dotenv
import fatcat_web
import fatcat_client
@pytest.fixture
def full_app():
+ load_dotenv(dotenv_path="./env.example")
fatcat_web.app.testing = True
fatcat_web.app.debug = False
return fatcat_web.app
@@ -20,8 +22,11 @@ def app(full_app):
@pytest.fixture
def api():
+ load_dotenv(dotenv_path="./env.example")
conf = fatcat_client.Configuration()
conf.host = "http://localhost:9411/v0"
+ conf.api_key["Authorization"] = os.getenv("FATCAT_API_AUTH_TOKEN")
+ conf.api_key_prefix["Authorization"] = "Bearer"
api_client = fatcat_client.DefaultApi(fatcat_client.ApiClient(conf))
return api_client
diff --git a/python/tests/import_crossref.py b/python/tests/import_crossref.py
index 1fb4a70f..e2ca6122 100644
--- a/python/tests/import_crossref.py
+++ b/python/tests/import_crossref.py
@@ -2,17 +2,18 @@
import json
import pytest
from fatcat_tools.importers import CrossrefImporter
+from fixtures import api
@pytest.fixture(scope="function")
-def crossref_importer():
+def crossref_importer(api):
with open('tests/files/ISSN-to-ISSN-L.snip.txt', 'r') as issn_file:
- yield CrossrefImporter("http://localhost:9411/v0", issn_file, 'tests/files/example_map.sqlite3', check_existing=False)
+ yield CrossrefImporter(api, issn_file, extid_map_file='tests/files/example_map.sqlite3', check_existing=False)
@pytest.fixture(scope="function")
-def crossref_importer_existing():
+def crossref_importer_existing(api):
with open('tests/files/ISSN-to-ISSN-L.snip.txt', 'r') as issn_file:
- yield CrossrefImporter("http://localhost:9411/v0", issn_file, 'tests/files/example_map.sqlite3', check_existing=True)
+ yield CrossrefImporter(api, issn_file, extid_map_file='tests/files/example_map.sqlite3', check_existing=True)
def test_crossref_importer_batch(crossref_importer):
with open('tests/files/crossref-works.2018-01-21.badsample.json', 'r') as f:
@@ -21,6 +22,13 @@ def test_crossref_importer_batch(crossref_importer):
def test_crossref_importer(crossref_importer):
with open('tests/files/crossref-works.2018-01-21.badsample.json', 'r') as f:
crossref_importer.process_source(f)
+ # fetch most recent editgroup
+ changes = crossref_importer.api.get_changelog(limit=1)
+ eg = changes[0].editgroup
+ assert eg.description
+ assert "crossref" in eg.description.lower()
+ assert eg.extra['git_rev']
+ assert "fatcat_tools.CrossrefImporter" in eg.extra['agent']
def test_crossref_mappings(crossref_importer):
assert crossref_importer.map_release_type('journal-article') == "article-journal"
diff --git a/python/tests/import_grobid_metadata.py b/python/tests/import_grobid_metadata.py
index 459b247b..97ebcaef 100644
--- a/python/tests/import_grobid_metadata.py
+++ b/python/tests/import_grobid_metadata.py
@@ -4,6 +4,7 @@ import json
import base64
import pytest
from fatcat_tools.importers import GrobidMetadataImporter
+from fixtures import api
"""
WARNING: these tests are currently very fragile because they have database
@@ -11,8 +12,8 @@ side-effects. Should probably be disabled or re-written.
"""
@pytest.fixture(scope="function")
-def grobid_metadata_importer():
- yield GrobidMetadataImporter("http://localhost:9411/v0")
+def grobid_metadata_importer(api):
+ yield GrobidMetadataImporter(api)
# TODO: use API to check that entities actually created...
#def test_grobid_metadata_importer_batch(grobid_metadata_importer):
@@ -54,3 +55,11 @@ def test_file_metadata_parse(grobid_metadata_importer):
def test_grobid_metadata_importer(grobid_metadata_importer):
with open('tests/files/example_grobid_metadata_lines.tsv', 'r') as f:
grobid_metadata_importer.process_source(f)
+
+ # fetch most recent editgroup
+ changes = grobid_metadata_importer.api.get_changelog(limit=1)
+ eg = changes[0].editgroup
+ assert eg.description
+ assert "grobid" in eg.description.lower()
+ assert eg.extra['git_rev']
+ assert "fatcat_tools.GrobidMetadataImporter" in eg.extra['agent']
diff --git a/python/tests/import_issn.py b/python/tests/import_issn.py
index 98a9f4a7..6b5978d9 100644
--- a/python/tests/import_issn.py
+++ b/python/tests/import_issn.py
@@ -1,11 +1,12 @@
import pytest
from fatcat_tools.importers import IssnImporter
+from fixtures import api
@pytest.fixture(scope="function")
-def issn_importer():
- yield IssnImporter("http://localhost:9411/v0")
+def issn_importer(api):
+ yield IssnImporter(api)
# TODO: use API to check that entities actually created...
def test_issn_importer_batch(issn_importer):
@@ -15,3 +16,11 @@ def test_issn_importer_batch(issn_importer):
def test_issn_importer(issn_importer):
with open('tests/files/journal_extra_metadata.snip.csv', 'r') as f:
issn_importer.process_csv_source(f)
+
+ # fetch most recent editgroup
+ changes = issn_importer.api.get_changelog(limit=1)
+ eg = changes[0].editgroup
+ assert eg.description
+ assert "container" in eg.description.lower()
+ assert eg.extra['git_rev']
+ assert "fatcat_tools.IssnImporter" in eg.extra['agent']
diff --git a/python/tests/import_matched.py b/python/tests/import_matched.py
index 46a9ef85..080674ac 100644
--- a/python/tests/import_matched.py
+++ b/python/tests/import_matched.py
@@ -2,11 +2,12 @@
import json
import pytest
from fatcat_tools.importers import MatchedImporter
+from fixtures import api
@pytest.fixture(scope="function")
-def matched_importer():
- yield MatchedImporter("http://localhost:9411/v0")
+def matched_importer(api):
+ yield MatchedImporter(api)
# TODO: use API to check that entities actually created...
def test_matched_importer_batch(matched_importer):
@@ -17,6 +18,14 @@ def test_matched_importer(matched_importer):
with open('tests/files/example_matched.json', 'r') as f:
matched_importer.process_source(f)
+ # fetch most recent editgroup
+ changes = matched_importer.api.get_changelog(limit=1)
+ eg = changes[0].editgroup
+ assert eg.description
+ assert "file-to-release" in eg.description.lower()
+ assert eg.extra['git_rev']
+ assert "fatcat_tools.MatchedImporter" in eg.extra['agent']
+
def test_matched_dict_parse(matched_importer):
with open('tests/files/example_matched.json', 'r') as f:
raw = json.loads(f.readline())
diff --git a/python/tests/import_orcid.py b/python/tests/import_orcid.py
index 18199888..717a1328 100644
--- a/python/tests/import_orcid.py
+++ b/python/tests/import_orcid.py
@@ -2,11 +2,12 @@
import json
import pytest
from fatcat_tools.importers import OrcidImporter
+from fixtures import api
@pytest.fixture(scope="function")
-def orcid_importer():
- yield OrcidImporter("http://localhost:9411/v0")
+def orcid_importer(api):
+ yield OrcidImporter(api)
# TODO: use API to check that entities actually created...
def test_orcid_importer_batch(orcid_importer):
@@ -21,6 +22,14 @@ def test_orcid_importer(orcid_importer):
with open('tests/files/0000-0001-8254-7103.json', 'r') as f:
orcid_importer.process_source(f)
+ # fetch most recent editgroup
+ changes = orcid_importer.api.get_changelog(limit=1)
+ eg = changes[0].editgroup
+ assert eg.description
+ assert "orcid" in eg.description.lower()
+ assert eg.extra['git_rev']
+ assert "fatcat_tools.OrcidImporter" in eg.extra['agent']
+
def test_orcid_importer_x(orcid_importer):
with open('tests/files/0000-0003-3953-765X.json', 'r') as f:
orcid_importer.process_source(f)
diff --git a/python/tests/importer.py b/python/tests/importer.py
index f228a9b2..34efa5d8 100644
--- a/python/tests/importer.py
+++ b/python/tests/importer.py
@@ -2,11 +2,12 @@
import pytest
from fatcat_tools.importers import FatcatImporter
+from fixtures import api
-def test_issnl_mapping_lookup():
+def test_issnl_mapping_lookup(api):
with open('tests/files/ISSN-to-ISSN-L.snip.txt', 'r') as issn_file:
- fi = FatcatImporter("http://localhost:9411/v0", issn_file)
+ fi = FatcatImporter(api, issn_map_file=issn_file)
assert fi.issn2issnl('0000-0027') == '0002-0027'
assert fi.issn2issnl('0002-0027') == '0002-0027'
@@ -14,10 +15,10 @@ def test_issnl_mapping_lookup():
assert fi.lookup_issnl('9999-9999') == None
-def test_identifiers():
+def test_identifiers(api):
with open('tests/files/ISSN-to-ISSN-L.snip.txt', 'r') as issn_file:
- fi = FatcatImporter("http://localhost:9411/v0", issn_file)
+ fi = FatcatImporter(api, issn_map_file=issn_file)
assert fi.is_issnl("1234-5678") == True
assert fi.is_issnl("1234-5678.") == False
diff --git a/python/tests/transform_tests.py b/python/tests/transform_tests.py
index a42db244..e9d23250 100644
--- a/python/tests/transform_tests.py
+++ b/python/tests/transform_tests.py
@@ -3,6 +3,7 @@ import json
import pytest
from fatcat_tools import *
from fatcat_client import *
+from fixtures import api
from import_crossref import crossref_importer