Commit c0df2fa0 authored by Leo Pound Singer's avatar Leo Pound Singer
Browse files

WIP

parent 18dce76e
Pipeline #93432 failed with stages
in 8 minutes and 9 seconds
import json
import pytest
import six
try:
from unittest import mock
except ImportError:
......
......@@ -16,9 +16,50 @@
# along with gracedb. If not, see <http://www.gnu.org/licenses/>.
from warnings import warn
from .requests.errors import HTTPError
import requests.exceptions
warn('DEPRECATED: this module is provided for backward compatibility. '
'Use requests.exceptions instead.')
__all__ = ('HTTPError',)
class HTTPError(requests.exceptions.HTTPError):
@property
def status(self):
warn('DEPRECATED: this attribute has been moved to '
'HTTPError.response.status_code')
return self.response.status_code
@property
def reason(self):
warn('DEPRECATED: this attribute has been moved to '
'HTTPError.response.text')
return self.response.reason
@property
def message(self):
warn('DEPRECATED: this attribute has been moved to '
'HTTPError.response.text')
return self.response.text
def _hook_raise_errors(response, *args, **kwargs):
"""Response hook to raise exception for any HTTP error (status >= 400)."""
try:
response.raise_for_status()
except requests.HTTPError as e:
# FIXME: remove once ligo.gracedb.exceptions has been removed
raise HTTPError(e.args, response=e.response)
class SessionLegacyErrorMixin(object):
"""A mixin for :class:`requests.Session` to raise legacy GraceDB exceptions
upon HTTP errors."""
def __init__(self, *args, **kwargs):
super(SessionLegacyErrorMixin, self).__init__(*args, **kwargs)
# Note: prepend instead of append so that the legacy exceptions
# override the normal ones.
self.hooks['response'].insert(0, _hook_raise_errors)
......@@ -26,11 +26,12 @@ from ligo.requests.cert_reload import load_certificate
from requests import codes, HTTPError
from .utils import event_or_superevent
from .exceptions import SessionLegacyErrorMixin
DEFAULT_SERVICE_URL = "https://gracedb.ligo.org/api/"
class GraceDb(Session):
class GraceDb(SessionLegacyErrorMixin, Session):
"""GraceDb REST client class.
Provides a client object for accessing the GraceDB server API.
......
......@@ -40,15 +40,13 @@ with open(readme_file, 'rb') as f:
# Required packages for tests
tests_require = [
'pytest-cov',
'pytest-socket',
]
tests_require = []
# Add pytest requirement - 5.0.0+ only supports Python 3.5+
pytest_requirement = 'pytest>=3.1.0'
if sys.version_info < (3, 5):
pytest_requirement += ',<5.0.0'
tests_require.append(pytest_requirement)
tests_require.append('pytest-cov')
# Add mock for Python 2
if sys.version_info.major < 3:
......@@ -87,7 +85,7 @@ setup(
name="ligo-gracedb",
version=parse_version(os.path.join('ligo', 'gracedb', 'version.py')),
author=("Tanner Prestegard, Alexander Pace, Branson Stephens, Brian Moe, "
"Patrick Brady, Leo Singer"),
"Patrick Brady"),
author_email="tanner.prestegard@ligo.org, alexander.pace@ligo.org",
description="A Python package for accessing the GraceDB API.",
long_description=long_description,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment