# Path: invenio_oauthclient/contrib/orcid.py
# def account_info(remote, resp):
#     """Retrieve remote account information used to find local user.
# 
#     It returns a dictionary with the following structure:
# 
#     .. code-block:: python
# 
#         {
#             'user': {
#                 'profile': {
#                     'full_name': 'Full Name',
#                 },
#             },
#             'external_id': 'github-unique-identifier',
#             'external_method': 'github',
#         }
# 
#     :param remote: The remote application.
#     :param resp: The response.
#     :returns: A dictionary with the user information.
#     """
#     orcid = resp.get('orcid')
# 
#     return {
#         'external_id': orcid,
#         'external_method': 'orcid',
#         'user': {
#             'profile': {
#                 'full_name': resp.get('name'),
#             },
#         },
#     }
# 
# Path: invenio_oauthclient/handlers/utils.py
# def token_session_key(remote_app):
#     """Generate a session key used to store the token for a remote app.
# 
#     :param remote_app: The remote application.
#     :returns: The session key.
#     """
#     return '%s_%s' % (current_app.config['OAUTHCLIENT_SESSION_KEY_PREFIX'],
#                       remote_app)


import httpretty
from flask import session, url_for
from flask_login import current_user
from flask_security import login_user
from flask_security.utils import hash_password
from helpers import check_response_redirect_url_args, get_state, 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.contrib.orcid import account_info
from invenio_oauthclient.handlers import token_session_key
from invenio_oauthclient.models import RemoteAccount, RemoteToken, UserIdentity
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2015-2018 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.

"""Test case for ORCID oauth remote app."""




def test_account_info(app_rest, example_orcid):
    """Test account info extraction."""
    client = app_rest.test_client()
    ioc = app_rest.extensions['oauthlib.client']
    # Ensure remote apps have been loaded (due to before first
    # request)
    client.get(url_for('invenio_oauthclient.rest_login', remote_app='orcid'))

    example_data, example_account_info = example_orcid

    assert account_info(
        ioc.remote_apps['orcid'], example_data) == example_account_info


# Path: invenio_oauthclient/contrib/orcid.py
# def account_info(remote, resp):
#     """Retrieve remote account information used to find local user.
# 
#     It returns a dictionary with the following structure:
# 
#     .. code-block:: python
# 
#         {
#             'user': {
#                 'profile': {
#                     'full_name': 'Full Name',
#                 },
#             },
#             'external_id': 'github-unique-identifier',
#             'external_method': 'github',
#         }
# 
#     :param remote: The remote application.
#     :param resp: The response.
#     :returns: A dictionary with the user information.
#     """
#     orcid = resp.get('orcid')
# 
#     return {
#         'external_id': orcid,
#         'external_method': 'orcid',
#         'user': {
#             'profile': {
#                 'full_name': resp.get('name'),
#             },
#         },
#     }
# 
# Path: invenio_oauthclient/handlers/utils.py
# def token_session_key(remote_app):
#     """Generate a session key used to store the token for a remote app.
# 
#     :param remote_app: The remote application.
#     :returns: The session key.
#     """
#     return '%s_%s' % (current_app.config['OAUTHCLIENT_SESSION_KEY_PREFIX'],
#                       remote_app)


# Path: tests/test_contrib_orcid_rest.py
import httpretty
from flask import session, url_for
from flask_login import current_user
from flask_security import login_user
from flask_security.utils import hash_password
from helpers import check_response_redirect_url_args, get_state, 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.contrib.orcid import account_info
from invenio_oauthclient.handlers import token_session_key
from invenio_oauthclient.models import RemoteAccount, RemoteToken, UserIdentity

# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2015-2018 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.

"""Test case for ORCID oauth remote app."""




def test_account_info(app_rest, example_orcid):
    """Test account info extraction."""
    client = app_rest.test_client()
    ioc = app_rest.extensions['oauthlib.client']
    # Ensure remote apps have been loaded (due to before first
    # request)
    client.get(url_for('invenio_oauthclient.rest_login', remote_app='orcid'))

    example_data, example_account_info = example_orcid

    assert account_info(
        ioc.remote_apps['orcid'], example_data) == example_account_info


    assert account_info(ioc.remote_apps['orcid'], {}) == \