Skip to content

Commit

Permalink
interlex session fix how no api key case is signaled
Browse files Browse the repository at this point in the history
also version bump for release
  • Loading branch information
tgbugs committed Aug 17, 2020
1 parent 8edc30b commit 863be8b
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 12 deletions.
1 change: 0 additions & 1 deletion Pipfile
Expand Up @@ -7,7 +7,6 @@ name = "pypi"
python_version = '3.7' # also works with pypy3

[dev-packages]
orthauth = {git = "https://github.com/tgbugs/orthauth.git", editable = true, ref = "master"}
"e1839a8" = {path = ".", extras = ["dev"], editable = true}

[packages]
Expand Down
2 changes: 1 addition & 1 deletion ontquery/__init__.py
Expand Up @@ -4,4 +4,4 @@

__all__ = ['OntCuries', 'OntId', 'OntTerm', 'OntQuery', 'OntQueryCli']

__version__ = '0.2.5'
__version__ = '0.2.6'
4 changes: 4 additions & 0 deletions ontquery/exceptions.py
Expand Up @@ -24,3 +24,7 @@ class ShouldNotHappenError(OntQueryError):

class FetchingError(OntQueryError):
""" A really good looking error you've got there! """


class NoApiKeyError(OntQueryError):
""" No api key has been set """
2 changes: 1 addition & 1 deletion ontquery/plugins/services/interlex.py
Expand Up @@ -57,7 +57,7 @@ def setup(self, **kwargs):
if self.apiEndpoint is not None:
try:
self.ilx_cli = InterLexClient(base_url=self.apiEndpoint)
except InterLexClient.NoApiKeyError:
except exc.NoApiKeyError:
if not self.readonly:
# expect attribute errors for ilx_cli
log.warning('You have not set an API key for the SciCrunch API! '
Expand Down
4 changes: 2 additions & 2 deletions ontquery/plugins/services/interlex_client.py
Expand Up @@ -8,6 +8,7 @@
from . import deco
from .interlex_session import InterlexSession
from ontquery.utils import log
from ontquery import exceptions as exc


@deco.interlex_api_key
Expand Down Expand Up @@ -52,8 +53,7 @@ class NoLabelError(Error):
class NoTypeError(Error):
"""New Entities need a type given."""

class NoApiKeyError(Error):
""" No api key has been set """
NoApiKeyError = exc.NoApiKeyError

class MissingKeyError(Error):
"""Missing dict key for scicrunch entity for API endpoint used."""
Expand Down
7 changes: 6 additions & 1 deletion ontquery/plugins/services/interlex_session.py
@@ -1,7 +1,7 @@
import os
import re
import json
from typing import Callable, Union, Dict, List, Tuple
from typing import Callable, List, Tuple

import requests
from requests import Response
Expand All @@ -10,6 +10,8 @@

from pyontutils.utils import Async, deferred

from ontquery import exceptions as exc


class InterlexSession:
""" Boiler plate for SciCrunch server responses. """
Expand Down Expand Up @@ -75,6 +77,9 @@ def __prepare_data(self, data: dict) -> str:
:param data: Parameters for API request.
"""
if self.key is None:
raise exc.NoApiKeyError

data = data or {}
data.update({'key': self.key})
data = json.dumps(data) # Incase backend is missing this step.
Expand Down
9 changes: 6 additions & 3 deletions setup.py
Expand Up @@ -47,8 +47,8 @@ def find_version(filename):
if status_code:
raise OSError(f'scigraph-codegen failed with status {status_code}')

services_require = ['orthauth>=0.0.13',
'pyontutils>=0.1.23',
services_require = ['orthauth>=0.0.14',
'pyontutils>=0.1.25',
'rdflib>=5.0.0',
'requests',]
tests_require = ['pytest'] + services_require
Expand Down Expand Up @@ -80,7 +80,10 @@ def find_version(filename):
tests_require=tests_require,
install_requires=[
],
extras_require={'dev': ['pyontutils>=0.1.5', 'pytest-cov', 'wheel',],
extras_require={'dev': ['pyontutils>=0.1.5',
'pytest-cov',
'wheel',
],
'services': services_require,
'test': tests_require},
entry_points={
Expand Down
6 changes: 3 additions & 3 deletions test/test_services.py
Expand Up @@ -58,14 +58,14 @@ def test_label(self):

def test_definition(self):
t1 = self.OntTerm('BIRNLEX:796')
assert t1.definition is not None
assert not t1.validated or t1.definition is not None

def test_synonyms(self):
t1 = self.OntTerm('BIRNLEX:796')
if not t1.synonyms: # No syns in SciGraph
if not t1.validated or not t1.synonyms: # No syns in SciGraph
t1 = self.OntTerm('BIRNLEX:798')

assert len(t1.synonyms)
assert not t1.validated or len(t1.synonyms)

def test_cache(self):
t1 = self.OntTerm('BIRNLEX:796')
Expand Down

0 comments on commit 863be8b

Please sign in to comment.