From 64ead48f7265054cf368b1f1b7472983eb7c96af Mon Sep 17 00:00:00 2001 From: Pablo Panero Date: Mon, 16 May 2022 10:52:52 +0200 Subject: [PATCH] global: fix tests from pallets family upgrade --- invenio_oauthclient/handlers/rest.py | 6 ++++-- setup.py | 10 +++++----- tests/test_contrib_cern.py | 4 ++-- tests/test_contrib_cern_openid.py | 4 ++-- tests/test_contrib_github.py | 13 +++---------- tests/test_contrib_github_rest.py | 1 - tests/test_contrib_globus.py | 12 +++--------- tests/test_contrib_keycloak.py | 6 ++---- tests/test_contrib_orcid.py | 5 +---- tests/test_contrib_orcid_rest.py | 1 - tests/test_handlers_rest.py | 2 -- 11 files changed, 22 insertions(+), 42 deletions(-) diff --git a/invenio_oauthclient/handlers/rest.py b/invenio_oauthclient/handlers/rest.py index d054aa6a..8de6ef44 100644 --- a/invenio_oauthclient/handlers/rest.py +++ b/invenio_oauthclient/handlers/rest.py @@ -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, \ @@ -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( diff --git a/setup.py b/setup.py index d1b90d05..d090021c 100644 --- a/setup.py +++ b/setup.py @@ -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, } @@ -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', diff --git a/tests/test_contrib_cern.py b/tests/test_contrib_cern.py index c507478d..0ce6341f 100644 --- a/tests/test_contrib_cern.py +++ b/tests/test_contrib_cern.py @@ -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 @@ -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' diff --git a/tests/test_contrib_cern_openid.py b/tests/test_contrib_cern_openid.py index 3770ad8b..7320df80 100644 --- a/tests/test_contrib_cern_openid.py +++ b/tests/test_contrib_cern_openid.py @@ -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 @@ -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' diff --git a/tests/test_contrib_github.py b/tests/test_contrib_github.py index 366c594f..20115ace 100644 --- a/tests/test_contrib_github.py +++ b/tests/test_contrib_github.py @@ -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() @@ -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() @@ -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') ) @@ -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' diff --git a/tests/test_contrib_github_rest.py b/tests/test_contrib_github_rest.py index 5c074fa4..9c038073 100644 --- a/tests/test_contrib_github_rest.py +++ b/tests/test_contrib_github_rest.py @@ -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') ) diff --git a/tests/test_contrib_globus.py b/tests/test_contrib_globus.py index 1f929e7a..4bfd0e9b 100644 --- a/tests/test_contrib_globus.py +++ b/tests/test_contrib_globus.py @@ -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='carberry@inveniosoftware.org').one() @@ -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='carberry@inveniosoftware.org').one() @@ -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' diff --git a/tests/test_contrib_keycloak.py b/tests/test_contrib_keycloak.py index 8847dd78..60b29352 100644 --- a/tests/test_contrib_keycloak.py +++ b/tests/test_contrib_keycloak.py @@ -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() @@ -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" diff --git a/tests/test_contrib_orcid.py b/tests/test_contrib_orcid.py index c0531d2a..fde89722 100644 --- a/tests/test_contrib_orcid.py +++ b/tests/test_contrib_orcid.py @@ -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') ) @@ -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' diff --git a/tests/test_contrib_orcid_rest.py b/tests/test_contrib_orcid_rest.py index 3a542924..02b858bb 100644 --- a/tests/test_contrib_orcid_rest.py +++ b/tests/test_contrib_orcid_rest.py @@ -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') ) diff --git a/tests/test_handlers_rest.py b/tests/test_handlers_rest.py index d1f37767..604e1539 100644 --- a/tests/test_handlers_rest.py +++ b/tests/test_handlers_rest.py @@ -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( @@ -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 = 'existing@inveniosoftware.org'