# Path: zenodo/modules/openaire/helpers.py
# def openaire_id(record):
#     """Compute the OpenAIRE identifier."""
#     return _openaire_id(record, openaire_type(record))
# 
# def openaire_link(record):
#     """Compute an OpenAIRE link."""
#     oatype = openaire_type(record)
#     doi = record.get('doi')
# 
#     if oatype == _OAType.publication:
#         return '{}/search/publication?pid={}'.format(
#             current_app.config['OPENAIRE_PORTAL_URL'],
#             urllib.quote(doi),
#         )
#     elif oatype == _OAType.dataset:
#         return '{}/search/dataset?pid={}'.format(
#             current_app.config['OPENAIRE_PORTAL_URL'],
#             urllib.quote(doi),
#         )
#     elif oatype == _OAType.software:
#         return '{}/search/software?pid={}'.format(
#             current_app.config['OPENAIRE_PORTAL_URL'],
#             urllib.quote(doi),
#         )
#     elif oatype == _OAType.other:
#         return '{}/search/other?pid={}'.format(
#             current_app.config['OPENAIRE_PORTAL_URL'],
#             urllib.quote(doi),
#         )
#     return None
# 
# def openaire_type(record):
#     """Get the OpenAIRE type of a record."""
#     if is_openaire_publication(record):
#         return _OAType.publication
#     elif is_openaire_dataset(record):
#         return _OAType.dataset
#     elif is_openaire_software(record):
#         return _OAType.software
#     elif is_openaire_other(record):
#         return _OAType.other
#     return None


from zenodo.modules.openaire.helpers import openaire_id, openaire_link, \
    openaire_type
    assert openaire_id(r) == 'r37b0ad08687::47287d1800c112499a117ca17aa1909d'

    # Dataset ID
    r['resource_type']['type'] = 'dataset'
    assert openaire_id(r) == 'r37b0ad08687::204007f516ddcf0a452c2f22d48695ca'

    # Publication ID
    r['resource_type']['type'] = 'publication'
    assert openaire_id(r) == 'od______2659::47287d1800c112499a117ca17aa1909d'


def test_openaire_link(app, minimal_record):
    """Test OpenAIRE ID."""
    r = minimal_record
    r['doi'] = u'10.5281/zenodo.123'
    r['_oai'] = {'id': u'oai:zenodo.org:123'}

    # Default zenodo type is software
    assert openaire_link(r) ==\
        'https://explore.openaire.eu/search/software?' \
        'pid=10.5281/zenodo.123'

    # Other type
    r['resource_type']['type'] = 'other'
    assert openaire_link(r) == \
        'https://explore.openaire.eu/search/other?' \
        'pid=10.5281/zenodo.123'

    # Dataset ID
    r['resource_type']['type'] = 'dataset'

# Path: zenodo/modules/openaire/helpers.py
# def openaire_id(record):
#     """Compute the OpenAIRE identifier."""
#     return _openaire_id(record, openaire_type(record))
# 
# def openaire_link(record):
#     """Compute an OpenAIRE link."""
#     oatype = openaire_type(record)
#     doi = record.get('doi')
# 
#     if oatype == _OAType.publication:
#         return '{}/search/publication?pid={}'.format(
#             current_app.config['OPENAIRE_PORTAL_URL'],
#             urllib.quote(doi),
#         )
#     elif oatype == _OAType.dataset:
#         return '{}/search/dataset?pid={}'.format(
#             current_app.config['OPENAIRE_PORTAL_URL'],
#             urllib.quote(doi),
#         )
#     elif oatype == _OAType.software:
#         return '{}/search/software?pid={}'.format(
#             current_app.config['OPENAIRE_PORTAL_URL'],
#             urllib.quote(doi),
#         )
#     elif oatype == _OAType.other:
#         return '{}/search/other?pid={}'.format(
#             current_app.config['OPENAIRE_PORTAL_URL'],
#             urllib.quote(doi),
#         )
#     return None
# 
# def openaire_type(record):
#     """Get the OpenAIRE type of a record."""
#     if is_openaire_publication(record):
#         return _OAType.publication
#     elif is_openaire_dataset(record):
#         return _OAType.dataset
#     elif is_openaire_software(record):
#         return _OAType.software
#     elif is_openaire_other(record):
#         return _OAType.other
#     return None


# Path: tests/unit/openaire/test_openaire_helpers.py
from zenodo.modules.openaire.helpers import openaire_id, openaire_link, \
    openaire_type

    assert openaire_id(r) == 'r37b0ad08687::47287d1800c112499a117ca17aa1909d'

    # Dataset ID
    r['resource_type']['type'] = 'dataset'
    assert openaire_id(r) == 'r37b0ad08687::204007f516ddcf0a452c2f22d48695ca'

    # Publication ID
    r['resource_type']['type'] = 'publication'
    assert openaire_id(r) == 'od______2659::47287d1800c112499a117ca17aa1909d'


def test_openaire_link(app, minimal_record):
    """Test OpenAIRE ID."""
    r = minimal_record
    r['doi'] = u'10.5281/zenodo.123'
    r['_oai'] = {'id': u'oai:zenodo.org:123'}

    # Default zenodo type is software
    assert openaire_link(r) ==\
        'https://explore.openaire.eu/search/software?' \
        'pid=10.5281/zenodo.123'

    # Other type
    r['resource_type']['type'] = 'other'
    assert openaire_link(r) == \
        'https://explore.openaire.eu/search/other?' \
        'pid=10.5281/zenodo.123'

    # Dataset ID
    r['resource_type']['type'] = 'dataset'

    assert openaire_link(r) == \