# Path: invenio_oauthclient/_compat.py
# def monkey_patch_werkzeug():
# 
# Path: invenio_oauthclient/errors.py
# class OAuthResponseError(OAuthError):
#     """Define response exception during OAuth process."""
# 
#     def __init__(self, message, remote, response):
#         """Initialize exception.
# 
#         :param message: Error message.
#         :param remote: Remote application.
#         :param response: OAuth response object.
#         """
#         super(OAuthResponseError, self).__init__(message, remote)
#         self.response = response
# 
# Path: invenio_oauthclient/views/client.py
# def post_ext_init(state):
# def auto_redirect_login(*args, **kwargs):
# def _login(remote_app, authorized_view_name):
# def login(remote_app):
# def rest_login(remote_app):
# def _authorized(remote_app=None):
# def authorized(remote_app=None):
# def rest_authorized(remote_app=None):
# def _signup(remote_app):
# def signup(remote_app):
# def rest_signup(remote_app):
# def _disconnect(remote_app):
# def disconnect(remote_app):
# def rest_disconnect(remote_app):


import json
import pytest
from flask import session, url_for
from flask_login import current_user
from flask_oauthlib.client import OAuthResponse
from flask_security import login_user
from flask_security.utils import hash_password
from helpers import mock_remote_get, mock_response
from invenio_accounts.models import User
from invenio_db import db
from six.moves.urllib_parse import parse_qs, urlparse
from invenio_oauthclient._compat import _create_identifier
from invenio_oauthclient.errors import OAuthResponseError
from invenio_oauthclient.models import RemoteAccount, RemoteToken, UserIdentity
from invenio_oauthclient.views.client import serializer
                      example_token)
        oauth_resp = OAuthResponse(resp=MockResponse(), content=None,
                                   content_type='application/json')
        mock_remote_get(ioc, 'globus', oauth_resp)

        with pytest.raises(OAuthResponseError):
            c.get(
                url_for('invenio_oauthclient.authorized',
                        remote_app='globus', code='test',
                        state=_get_state()))


def test_invalid_user_id_response(app, example_globus):
    with app.test_client() as c:

        # User login with email 'info'
        ioc = app.extensions['oauthlib.client']

        # Ensure remote apps have been loaded (due to before first request)
        resp = c.get(url_for('invenio_oauthclient.login',
                             remote_app='globus'))
        assert resp.status_code == 302

        example_info, example_token, _ = example_globus
        mock_response(app.extensions['oauthlib.client'], 'globus',
                      example_token)
        oauth_resp = OAuthResponse(resp=None, content=json.dumps(example_info),
                                   content_type='application/json')
        mock_remote_get(ioc, 'globus', oauth_resp)


# Path: invenio_oauthclient/_compat.py
# def monkey_patch_werkzeug():
# 
# Path: invenio_oauthclient/errors.py
# class OAuthResponseError(OAuthError):
#     """Define response exception during OAuth process."""
# 
#     def __init__(self, message, remote, response):
#         """Initialize exception.
# 
#         :param message: Error message.
#         :param remote: Remote application.
#         :param response: OAuth response object.
#         """
#         super(OAuthResponseError, self).__init__(message, remote)
#         self.response = response
# 
# Path: invenio_oauthclient/views/client.py
# def post_ext_init(state):
# def auto_redirect_login(*args, **kwargs):
# def _login(remote_app, authorized_view_name):
# def login(remote_app):
# def rest_login(remote_app):
# def _authorized(remote_app=None):
# def authorized(remote_app=None):
# def rest_authorized(remote_app=None):
# def _signup(remote_app):
# def signup(remote_app):
# def rest_signup(remote_app):
# def _disconnect(remote_app):
# def disconnect(remote_app):
# def rest_disconnect(remote_app):


# Path: tests/test_contrib_globus.py
import json
import pytest
from flask import session, url_for
from flask_login import current_user
from flask_oauthlib.client import OAuthResponse
from flask_security import login_user
from flask_security.utils import hash_password
from helpers import mock_remote_get, mock_response
from invenio_accounts.models import User
from invenio_db import db
from six.moves.urllib_parse import parse_qs, urlparse
from invenio_oauthclient._compat import _create_identifier
from invenio_oauthclient.errors import OAuthResponseError
from invenio_oauthclient.models import RemoteAccount, RemoteToken, UserIdentity
from invenio_oauthclient.views.client import serializer

                      example_token)
        oauth_resp = OAuthResponse(resp=MockResponse(), content=None,
                                   content_type='application/json')
        mock_remote_get(ioc, 'globus', oauth_resp)

        with pytest.raises(OAuthResponseError):
            c.get(
                url_for('invenio_oauthclient.authorized',
                        remote_app='globus', code='test',
                        state=_get_state()))


def test_invalid_user_id_response(app, example_globus):
    with app.test_client() as c:

        # User login with email 'info'
        ioc = app.extensions['oauthlib.client']

        # Ensure remote apps have been loaded (due to before first request)
        resp = c.get(url_for('invenio_oauthclient.login',
                             remote_app='globus'))
        assert resp.status_code == 302

        example_info, example_token, _ = example_globus
        mock_response(app.extensions['oauthlib.client'], 'globus',
                      example_token)
        oauth_resp = OAuthResponse(resp=None, content=json.dumps(example_info),
                                   content_type='application/json')
        mock_remote_get(ioc, 'globus', oauth_resp)


        with pytest.raises(OAuthResponseError):