# Path: dbcollection/utils/test.py
# def check_url_redirect(url, timeout_seconds=3):
#     try:
#         with Timeout(timeout_seconds):
#             response = requests.get(url)
#             return response.status_code == 200
#     except Timeout.Timeout:
#         return True
# 
# Path: dbcollection/core/api/metadata.py
# def get_list_urls_dataset():
#     available_datasets = fetch_list_datasets()
#     dataset_urls = []
#     for name in available_datasets:
#         urls = available_datasets[name]['urls']
#         url_list = get_urls_list(urls)
#         dataset_urls.append((name, url_list))
#     return dataset_urls


import requests
import pytest
from dbcollection.utils.test import check_url_redirect
from dbcollection.core.api.metadata import get_list_urls_dataset
"""
Test dataset's urls download status.
"""




TIMEOUT_SECONDS = 3


@pytest.mark.parametrize("dataset_name, urls", get_list_urls_dataset())
@pytest.mark.slow
def test_check_urls_are_valid(dataset_name, urls):
    for url in urls:
        response = requests.head(url)  # try without redirect enabled
        if response.status_code == 200:
            status = True
        else:
            if response.status_code == 301:

# Path: dbcollection/utils/test.py
# def check_url_redirect(url, timeout_seconds=3):
#     try:
#         with Timeout(timeout_seconds):
#             response = requests.get(url)
#             return response.status_code == 200
#     except Timeout.Timeout:
#         return True
# 
# Path: dbcollection/core/api/metadata.py
# def get_list_urls_dataset():
#     available_datasets = fetch_list_datasets()
#     dataset_urls = []
#     for name in available_datasets:
#         urls = available_datasets[name]['urls']
#         url_list = get_urls_list(urls)
#         dataset_urls.append((name, url_list))
#     return dataset_urls


# Path: tests/datasets/test_check_urls_health.py
import requests
import pytest
from dbcollection.utils.test import check_url_redirect
from dbcollection.core.api.metadata import get_list_urls_dataset

"""
Test dataset's urls download status.
"""




TIMEOUT_SECONDS = 3


@pytest.mark.parametrize("dataset_name, urls", get_list_urls_dataset())
@pytest.mark.slow
def test_check_urls_are_valid(dataset_name, urls):
    for url in urls:
        response = requests.head(url)  # try without redirect enabled
        if response.status_code == 200:
            status = True
        else:
            if response.status_code == 301:

                status = check_url_redirect(url, TIMEOUT_SECONDS)  # try with redirect enabled