# Path: zenodo/modules/metrics/utils.py
# def calculate_metrics(metric_id, cache=True):
#     if cache:
#         cached_data = current_cache.get(
#             'ZENODO_METRICS_CACHE::{}'.format(metric_id))
#         if cached_data is not None:
#             return cached_data
# 
#     result = deepcopy(
#         current_app.config['ZENODO_METRICS_DATA'][metric_id])
# 
#     for metric in result:
#         metric['value'] = metric['value']()
# 
#     current_cache.set('ZENODO_METRICS_CACHE::{}'.format(metric_id), result,
#                       timeout=current_app.config[
#                           'ZENODO_METRICS_CACHE_TIMEOUT'])
# 
#     return result
# 
# def formatted_response(metrics):
#     response = ''
#     for metric in metrics:
#         response += "# HELP {name} {help}\n# TYPE {name} {type}\n{name} " \
#                     "{value}\n".format(**metric)
# 
#     return response


from zenodo.modules.metrics.utils import calculate_metrics, formatted_response
    expected_data = [
        {
            'name': 'zenodo_unique_visitors_web_total',
            'help': 'Number of unique visitors in total on Zenodo portal',
            'type': 'gauge',
            'value': 0
        },
        {
            'name': 'zenodo_researchers_total',
            'help': 'Number of researchers registered on Zenodo',
            'type': 'gauge',
            'value': 0
        },
        {
            'name': 'zenodo_files_total',
            'help': 'Number of files hosted on Zenodo',
            'type': 'gauge',
            'value': 0
        },
        {
            'name': 'zenodo_communities_total',
            'help': 'Number of Zenodo communities created',
            'type': 'gauge',
            'value': 0
        },
    ]

    calculated_metrics = calculate_metrics('openaire-nexus', cache=False)
    assert calculated_metrics == expected_data


# Path: zenodo/modules/metrics/utils.py
# def calculate_metrics(metric_id, cache=True):
#     if cache:
#         cached_data = current_cache.get(
#             'ZENODO_METRICS_CACHE::{}'.format(metric_id))
#         if cached_data is not None:
#             return cached_data
# 
#     result = deepcopy(
#         current_app.config['ZENODO_METRICS_DATA'][metric_id])
# 
#     for metric in result:
#         metric['value'] = metric['value']()
# 
#     current_cache.set('ZENODO_METRICS_CACHE::{}'.format(metric_id), result,
#                       timeout=current_app.config[
#                           'ZENODO_METRICS_CACHE_TIMEOUT'])
# 
#     return result
# 
# def formatted_response(metrics):
#     response = ''
#     for metric in metrics:
#         response += "# HELP {name} {help}\n# TYPE {name} {type}\n{name} " \
#                     "{value}\n".format(**metric)
# 
#     return response


# Path: tests/unit/metrics/test_metrics_utils.py
from zenodo.modules.metrics.utils import calculate_metrics, formatted_response

    expected_data = [
        {
            'name': 'zenodo_unique_visitors_web_total',
            'help': 'Number of unique visitors in total on Zenodo portal',
            'type': 'gauge',
            'value': 0
        },
        {
            'name': 'zenodo_researchers_total',
            'help': 'Number of researchers registered on Zenodo',
            'type': 'gauge',
            'value': 0
        },
        {
            'name': 'zenodo_files_total',
            'help': 'Number of files hosted on Zenodo',
            'type': 'gauge',
            'value': 0
        },
        {
            'name': 'zenodo_communities_total',
            'help': 'Number of Zenodo communities created',
            'type': 'gauge',
            'value': 0
        },
    ]

    calculated_metrics = calculate_metrics('openaire-nexus', cache=False)
    assert calculated_metrics == expected_data


    calculated_metrics = calculate_metrics('openaire-nexus', cache=True)