From ab80106891e5eca1a400b095aa456ad53dce2f71 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 31 Dec 2018 18:44:24 -0800 Subject: add crude/manual auth token to python tests (fixing them) --- python/tests/fixtures.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'python/tests') diff --git a/python/tests/fixtures.py b/python/tests/fixtures.py index 567e9132..c415abef 100644 --- a/python/tests/fixtures.py +++ b/python/tests/fixtures.py @@ -22,6 +22,8 @@ def app(full_app): def api(): conf = fatcat_client.Configuration() conf.host = "http://localhost:9411/v0" + conf.api_key["Authorization"] = "AgEPZGV2LmZhdGNhdC53aWtpAg4yMDE4LTEyLTMxLWRldgACJmVkaXRvcl9pZCA9IGFhYWFhYWFhYWFhYWJrdmthYWFhYWFhYWFlAAIeY3JlYXRlZCA9IDIwMTgtMTItMzFUMjE6MTU6NDdaAAAGIMWFZeZ54pH4OzNl5+U5X3p1H1rMioSuIldihuiM5XAw" + conf.api_key_prefix["Authorization"] = "Bearer" api_client = fatcat_client.DefaultApi(fatcat_client.ApiClient(conf)) return api_client -- cgit v1.2.3 From b66dd55b128758cc929a1633ab6e15f8385873a1 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 3 Jan 2019 16:53:58 -0800 Subject: python codegen --- python/fatcat_client/README.md | 3 + python/fatcat_client/__init__.py | 2 + python/fatcat_client/api/default_api.py | 97 ++++++++++++ python/fatcat_client/models/__init__.py | 2 + python/fatcat_client/models/auth_oidc.py | 167 +++++++++++++++++++++ python/fatcat_client/models/auth_oidc_result.py | 142 ++++++++++++++++++ python/fatcat_client/models/editor.py | 84 ++++++++++- python/tests/codegen_tests/test_auth_oidc.py | 40 +++++ .../tests/codegen_tests/test_auth_oidc_result.py | 40 +++++ python/tests/codegen_tests/test_default_api.py | 6 + 10 files changed, 580 insertions(+), 3 deletions(-) create mode 100644 python/fatcat_client/models/auth_oidc.py create mode 100644 python/fatcat_client/models/auth_oidc_result.py create mode 100644 python/tests/codegen_tests/test_auth_oidc.py create mode 100644 python/tests/codegen_tests/test_auth_oidc_result.py (limited to 'python/tests') diff --git a/python/fatcat_client/README.md b/python/fatcat_client/README.md index 069eb1b4..d03a4092 100644 --- a/python/fatcat_client/README.md +++ b/python/fatcat_client/README.md @@ -74,6 +74,7 @@ All URIs are relative to *https://api.fatcat.wiki/v0* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- *DefaultApi* | [**accept_editgroup**](docs/DefaultApi.md#accept_editgroup) | **POST** /editgroup/{editgroup_id}/accept | +*DefaultApi* | [**auth_oidc**](docs/DefaultApi.md#auth_oidc) | **POST** /auth/oidc | *DefaultApi* | [**create_container**](docs/DefaultApi.md#create_container) | **POST** /container | *DefaultApi* | [**create_container_batch**](docs/DefaultApi.md#create_container_batch) | **POST** /container/batch | *DefaultApi* | [**create_creator**](docs/DefaultApi.md#create_creator) | **POST** /creator | @@ -163,6 +164,8 @@ Class | Method | HTTP request | Description ## Documentation For Models + - [AuthOidc](docs/AuthOidc.md) + - [AuthOidcResult](docs/AuthOidcResult.md) - [ChangelogEntry](docs/ChangelogEntry.md) - [ContainerEntity](docs/ContainerEntity.md) - [CreatorEntity](docs/CreatorEntity.md) diff --git a/python/fatcat_client/__init__.py b/python/fatcat_client/__init__.py index 6b08c0b1..e9a04942 100644 --- a/python/fatcat_client/__init__.py +++ b/python/fatcat_client/__init__.py @@ -22,6 +22,8 @@ from fatcat_client.api.default_api import DefaultApi from fatcat_client.api_client import ApiClient from fatcat_client.configuration import Configuration # import models into sdk package +from fatcat_client.models.auth_oidc import AuthOidc +from fatcat_client.models.auth_oidc_result import AuthOidcResult from fatcat_client.models.changelog_entry import ChangelogEntry from fatcat_client.models.container_entity import ContainerEntity from fatcat_client.models.creator_entity import CreatorEntity diff --git a/python/fatcat_client/api/default_api.py b/python/fatcat_client/api/default_api.py index 5cb5dc64..a0a193f0 100644 --- a/python/fatcat_client/api/default_api.py +++ b/python/fatcat_client/api/default_api.py @@ -138,6 +138,103 @@ class DefaultApi(object): _request_timeout=params.get('_request_timeout'), collection_formats=collection_formats) + def auth_oidc(self, oidc_params, **kwargs): # noqa: E501 + """auth_oidc # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async=True + >>> thread = api.auth_oidc(oidc_params, async=True) + >>> result = thread.get() + + :param async bool + :param AuthOidc oidc_params: (required) + :return: AuthOidcResult + If the method is called asynchronously, + returns the request thread. + """ + kwargs['_return_http_data_only'] = True + if kwargs.get('async'): + return self.auth_oidc_with_http_info(oidc_params, **kwargs) # noqa: E501 + else: + (data) = self.auth_oidc_with_http_info(oidc_params, **kwargs) # noqa: E501 + return data + + def auth_oidc_with_http_info(self, oidc_params, **kwargs): # noqa: E501 + """auth_oidc # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async=True + >>> thread = api.auth_oidc_with_http_info(oidc_params, async=True) + >>> result = thread.get() + + :param async bool + :param AuthOidc oidc_params: (required) + :return: AuthOidcResult + If the method is called asynchronously, + returns the request thread. + """ + + all_params = ['oidc_params'] # noqa: E501 + all_params.append('async') + all_params.append('_return_http_data_only') + all_params.append('_preload_content') + all_params.append('_request_timeout') + + params = locals() + for key, val in six.iteritems(params['kwargs']): + if key not in all_params: + raise TypeError( + "Got an unexpected keyword argument '%s'" + " to method auth_oidc" % key + ) + params[key] = val + del params['kwargs'] + # verify the required parameter 'oidc_params' is set + if ('oidc_params' not in params or + params['oidc_params'] is None): + raise ValueError("Missing the required parameter `oidc_params` when calling `auth_oidc`") # noqa: E501 + + collection_formats = {} + + path_params = {} + + query_params = [] + + header_params = {} + + form_params = [] + local_var_files = {} + + body_params = None + if 'oidc_params' in params: + body_params = params['oidc_params'] + # HTTP header `Accept` + header_params['Accept'] = self.api_client.select_header_accept( + ['application/json']) # noqa: E501 + + # HTTP header `Content-Type` + header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 + ['application/json']) # noqa: E501 + + # Authentication setting + auth_settings = ['Bearer'] # noqa: E501 + + return self.api_client.call_api( + '/auth/oidc', 'POST', + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type='AuthOidcResult', # noqa: E501 + auth_settings=auth_settings, + async=params.get('async'), + _return_http_data_only=params.get('_return_http_data_only'), + _preload_content=params.get('_preload_content', True), + _request_timeout=params.get('_request_timeout'), + collection_formats=collection_formats) + def create_container(self, entity, **kwargs): # noqa: E501 """create_container # noqa: E501 diff --git a/python/fatcat_client/models/__init__.py b/python/fatcat_client/models/__init__.py index f4716d61..ef77b4fd 100644 --- a/python/fatcat_client/models/__init__.py +++ b/python/fatcat_client/models/__init__.py @@ -15,6 +15,8 @@ from __future__ import absolute_import # import models into model package +from fatcat_client.models.auth_oidc import AuthOidc +from fatcat_client.models.auth_oidc_result import AuthOidcResult from fatcat_client.models.changelog_entry import ChangelogEntry from fatcat_client.models.container_entity import ContainerEntity from fatcat_client.models.creator_entity import CreatorEntity diff --git a/python/fatcat_client/models/auth_oidc.py b/python/fatcat_client/models/auth_oidc.py new file mode 100644 index 00000000..871cc23d --- /dev/null +++ b/python/fatcat_client/models/auth_oidc.py @@ -0,0 +1,167 @@ +# 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 +""" + + +import pprint +import re # noqa: F401 + +import six + + +class AuthOidc(object): + """NOTE: This class is auto generated by the swagger code generator program. + + Do not edit the class manually. + """ + + """ + Attributes: + swagger_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + swagger_types = { + 'provider': 'str', + 'sub': 'str', + 'iss': 'str' + } + + attribute_map = { + 'provider': 'provider', + 'sub': 'sub', + 'iss': 'iss' + } + + def __init__(self, provider=None, sub=None, iss=None): # noqa: E501 + """AuthOidc - a model defined in Swagger""" # noqa: E501 + + self._provider = None + self._sub = None + self._iss = None + self.discriminator = None + + self.provider = provider + self.sub = sub + self.iss = iss + + @property + def provider(self): + """Gets the provider of this AuthOidc. # noqa: E501 + + + :return: The provider of this AuthOidc. # noqa: E501 + :rtype: str + """ + return self._provider + + @provider.setter + def provider(self, provider): + """Sets the provider of this AuthOidc. + + + :param provider: The provider of this AuthOidc. # noqa: E501 + :type: str + """ + if provider is None: + raise ValueError("Invalid value for `provider`, must not be `None`") # noqa: E501 + + self._provider = provider + + @property + def sub(self): + """Gets the sub of this AuthOidc. # noqa: E501 + + + :return: The sub of this AuthOidc. # noqa: E501 + :rtype: str + """ + return self._sub + + @sub.setter + def sub(self, sub): + """Sets the sub of this AuthOidc. + + + :param sub: The sub of this AuthOidc. # noqa: E501 + :type: str + """ + if sub is None: + raise ValueError("Invalid value for `sub`, must not be `None`") # noqa: E501 + + self._sub = sub + + @property + def iss(self): + """Gets the iss of this AuthOidc. # noqa: E501 + + + :return: The iss of this AuthOidc. # noqa: E501 + :rtype: str + """ + return self._iss + + @iss.setter + def iss(self, iss): + """Sets the iss of this AuthOidc. + + + :param iss: The iss of this AuthOidc. # noqa: E501 + :type: str + """ + if iss is None: + raise ValueError("Invalid value for `iss`, must not be `None`") # noqa: E501 + + self._iss = iss + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.swagger_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, AuthOidc): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/python/fatcat_client/models/auth_oidc_result.py b/python/fatcat_client/models/auth_oidc_result.py new file mode 100644 index 00000000..5e31a574 --- /dev/null +++ b/python/fatcat_client/models/auth_oidc_result.py @@ -0,0 +1,142 @@ +# 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 +""" + + +import pprint +import re # noqa: F401 + +import six + +from fatcat_client.models.editor import Editor # noqa: F401,E501 + + +class AuthOidcResult(object): + """NOTE: This class is auto generated by the swagger code generator program. + + Do not edit the class manually. + """ + + """ + Attributes: + swagger_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + swagger_types = { + 'editor': 'Editor', + 'token': 'str' + } + + attribute_map = { + 'editor': 'editor', + 'token': 'token' + } + + def __init__(self, editor=None, token=None): # noqa: E501 + """AuthOidcResult - a model defined in Swagger""" # noqa: E501 + + self._editor = None + self._token = None + self.discriminator = None + + self.editor = editor + self.token = token + + @property + def editor(self): + """Gets the editor of this AuthOidcResult. # noqa: E501 + + + :return: The editor of this AuthOidcResult. # noqa: E501 + :rtype: Editor + """ + return self._editor + + @editor.setter + def editor(self, editor): + """Sets the editor of this AuthOidcResult. + + + :param editor: The editor of this AuthOidcResult. # noqa: E501 + :type: Editor + """ + if editor is None: + raise ValueError("Invalid value for `editor`, must not be `None`") # noqa: E501 + + self._editor = editor + + @property + def token(self): + """Gets the token of this AuthOidcResult. # noqa: E501 + + + :return: The token of this AuthOidcResult. # noqa: E501 + :rtype: str + """ + return self._token + + @token.setter + def token(self, token): + """Sets the token of this AuthOidcResult. + + + :param token: The token of this AuthOidcResult. # noqa: E501 + :type: str + """ + if token is None: + raise ValueError("Invalid value for `token`, must not be `None`") # noqa: E501 + + self._token = token + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.swagger_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, AuthOidcResult): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/python/fatcat_client/models/editor.py b/python/fatcat_client/models/editor.py index 2010d454..493f5d81 100644 --- a/python/fatcat_client/models/editor.py +++ b/python/fatcat_client/models/editor.py @@ -32,24 +32,39 @@ class Editor(object): """ swagger_types = { 'editor_id': 'str', - 'username': 'str' + 'username': 'str', + 'is_admin': 'bool', + 'is_bot': 'bool', + 'is_active': 'bool' } attribute_map = { 'editor_id': 'editor_id', - 'username': 'username' + 'username': 'username', + 'is_admin': 'is_admin', + 'is_bot': 'is_bot', + 'is_active': 'is_active' } - def __init__(self, editor_id=None, username=None): # noqa: E501 + def __init__(self, editor_id=None, username=None, is_admin=None, is_bot=None, is_active=None): # noqa: E501 """Editor - a model defined in Swagger""" # noqa: E501 self._editor_id = None self._username = None + self._is_admin = None + self._is_bot = None + self._is_active = None self.discriminator = None if editor_id is not None: self.editor_id = editor_id self.username = username + if is_admin is not None: + self.is_admin = is_admin + if is_bot is not None: + self.is_bot = is_bot + if is_active is not None: + self.is_active = is_active @property def editor_id(self): @@ -103,6 +118,69 @@ class Editor(object): self._username = username + @property + def is_admin(self): + """Gets the is_admin of this Editor. # noqa: E501 + + + :return: The is_admin of this Editor. # noqa: E501 + :rtype: bool + """ + return self._is_admin + + @is_admin.setter + def is_admin(self, is_admin): + """Sets the is_admin of this Editor. + + + :param is_admin: The is_admin of this Editor. # noqa: E501 + :type: bool + """ + + self._is_admin = is_admin + + @property + def is_bot(self): + """Gets the is_bot of this Editor. # noqa: E501 + + + :return: The is_bot of this Editor. # noqa: E501 + :rtype: bool + """ + return self._is_bot + + @is_bot.setter + def is_bot(self, is_bot): + """Sets the is_bot of this Editor. + + + :param is_bot: The is_bot of this Editor. # noqa: E501 + :type: bool + """ + + self._is_bot = is_bot + + @property + def is_active(self): + """Gets the is_active of this Editor. # noqa: E501 + + + :return: The is_active of this Editor. # noqa: E501 + :rtype: bool + """ + return self._is_active + + @is_active.setter + def is_active(self, is_active): + """Sets the is_active of this Editor. + + + :param is_active: The is_active of this Editor. # noqa: E501 + :type: bool + """ + + self._is_active = is_active + def to_dict(self): """Returns the model properties as a dict""" result = {} 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..2f37a582 100644 --- a/python/tests/codegen_tests/test_default_api.py +++ b/python/tests/codegen_tests/test_default_api.py @@ -35,6 +35,12 @@ class TestDefaultApi(unittest.TestCase): """ pass + def test_auth_oidc(self): + """Test case for auth_oidc + + """ + pass + def test_create_container(self): """Test case for create_container -- cgit v1.2.3 From 206c92823a5ebedef459292fe83cd4d39d78bf46 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 3 Jan 2019 17:53:53 -0800 Subject: python codegen --- python/fatcat_client/README.md | 1 + python/fatcat_client/api/default_api.py | 105 +++++++++++++++++++++++++ python/tests/codegen_tests/test_default_api.py | 6 ++ 3 files changed, 112 insertions(+) (limited to 'python/tests') diff --git a/python/fatcat_client/README.md b/python/fatcat_client/README.md index d03a4092..9c358fce 100644 --- a/python/fatcat_client/README.md +++ b/python/fatcat_client/README.md @@ -155,6 +155,7 @@ Class | Method | HTTP request | Description *DefaultApi* | [**lookup_release**](docs/DefaultApi.md#lookup_release) | **GET** /release/lookup | *DefaultApi* | [**update_container**](docs/DefaultApi.md#update_container) | **PUT** /container/{ident} | *DefaultApi* | [**update_creator**](docs/DefaultApi.md#update_creator) | **PUT** /creator/{ident} | +*DefaultApi* | [**update_editor**](docs/DefaultApi.md#update_editor) | **PUT** /editor/{editor_id} | *DefaultApi* | [**update_file**](docs/DefaultApi.md#update_file) | **PUT** /file/{ident} | *DefaultApi* | [**update_fileset**](docs/DefaultApi.md#update_fileset) | **PUT** /fileset/{ident} | *DefaultApi* | [**update_release**](docs/DefaultApi.md#update_release) | **PUT** /release/{ident} | diff --git a/python/fatcat_client/api/default_api.py b/python/fatcat_client/api/default_api.py index a0a193f0..926cbaca 100644 --- a/python/fatcat_client/api/default_api.py +++ b/python/fatcat_client/api/default_api.py @@ -8555,6 +8555,111 @@ class DefaultApi(object): _request_timeout=params.get('_request_timeout'), collection_formats=collection_formats) + def update_editor(self, editor_id, editor, **kwargs): # noqa: E501 + """update_editor # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async=True + >>> thread = api.update_editor(editor_id, editor, async=True) + >>> result = thread.get() + + :param async bool + :param str editor_id: (required) + :param Editor editor: (required) + :return: Editor + If the method is called asynchronously, + returns the request thread. + """ + kwargs['_return_http_data_only'] = True + if kwargs.get('async'): + return self.update_editor_with_http_info(editor_id, editor, **kwargs) # noqa: E501 + else: + (data) = self.update_editor_with_http_info(editor_id, editor, **kwargs) # noqa: E501 + return data + + def update_editor_with_http_info(self, editor_id, editor, **kwargs): # noqa: E501 + """update_editor # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async=True + >>> thread = api.update_editor_with_http_info(editor_id, editor, async=True) + >>> result = thread.get() + + :param async bool + :param str editor_id: (required) + :param Editor editor: (required) + :return: Editor + If the method is called asynchronously, + returns the request thread. + """ + + all_params = ['editor_id', 'editor'] # noqa: E501 + all_params.append('async') + all_params.append('_return_http_data_only') + all_params.append('_preload_content') + all_params.append('_request_timeout') + + params = locals() + for key, val in six.iteritems(params['kwargs']): + if key not in all_params: + raise TypeError( + "Got an unexpected keyword argument '%s'" + " to method update_editor" % key + ) + params[key] = val + del params['kwargs'] + # verify the required parameter 'editor_id' is set + if ('editor_id' not in params or + params['editor_id'] is None): + raise ValueError("Missing the required parameter `editor_id` when calling `update_editor`") # noqa: E501 + # verify the required parameter 'editor' is set + if ('editor' not in params or + params['editor'] is None): + raise ValueError("Missing the required parameter `editor` when calling `update_editor`") # noqa: E501 + + collection_formats = {} + + path_params = {} + if 'editor_id' in params: + path_params['editor_id'] = params['editor_id'] # noqa: E501 + + query_params = [] + + header_params = {} + + form_params = [] + local_var_files = {} + + body_params = None + if 'editor' in params: + body_params = params['editor'] + # HTTP header `Accept` + header_params['Accept'] = self.api_client.select_header_accept( + ['application/json']) # noqa: E501 + + # HTTP header `Content-Type` + header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 + ['application/json']) # noqa: E501 + + # Authentication setting + auth_settings = ['Bearer'] # noqa: E501 + + return self.api_client.call_api( + '/editor/{editor_id}', 'PUT', + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type='Editor', # noqa: E501 + auth_settings=auth_settings, + async=params.get('async'), + _return_http_data_only=params.get('_return_http_data_only'), + _preload_content=params.get('_preload_content', True), + _request_timeout=params.get('_request_timeout'), + collection_formats=collection_formats) + def update_file(self, ident, entity, **kwargs): # noqa: E501 """update_file # noqa: E501 diff --git a/python/tests/codegen_tests/test_default_api.py b/python/tests/codegen_tests/test_default_api.py index 2f37a582..522eeb1b 100644 --- a/python/tests/codegen_tests/test_default_api.py +++ b/python/tests/codegen_tests/test_default_api.py @@ -521,6 +521,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 -- cgit v1.2.3 From b0d46cb4c3a9922aba78cdc5cf70525d2ff21d84 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 8 Jan 2019 14:33:15 -0800 Subject: run basic CLI tests in CI --- .gitlab-ci.yml | 2 ++ python/tests/cli.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100755 python/tests/cli.sh (limited to 'python/tests') diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a0a67fa8..6f90a20e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -28,8 +28,10 @@ unified_test: - cargo test -- --test-threads 1 - cargo run --bin fatcatd & - cd ../python + - cp env.example .env - pipenv install --dev --deploy - pipenv run pytest --cov + - pipenv run ./tests/cli.sh # Just errors - pipenv run pylint -E fatcat*.py fatcat_tools fatcat_web 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)" -- cgit v1.2.3 From 13ab15af83a355b89aa3fdc032ad9bfca71cf350 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 8 Jan 2019 14:33:59 -0800 Subject: python codegen --- python/fatcat_client/README.md | 1 + python/fatcat_client/api/default_api.py | 93 ++++++++++++++++++++++++++ python/tests/codegen_tests/test_default_api.py | 6 ++ 3 files changed, 100 insertions(+) (limited to 'python/tests') diff --git a/python/fatcat_client/README.md b/python/fatcat_client/README.md index 9c358fce..8704641e 100644 --- a/python/fatcat_client/README.md +++ b/python/fatcat_client/README.md @@ -74,6 +74,7 @@ All URIs are relative to *https://api.fatcat.wiki/v0* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- *DefaultApi* | [**accept_editgroup**](docs/DefaultApi.md#accept_editgroup) | **POST** /editgroup/{editgroup_id}/accept | +*DefaultApi* | [**auth_check**](docs/DefaultApi.md#auth_check) | **GET** /auth/check | *DefaultApi* | [**auth_oidc**](docs/DefaultApi.md#auth_oidc) | **POST** /auth/oidc | *DefaultApi* | [**create_container**](docs/DefaultApi.md#create_container) | **POST** /container | *DefaultApi* | [**create_container_batch**](docs/DefaultApi.md#create_container_batch) | **POST** /container/batch | diff --git a/python/fatcat_client/api/default_api.py b/python/fatcat_client/api/default_api.py index 926cbaca..8b652571 100644 --- a/python/fatcat_client/api/default_api.py +++ b/python/fatcat_client/api/default_api.py @@ -138,6 +138,99 @@ class DefaultApi(object): _request_timeout=params.get('_request_timeout'), collection_formats=collection_formats) + def auth_check(self, **kwargs): # noqa: E501 + """auth_check # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async=True + >>> thread = api.auth_check(async=True) + >>> result = thread.get() + + :param async bool + :param str role: + :return: Success + If the method is called asynchronously, + returns the request thread. + """ + kwargs['_return_http_data_only'] = True + if kwargs.get('async'): + return self.auth_check_with_http_info(**kwargs) # noqa: E501 + else: + (data) = self.auth_check_with_http_info(**kwargs) # noqa: E501 + return data + + def auth_check_with_http_info(self, **kwargs): # noqa: E501 + """auth_check # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async=True + >>> thread = api.auth_check_with_http_info(async=True) + >>> result = thread.get() + + :param async bool + :param str role: + :return: Success + If the method is called asynchronously, + returns the request thread. + """ + + all_params = ['role'] # noqa: E501 + all_params.append('async') + all_params.append('_return_http_data_only') + all_params.append('_preload_content') + all_params.append('_request_timeout') + + params = locals() + for key, val in six.iteritems(params['kwargs']): + if key not in all_params: + raise TypeError( + "Got an unexpected keyword argument '%s'" + " to method auth_check" % key + ) + params[key] = val + del params['kwargs'] + + collection_formats = {} + + path_params = {} + + query_params = [] + if 'role' in params: + query_params.append(('role', params['role'])) # noqa: E501 + + header_params = {} + + form_params = [] + local_var_files = {} + + body_params = None + # HTTP header `Accept` + header_params['Accept'] = self.api_client.select_header_accept( + ['application/json']) # noqa: E501 + + # HTTP header `Content-Type` + header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 + ['application/json']) # noqa: E501 + + # Authentication setting + auth_settings = ['Bearer'] # noqa: E501 + + return self.api_client.call_api( + '/auth/check', 'GET', + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type='Success', # noqa: E501 + auth_settings=auth_settings, + async=params.get('async'), + _return_http_data_only=params.get('_return_http_data_only'), + _preload_content=params.get('_preload_content', True), + _request_timeout=params.get('_request_timeout'), + collection_formats=collection_formats) + def auth_oidc(self, oidc_params, **kwargs): # noqa: E501 """auth_oidc # noqa: E501 diff --git a/python/tests/codegen_tests/test_default_api.py b/python/tests/codegen_tests/test_default_api.py index 522eeb1b..9a632824 100644 --- a/python/tests/codegen_tests/test_default_api.py +++ b/python/tests/codegen_tests/test_default_api.py @@ -35,6 +35,12 @@ 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 -- cgit v1.2.3 From d1862ea4a6dcb781713ffc54bdc4bd7d7cdbdb9e Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 8 Jan 2019 14:35:46 -0800 Subject: start updating importer auth with crossref importer --- python/fatcat_tools/api_auth.py | 6 +++--- python/fatcat_tools/importers/common.py | 32 ++++++++++++++++++++++--------- python/fatcat_tools/importers/crossref.py | 16 ++++++++++++++-- python/tests/fixtures.py | 5 ++++- python/tests/import_crossref.py | 16 ++++++++++++---- 5 files changed, 56 insertions(+), 19 deletions(-) (limited to 'python/tests') diff --git a/python/fatcat_tools/api_auth.py b/python/fatcat_tools/api_auth.py index b36d467c..c49051f6 100644 --- a/python/fatcat_tools/api_auth.py +++ b/python/fatcat_tools/api_auth.py @@ -1,5 +1,5 @@ -import sys +import os, sys import fatcat_client from fatcat_client.rest import ApiException @@ -23,7 +23,7 @@ def authenticated_api(host_uri, token=None): conf = fatcat_client.Configuration() conf.host = host_uri if not token: - token = sys.env['FATCAT_API_AUTH_TOKEN'] + token = os.environ['FATCAT_API_AUTH_TOKEN'] if not token: sys.stderr.write( 'This client requires a fatcat API token (eg, in env var FATCAT_API_AUTH_TOKEN)\n') @@ -34,7 +34,7 @@ def authenticated_api(host_uri, token=None): api = fatcat_client.DefaultApi(fatcat_client.ApiClient(conf)) # verify up front that auth is working - api.check_auth() + api.auth_check() return api diff --git a/python/fatcat_tools/importers/common.py b/python/fatcat_tools/importers/common.py index 40c7abc0..5c33ebc9 100644 --- a/python/fatcat_tools/importers/common.py +++ b/python/fatcat_tools/importers/common.py @@ -4,6 +4,7 @@ import sys import csv import json import itertools +import subprocess from collections import Counter import pykafka @@ -37,19 +38,32 @@ class FatcatImporter: Base class for fatcat importers """ - def __init__(self, host_url, issn_map_file=None): - conf = fatcat_client.Configuration() - conf.host = host_url - self.api = fatcat_client.DefaultApi(fatcat_client.ApiClient(conf)) + def __init__(self, api, **kwargs): + + eg_extra = kwargs.get('editgroup_extra', dict()) + eg_extra['git_rev'] = eg_extra.get('git_rev', + subprocess.check_output(["git", "describe", "--always"]).strip()).decode('utf-8') + + self.api = api + self._editgroup_description = kwargs.get('editgroup_description') + self._editgroup_extra = kwargs.get('editgroup_extra') + issn_map_file = kwargs.get('issn_map_file') + self._issnl_id_map = dict() self._orcid_id_map = dict() self._doi_id_map = dict() - self._issn_issnl_map = None - self._orcid_regex = re.compile("^\\d{4}-\\d{4}-\\d{4}-\\d{3}[\\dX]$") if issn_map_file: self.read_issn_map_file(issn_map_file) + self._orcid_regex = re.compile("^\\d{4}-\\d{4}-\\d{4}-\\d{3}[\\dX]$") self.counts = Counter({'insert': 0, 'update': 0, 'processed_lines': 0}) + def _editgroup(self): + eg = fatcat_client.Editgroup( + description=self._editgroup_description, + extra=self._editgroup_extra, + ) + return self.api.create_editgroup(eg) + def describe_run(self): print("Processed {} lines, inserted {}, updated {}.".format( self.counts['processed_lines'], self.counts['insert'], self.counts['update'])) @@ -64,13 +78,13 @@ class FatcatImporter: def process_source(self, source, group_size=100): """Creates and auto-accepts editgroup every group_size rows""" - eg = self.api.create_editgroup(fatcat_client.Editgroup()) + eg = self._editgroup() i = 0 for i, row in enumerate(source): self.create_row(row, editgroup_id=eg.editgroup_id) if i > 0 and (i % group_size) == 0: self.api.accept_editgroup(eg.editgroup_id) - eg = self.api.create_editgroup(fatcat_client.Editgroup()) + eg = self._editgroup() self.counts['processed_lines'] += 1 if i == 0 or (i % group_size) != 0: self.api.accept_editgroup(eg.editgroup_id) @@ -81,7 +95,7 @@ class FatcatImporter: if decode_kafka: rows = [msg.value.decode('utf-8') for msg in rows] self.counts['processed_lines'] += len(rows) - eg = self.api.create_editgroup(fatcat_client.Editgroup()) + eg = self._editgroup() self.create_batch(rows, editgroup_id=eg.editgroup_id) def process_csv_source(self, source, group_size=100, delimiter=','): diff --git a/python/fatcat_tools/importers/crossref.py b/python/fatcat_tools/importers/crossref.py index 05543590..4f7faf59 100644 --- a/python/fatcat_tools/importers/crossref.py +++ b/python/fatcat_tools/importers/crossref.py @@ -4,6 +4,7 @@ import json import sqlite3 import datetime import itertools +import subprocess import fatcat_client from .common import FatcatImporter @@ -40,8 +41,19 @@ class CrossrefImporter(FatcatImporter): See https://github.com/CrossRef/rest-api-doc for JSON schema notes """ - def __init__(self, host_url, issn_map_file, extid_map_file=None, create_containers=True, check_existing=True): - super().__init__(host_url, issn_map_file) + def __init__(self, api, issn_map_file, **kwargs): + + eg_desc = kwargs.get('editgroup_description', + "Automated import of Crossref DOI metadata, harvested from REST API") + eg_extra = kwargs.get('editgroup_extra', dict()) + eg_extra['agent'] = eg_extra.get('agent', 'CrossrefImporter') + super().__init__(api, + issn_map_file=issn_map_file, + editgroup_description=eg_desc, + editgroup_extra=eg_extra) + extid_map_file = kwargs.get('extid_map_file') + create_containers = kwargs.get('create_containers') + check_existing = kwargs.get('check_existing') self.extid_map_db = None if extid_map_file: db_uri = "file:{}?mode=ro".format(extid_map_file) diff --git a/python/tests/fixtures.py b/python/tests/fixtures.py index c415abef..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,9 +22,10 @@ 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"] = "AgEPZGV2LmZhdGNhdC53aWtpAg4yMDE4LTEyLTMxLWRldgACJmVkaXRvcl9pZCA9IGFhYWFhYWFhYWFhYWJrdmthYWFhYWFhYWFlAAIeY3JlYXRlZCA9IDIwMTgtMTItMzFUMjE6MTU6NDdaAAAGIMWFZeZ54pH4OzNl5+U5X3p1H1rMioSuIldihuiM5XAw" + 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..3ef97719 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 "CrossrefImporter" in eg.extra['agent'] def test_crossref_mappings(crossref_importer): assert crossref_importer.map_release_type('journal-article') == "article-journal" -- cgit v1.2.3 From 8c930ded07b6a668bc1721ef98312d9259c06b59 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 8 Jan 2019 14:59:38 -0800 Subject: importers and tests all use new api-passing --- python/env.example | 8 ++++++++ python/fatcat_tools/importers/common.py | 1 + python/fatcat_tools/importers/crossref.py | 2 +- python/fatcat_tools/importers/grobid_metadata.py | 13 ++++++++++--- python/fatcat_tools/importers/issn.py | 10 ++++++++++ python/fatcat_tools/importers/matched.py | 18 ++++++++++++------ python/fatcat_tools/importers/orcid.py | 10 ++++++++++ python/tests/import_crossref.py | 2 +- python/tests/import_grobid_metadata.py | 13 +++++++++++-- python/tests/import_issn.py | 13 +++++++++++-- python/tests/import_matched.py | 13 +++++++++++-- python/tests/import_orcid.py | 13 +++++++++++-- python/tests/importer.py | 9 +++++---- python/tests/transform_tests.py | 1 + 14 files changed, 103 insertions(+), 23 deletions(-) (limited to 'python/tests') diff --git a/python/env.example b/python/env.example index c1855440..fe9036b3 100644 --- a/python/env.example +++ b/python/env.example @@ -9,3 +9,11 @@ GITLAB_CLIENT_SECRET="" IA_XAUTH_CLIENT_ID="" IA_XAUTH_CLIENT_SECRET="" SENTRY_DSN="" + +# These auth keys only for workers/importers; locally will fall back to +# FATCAT_API_AUTH_TOKEN +FATCAT_AUTH_WORKER_CROSSREF="" +FATCAT_AUTH_WORKER_ORCID="" +FATCAT_AUTH_WORKER_ISSN="" +FATCAT_AUTH_WORKER_MATCHED="" +FATCAT_AUTH_WORKER_GROBID_METADATA="" diff --git a/python/fatcat_tools/importers/common.py b/python/fatcat_tools/importers/common.py index 5c33ebc9..e39ec6c9 100644 --- a/python/fatcat_tools/importers/common.py +++ b/python/fatcat_tools/importers/common.py @@ -43,6 +43,7 @@ class FatcatImporter: eg_extra = kwargs.get('editgroup_extra', dict()) eg_extra['git_rev'] = eg_extra.get('git_rev', subprocess.check_output(["git", "describe", "--always"]).strip()).decode('utf-8') + eg_extra['agent'] = eg_extra.get('agent', 'fatcat_tools.FatcatImporter') self.api = api self._editgroup_description = kwargs.get('editgroup_description') diff --git a/python/fatcat_tools/importers/crossref.py b/python/fatcat_tools/importers/crossref.py index 4f7faf59..ed60a78c 100644 --- a/python/fatcat_tools/importers/crossref.py +++ b/python/fatcat_tools/importers/crossref.py @@ -46,7 +46,7 @@ class CrossrefImporter(FatcatImporter): eg_desc = kwargs.get('editgroup_description', "Automated import of Crossref DOI metadata, harvested from REST API") eg_extra = kwargs.get('editgroup_extra', dict()) - eg_extra['agent'] = eg_extra.get('agent', 'CrossrefImporter') + eg_extra['agent'] = eg_extra.get('agent', 'fatcat_tools.CrossrefImporter') super().__init__(api, issn_map_file=issn_map_file, editgroup_description=eg_desc, diff --git a/python/fatcat_tools/importers/grobid_metadata.py b/python/fatcat_tools/importers/grobid_metadata.py index 2cb97b01..5e61a154 100644 --- a/python/fatcat_tools/importers/grobid_metadata.py +++ b/python/fatcat_tools/importers/grobid_metadata.py @@ -12,9 +12,16 @@ MAX_ABSTRACT_BYTES=4096 class GrobidMetadataImporter(FatcatImporter): - def __init__(self, host_url, default_link_rel="web"): - super().__init__(host_url) - self.default_link_rel = default_link_rel + def __init__(self, api, **kwargs): + + eg_desc = kwargs.get('editgroup_description', + "Import of release and file metadata, as extracted from PDFs by GROBID.") + eg_extra = kwargs.get('editgroup_extra', dict()) + eg_extra['agent'] = eg_extra.get('agent', 'fatcat_tools.GrobidMetadataImporter') + super().__init__(api, + editgroup_description=eg_desc, + editgroup_extra=eg_extra) + self.default_link_rel = kwargs.get("default_link_rel", "web") def parse_grobid_json(self, obj): diff --git a/python/fatcat_tools/importers/issn.py b/python/fatcat_tools/importers/issn.py index 9b9ca63f..02a1eea0 100644 --- a/python/fatcat_tools/importers/issn.py +++ b/python/fatcat_tools/importers/issn.py @@ -35,6 +35,16 @@ class IssnImporter(FatcatImporter): ISSN-L,in_doaj,in_road,in_norwegian,in_crossref,title,publisher,url,lang,ISSN-print,ISSN-electronic,doi_count,has_doi,is_oa,is_kept,publisher_size,url_live,url_live_status,url_live_final_status,url_live_final_url,url_live_status_simple,url_live_final_status_simple,url_domain,gwb_pdf_count """ + def __init__(self, api, **kwargs): + + eg_desc = kwargs.get('editgroup_description', + "Automated import of container-level metadata, by ISSN. Metadata from Internet Archive munging.") + eg_extra = kwargs.get('editgroup_extra', dict()) + eg_extra['agent'] = eg_extra.get('agent', 'fatcat_tools.IssnImporter') + super().__init__(api, + editgroup_description=eg_desc, + editgroup_extra=eg_extra) + def parse_issn_row(self, row): """ row is a python dict (parsed from CSV). diff --git a/python/fatcat_tools/importers/matched.py b/python/fatcat_tools/importers/matched.py index 5dbda27c..0b77bcf0 100644 --- a/python/fatcat_tools/importers/matched.py +++ b/python/fatcat_tools/importers/matched.py @@ -37,12 +37,18 @@ class MatchedImporter(FatcatImporter): - core_id, wikidata_id, pmcid, pmid: not as lists """ - def __init__(self, host_url, skip_file_updates=False, default_mime=None, - default_link_rel="web"): - super().__init__(host_url) - self.default_mime = default_mime - self.default_link_rel = default_link_rel - self.skip_file_updates = skip_file_updates + def __init__(self, api, **kwargs): + + eg_desc = kwargs.get('editgroup_description', + "Import of large-scale file-to-release match results. Source of metadata varies.") + eg_extra = kwargs.get('editgroup_extra', dict()) + eg_extra['agent'] = eg_extra.get('agent', 'fatcat_tools.MatchedImporter') + super().__init__(api, + editgroup_description=eg_desc, + editgroup_extra=eg_extra) + self.default_link_rel = kwargs.get("default_link_rel", "web") + self.default_mime = kwargs.get("default_mime", None) + self.skip_file_updates = kwargs.get("skip_file_updates", False) def make_url(self, raw): rel = self.default_link_rel diff --git a/python/fatcat_tools/importers/orcid.py b/python/fatcat_tools/importers/orcid.py index fc4562d0..0aa4ab00 100644 --- a/python/fatcat_tools/importers/orcid.py +++ b/python/fatcat_tools/importers/orcid.py @@ -22,6 +22,16 @@ def value_or_none(e): class OrcidImporter(FatcatImporter): + def __init__(self, api, **kwargs): + + eg_desc = kwargs.get('editgroup_description', + "Automated import of ORCID metadata, from official bulk releases.") + eg_extra = kwargs.get('editgroup_extra', dict()) + eg_extra['agent'] = eg_extra.get('agent', 'fatcat_tools.OrcidImporter') + super().__init__(api, + editgroup_description=eg_desc, + editgroup_extra=eg_extra) + def parse_orcid_dict(self, obj): """ obj is a python dict (parsed from json). diff --git a/python/tests/import_crossref.py b/python/tests/import_crossref.py index 3ef97719..e2ca6122 100644 --- a/python/tests/import_crossref.py +++ b/python/tests/import_crossref.py @@ -28,7 +28,7 @@ def test_crossref_importer(crossref_importer): assert eg.description assert "crossref" in eg.description.lower() assert eg.extra['git_rev'] - assert "CrossrefImporter" in eg.extra['agent'] + 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 -- cgit v1.2.3