Skip to content

Commit

Permalink
Merge 658874a into 4f5d78e
Browse files Browse the repository at this point in the history
  • Loading branch information
ntarocco committed May 4, 2018
2 parents 4f5d78e + 658874a commit 70a3566
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 19 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -25,10 +25,12 @@
addons:
postgresql: 9.4

dist: trusty

notifications:
email: false

sudo: false
sudo: true

language: python

Expand Down
48 changes: 48 additions & 0 deletions invenio_webhooks/_compat.py
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2018 CERN.
#
# Invenio is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Invenio is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Invenio; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307, USA.
#
# In applying this license, CERN does not
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.

"""Compatibility module for Flask."""

from __future__ import absolute_import

from distutils.version import LooseVersion as V

from pkg_resources import get_distribution

_FLASK_CURRENT_VERSION = V(get_distribution('flask').version)
_FLASK_VERSION_WITH_BUG = V('0.12')


def delete_cached_json_for(request):
"""Delete `_cached_json` attribute for the given request.
Bug workaround to delete `_cached_json` attribute when using Flask < 0.12.
More details: https://github.com/pallets/flask/issues/2087
Note that starting from Flask 1.0, the private `_cached_json` attribute
has been changed in Flask package, and this code will fail.
"""
if _FLASK_CURRENT_VERSION < _FLASK_VERSION_WITH_BUG:
if hasattr(request, '_cached_json'):
delattr(request, '_cached_json')
4 changes: 2 additions & 2 deletions invenio_webhooks/models.py
Expand Up @@ -41,6 +41,7 @@
from sqlalchemy_utils.types import JSONType, UUIDType

from . import signatures
from ._compat import delete_cached_json_for
from .errors import InvalidPayload, InvalidSignature, ReceiverDoesNotExist
from .proxies import current_webhooks

Expand Down Expand Up @@ -132,8 +133,7 @@ def extract_payload(self):
raise InvalidSignature('Invalid Signature')
if request.is_json:
# Request.get_json() could be first called with silent=True.
if hasattr(request, '_cached_json'):
delattr(request, '_cached_json')
delete_cached_json_for(request)
return request.get_json(silent=False, cache=False)
elif request.content_type == 'application/x-www-form-urlencoded':
return dict(request.form)
Expand Down
2 changes: 1 addition & 1 deletion invenio_webhooks/views.py
Expand Up @@ -85,7 +85,7 @@ def make_response(event):
# Default decorators
#
def error_handler(f):
"""Decorator to handle exceptions."""
"""Return a json payload and appropriate status code on expection."""
@wraps(f)
def inner(*args, **kwargs):
try:
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Expand Up @@ -34,6 +34,9 @@ all_files = 1
[bdist_wheel]
universal = 1

[pydocstyle]
add_ignore = D401

[compile_catalog]
directory = invenio_webhooks/translations/

Expand Down
30 changes: 16 additions & 14 deletions setup.py
Expand Up @@ -34,31 +34,31 @@
tests_require = [
'Flask-CeleryExt>=0.2.2',
'SQLAlchemy-Continuum>=1.2.1',
'check-manifest>=0.25',
'coverage>=4.0',
'isort>=4.2.2',
'pydocstyle>=1.0.0',
'check-manifest>=0.35',
'coverage>=4.4.1',
'isort>=4.3',
'pydocstyle>=2.0.0',
'pytest-cache>=1.0',
'pytest-cov>=1.8.0',
'pytest-cov>=2.5.1',
'pytest-pep8>=1.0.6',
'pytest>=2.8.0',
'pytest>=3.3.1',
]

extras_require = {
'celery': [
'celery>=3.1,<4.0',
],
'docs': [
'Sphinx>=1.4.2',
'Sphinx>=1.5.2',
],
'mysql': [
'invenio-db[mysql]>=1.0.0b3',
'invenio-db[mysql]>=1.0.0b8',
],
'postgresql': [
'invenio-db[postgresql]>=1.0.0b3',
'invenio-db[postgresql]>=1.0.0b8',
],
'sqlite': [
'invenio-db>=1.0.0b3',
'invenio-db>=1.0.0b8',
],
'tests': tests_require,
}
Expand All @@ -70,16 +70,18 @@
extras_require['all'].extend(reqs)

setup_requires = [
'Babel>=1.3',
'pytest-runner>=2.6.2',
'Babel>=2.4.0',
'pytest-runner>=3.0.0,<5',
]

install_requires = [
'Flask-BabelEx>=0.9.2',
'Flask>=0.11.1',
'SQLAlchemy>=1.1.5',
'SQLAlchemy-Utils>=0.32.9',
'cryptography>=1.3.1',
'invenio-accounts>=1.0.0b1',
'invenio-oauth2server>=1.0.0a13',
'invenio-accounts>=1.0.0b9',
'invenio-oauth2server>=1.0.0b4',
]

packages = find_packages()
Expand Down
4 changes: 3 additions & 1 deletion tests/conftest.py
Expand Up @@ -39,7 +39,7 @@
from invenio_accounts import InvenioAccounts
from invenio_accounts.views import blueprint as accounts_blueprint
from invenio_db import InvenioDB, db
from invenio_oauth2server import InvenioOAuth2Server
from invenio_oauth2server import InvenioOAuth2Server, InvenioOAuth2ServerREST
from invenio_oauth2server.models import Token
from invenio_oauth2server.views import server_blueprint, settings_blueprint
from sqlalchemy_utils.functions import create_database, database_exists, \
Expand All @@ -55,6 +55,7 @@ def app(request):
"""Flask application fixture."""
app = Flask('testapp')
app.config.update(
ACCOUNTS_JWT_ENABLE=False,
BROKER_TRANSPORT='redis',
CELERY_ALWAYS_EAGER=True,
CELERY_CACHE_BACKEND='memory',
Expand Down Expand Up @@ -84,6 +85,7 @@ def app(request):
InvenioAccounts(app)
app.register_blueprint(accounts_blueprint)
InvenioOAuth2Server(app)
InvenioOAuth2ServerREST(app)
app.register_blueprint(server_blueprint)
app.register_blueprint(settings_blueprint)
InvenioWebhooks(app)
Expand Down

0 comments on commit 70a3566

Please sign in to comment.