Skip to content

Commit

Permalink
global: fix tests from pallets family upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Panero committed May 16, 2022
1 parent 55a5880 commit 64ead48
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 42 deletions.
6 changes: 4 additions & 2 deletions invenio_oauthclient/handlers/rest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2015-2018 CERN.
# Copyright (C) 2015-2022 CERN.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Handlers for customizing oauthclient endpoints."""

import json
from functools import partial, wraps

from flask import abort, current_app, jsonify, make_response, redirect, \
Expand Down Expand Up @@ -244,7 +245,8 @@ def signup_handler(remote, *args, **kwargs):
remote.name]
try:
form = create_csrf_disabled_registrationform(remote)
form = fill_form(form, request.json or {})
json_data = {} if not request.data else json.loads(request.data)
form = fill_form(form, json_data)
next_url = base_signup_handler(remote, form, *args, **kwargs)
if form.is_submitted():
response_payload = dict(
Expand Down
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
'uritemplate.py>=0.2.0,<2.0',
],
'mysql': [
'invenio-db[mysql,versioning]>=1.0.11',
'invenio-db[mysql,versioning]>=1.0.14',
],
'orcid': [],
'postgresql': [
'invenio-db[postgresql,versioning]>=1.0.11',
'invenio-db[postgresql,versioning]>=1.0.14',
],
'sqlite': [
'invenio-db[versioning]>=1.0.11',
'invenio-db[versioning]>=1.0.14',
],
'tests': tests_require,
}
Expand All @@ -63,8 +63,8 @@
install_requires = [
'blinker>=1.4',
'Flask-OAuthlib>=0.9.6',
'invenio-accounts>=2.0.0.dev2',
'invenio-base>=1.2.5',
'invenio-accounts>=2.0.0.dev10',
'invenio-base>=1.2.11',
'invenio-i18n>=1.3.1',
'invenio-mail>=1.0.2',
'invenio-theme>=1.3.12',
Expand Down
4 changes: 2 additions & 2 deletions tests/test_contrib_cern.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_account_setup(app, example_cern, models_fixture):
remote_app='cern', code='test',
state=get_state('cern')))
assert resp.status_code == 302
assert resp.location == ('http://localhost/account/settings/'
assert resp.location == ('/account/settings/'
'linkedaccounts/')
assert len(g.identity.provides) == 7

Expand Down Expand Up @@ -182,7 +182,7 @@ def test_authorized_reject(app):
error_description='User denied access',
state=get_state('cern')))
assert resp.status_code in (301, 302)
assert resp.location == 'http://localhost/'
assert resp.location == '/'
# Check message flash
assert session['_flashes'][0][0] == 'info'

Expand Down
4 changes: 2 additions & 2 deletions tests/test_contrib_cern_openid.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_account_setup(app, example_cern_openid, models_fixture):
remote_app='cern_openid', code='test',
state=get_state('cern_openid')))
assert resp.status_code == 302
assert resp.location == ('http://localhost/account/settings/'
assert resp.location == ('/account/settings/'
'linkedaccounts/')
assert len(g.identity.provides) == 3

Expand Down Expand Up @@ -163,7 +163,7 @@ def test_authorized_reject(app):
error_description='User denied access',
state=get_state('cern_openid')))
assert resp.status_code in (301, 302)
assert resp.location == 'http://localhost/'
assert resp.location == '/'
# Check message flash
assert session['_flashes'][0][0] == 'info'

Expand Down
13 changes: 3 additions & 10 deletions tests/test_contrib_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ def test_authorized_signup_valid_user(app, example_github):
remote_app='github', code='test',
state=_get_state()))
assert resp.status_code == 302
assert resp.location == ('http://localhost/account/settings/' +
'linkedaccounts/')
assert resp.location == '/account/settings/linkedaccounts/'

# Assert database state (Sign-up complete)
user = User.query.filter_by(email=example_email).one()
Expand Down Expand Up @@ -145,10 +144,7 @@ def test_authorized_signup_valid_user(app, example_github):
remote_app='github', code='test',
state=_get_state()))
assert resp.status_code == 302
assert resp.location == (
'http://localhost/' +
'account/settings/linkedaccounts/'
)
assert resp.location == '/account/settings/linkedaccounts/'

# check that exist only one account
user = User.query.filter_by(email=example_email).one()
Expand Down Expand Up @@ -181,7 +177,6 @@ def test_authorized_signup_username_already_exists(app, example_github, user):
state=_get_state()))
assert resp.status_code == 302
assert resp.location == (
'http://localhost' +
url_for('invenio_oauthclient.signup', remote_app='github')
)

Expand Down Expand Up @@ -246,9 +241,7 @@ def test_authorized_reject(app):
error_description='User denied access',
state=_get_state()))
assert resp.status_code in (301, 302)
assert resp.location == (
'http://localhost/'
)
assert resp.location == '/'
# Check message flash
assert session['_flashes'][0][0] == 'info'

Expand Down
1 change: 0 additions & 1 deletion tests/test_contrib_github_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ def test_authorized_signup_username_already_exists(
state=_get_state()))
assert resp.status_code == 302
assert resp.location == (
'http://localhost' +
url_for('invenio_oauthclient.rest_signup', remote_app='github')
)

Expand Down
12 changes: 3 additions & 9 deletions tests/test_contrib_globus.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ def test_authorized_signup_valid_user(app, example_globus):
remote_app='globus', code='test',
state=_get_state()))
assert resp.status_code == 302
assert resp.location == ('http://localhost/account/settings/' +
'linkedaccounts/')
assert resp.location == '/account/settings/linkedaccounts/'

# Assert database state (Sign-up complete)
user = User.query.filter_by(email='[email protected]').one()
Expand Down Expand Up @@ -120,10 +119,7 @@ def test_authorized_signup_valid_user(app, example_globus):
remote_app='globus', code='test',
state=_get_state()))
assert resp.status_code == 302
assert resp.location == (
'http://localhost/' +
'account/settings/linkedaccounts/'
)
assert resp.location == '/account/settings/linkedaccounts/'

# check that exist only one account
user = User.query.filter_by(email='[email protected]').one()
Expand All @@ -140,9 +136,7 @@ def test_authorized_reject(app):
error_description='User denied access',
state=_get_state()))
assert resp.status_code in (301, 302)
assert resp.location == (
'http://localhost/'
)
assert resp.location == '/'
# Check message flash
assert session['_flashes'][0][0] == 'info'

Expand Down
6 changes: 2 additions & 4 deletions tests/test_contrib_keycloak.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ def test_authorized_signup_valid_user(app_with_userprofiles,
# note: because we provided an e-mail address in 'info_handler',
# the user does not need to sign up
assert resp.status_code == 302
assert resp.location == ("http://localhost/"
"account/settings/linkedaccounts/")
assert resp.location == "/account/settings/linkedaccounts/"

# check that the user exists
user = User.query.filter_by(email=example_keycloak["email"]).one()
Expand Down Expand Up @@ -164,9 +163,8 @@ def test_authorized_reject(app, example_keycloak_token):
state=get_state("keycloak")
)
)

assert resp.status_code in (301, 302)
assert resp.location == "http://localhost/"
assert resp.location == "/"

# check message flash
assert session["_flashes"][0][0] == "info"
Expand Down
5 changes: 1 addition & 4 deletions tests/test_contrib_orcid.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def test_authorized_signup(app_with_userprofiles, example_orcid, orcid_bio):
state=get_state('orcid')))
assert resp.status_code == 302
assert resp.location == (
'http://localhost' +
url_for('invenio_oauthclient.signup', remote_app='orcid')
)

Expand Down Expand Up @@ -171,9 +170,7 @@ def test_authorized_reject(app, example_orcid):
error_description='User denied access',
state=get_state('orcid')))
assert resp.status_code in (301, 302)
assert resp.location == (
'http://localhost/'
)
assert resp.location == '/'
# Check message flash
assert session['_flashes'][0][0] == 'info'

Expand Down
1 change: 0 additions & 1 deletion tests/test_contrib_orcid_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def test_authorized_signup(app_rest_with_userprofiles,
state=get_state('orcid')))
assert resp.status_code == 302
assert resp.location == (
'http://localhost' +
url_for('invenio_oauthclient.rest_signup', remote_app='orcid')
)

Expand Down
2 changes: 0 additions & 2 deletions tests/test_handlers_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ def mock_response_handler(remote, url, payload):
# Initialize InvenioOAuth
FlaskOAuth(app_rest)
InvenioOAuthClientREST(app_rest)
app_rest.register_blueprint(rest_blueprint)

# Try to sign-up client
response = app_rest.test_client().get(
Expand All @@ -222,7 +221,6 @@ def test_response_handler_with_postmessage(remote, app_rest, models_fixture):
# Initialize InvenioOAuth
FlaskOAuth(app_rest)
InvenioOAuthClientREST(app_rest)
app_rest.register_blueprint(rest_blueprint)

datastore = app_rest.extensions['invenio-accounts'].datastore
existing_email = '[email protected]'
Expand Down

0 comments on commit 64ead48

Please sign in to comment.