Skip to content

Commit

Permalink
upgrade invenio-pytest 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
topless authored and ntarocco committed Oct 2, 2020
1 parent f81de04 commit 02da1e7
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 45 deletions.
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

import os

import sphinx.environment

# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
Expand Down Expand Up @@ -321,7 +319,9 @@
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
'https://docs.python.org/': None,
'invenio-accounts': ('https://invenio-accounts.readthedocs.io/en/latest/', None),
'invenio-accounts': (
'https://invenio-accounts.readthedocs.io/en/latest/', None
),
}

# Autodoc configuraton.
Expand Down
20 changes: 5 additions & 15 deletions invenio_oauthclient/handlers/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,26 @@

from functools import partial, wraps

import six
from flask import current_app, flash, redirect, render_template, request, \
session, url_for
url_for
from flask_babelex import gettext as _
from flask_login import current_user
from invenio_db import db
from werkzeug.utils import import_string

from ..errors import AlreadyLinkedError, OAuthClientAlreadyAuthorized, \
OAuthClientError, OAuthClientMustRedirectLogin, \
OAuthClientMustRedirectSignup, OAuthClientTokenNotFound, \
OAuthClientTokenNotSet, OAuthClientUnAuthorized, \
OAuthClientUserNotRegistered, OAuthError, OAuthRejectedRequestError, \
OAuthResponseError
from ..models import RemoteAccount, RemoteToken
from ..proxies import current_oauthclient
from ..signals import account_info_received, account_setup_committed, \
account_setup_received
from ..utils import create_csrf_disabled_registrationform, \
create_registrationform, fill_form, oauth_authenticate, oauth_register
OAuthClientUserNotRegistered, OAuthError, OAuthRejectedRequestError
from ..utils import create_registrationform
from .base import base_authorized_signup_handler, base_disconnect_handler, \
base_signup_handler
from .utils import get_session_next_url, response_token_setter, token_getter, \
token_session_key, token_setter
from .utils import response_token_setter


def _oauth_error_handler(remote, f, *args, **kwargs):
"""Function to handle exceptions."""
try:
return f(remote, *args, **kwargs)
return f(remote, *args, **kwargs)
except OAuthClientError as e:
current_app.logger.warning(e.message, exc_info=True)
return oauth2_handle_error(
Expand Down
26 changes: 13 additions & 13 deletions invenio_oauthclient/handlers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ def token_delete(remote, token=''):
"""Remove OAuth access tokens from session.
:param remote: The remote application.
:param token: Type of token to get. Data passed from ``oauth.request()`` to
identify which token to retrieve. (Default: ``''``)
:param token: Type of token to get. Data passed from ``oauth.request()``
to identify which token to retrieve. (Default: ``''``)
:returns: The token.
"""
session_key = token_session_key(remote.name)
Expand Down Expand Up @@ -245,14 +245,14 @@ def make_token_getter(remote):


def authorized_handler(f, authorized_response):
"""Handles an OAuth callback.
As authorized_handler is deprecated in favor of authorized_response,
it's has to be wrapped with handler which will be executed
at the proper time.
"""
@wraps(f)
def decorated(*args, **kwargs):
data = authorized_response()
return f(*((data,) + args), **kwargs)
return decorated
"""Handles an OAuth callback.
As authorized_handler is deprecated in favor of authorized_response,
it's has to be wrapped with handler which will be executed
at the proper time.
"""
@wraps(f)
def decorated(*args, **kwargs):
data = authorized_response()
return f(*((data,) + args), **kwargs)
return decorated
3 changes: 1 addition & 2 deletions invenio_oauthclient/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
from invenio_accounts.utils import register_user
from invenio_db import db
from invenio_db.utils import rebuild_encrypted_properties
from itsdangerous import BadData, TimedJSONWebSignatureSerializer
from itsdangerous import TimedJSONWebSignatureSerializer
from sqlalchemy.exc import IntegrityError
from uritools import uricompose, urisplit
from werkzeug.local import LocalProxy
from werkzeug.utils import import_string
from wtforms.fields.core import FormField

from .errors import AlreadyLinkedError
from .models import RemoteAccount, RemoteToken, UserIdentity
Expand Down
4 changes: 1 addition & 3 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@
# under the terms of the MIT License; see LICENSE file for more details.

[pytest]
pep8ignore = docs/conf.py ALL
addopts = --pep8 --doctest-glob="*.rst" --doctest-modules --cov=invenio_oauthclient --cov-report=term-missing
addopts = --isort --pydocstyle --pycodestyle --doctest-glob="*.rst" --doctest-modules --cov=invenio_oauthclient --cov-report=term-missing
testpaths = docs tests invenio_oauthclient
filterwarnings = ignore::pytest.PytestDeprecationWarning
4 changes: 1 addition & 3 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
# under the terms of the MIT License; see LICENSE file for more details.


pydocstyle invenio_oauthclient tests && \
isort invenio_oauthclient tests --check --diff && \
check-manifest --ignore ".travis-*" && \
sphinx-build -qnNW docs docs/_build/html && \
python setup.py test
python -m pytest
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@ output-dir = invenio_oauthclient/translations/
input-file = invenio_oauthclient/translations/messages.pot
output-dir = invenio_oauthclient/translations/

[pycodestyle]
exclude = docs/conf.py

[pydocstyle]
add_ignore = D401
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
history = open('CHANGES.rst').read()

tests_require = [
'pytest-invenio>=1.3.2',
'pytest-invenio>=1.4.0',
'SQLAlchemy-Continuum>=1.2.1',
'httpretty>=0.8.14',
'invenio-userprofiles>=1.0.0',
Expand All @@ -31,7 +31,7 @@
'invenio-admin>=1.0.0',
],
'docs': [
'Sphinx>=1.5.1',
'Sphinx>=3.0.0',
],
'github': [
'github3.py>=1.0.0a4',
Expand All @@ -58,7 +58,6 @@

setup_requires = [
'Babel>=1.3',
'pytest-runner>=2.6.2',
]

install_requires = [
Expand Down
7 changes: 4 additions & 3 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ def teardown():
request.addfinalizer(teardown)

with app.app_context():
if str(db.engine.url) != 'sqlite://' and \
not database_exists(str(db.engine.url)):
create_database(str(db.engine.url))
is_sqllite = str(db.engine.url) == 'sqlite://'
db_exists = database_exists(str(db.engine.url))
if not is_sqllite and not db_exists:
create_database(str(db.engine.url))
db.create_all()
tables = list(filter(lambda table: table.startswith('oauthclient'),
db.metadata.tables.keys()))
Expand Down

0 comments on commit 02da1e7

Please sign in to comment.