# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright (c) 2016-2017 Anaconda, Inc.
#
# May be copied and distributed freely only as part of an Anaconda or
# Miniconda installation.
# -----------------------------------------------------------------------------
"""Tests for valid urls in bundled content."""

# yapf: disable

# Standard library imports
import io
import json

# Third party imports
import pytest
import requests

# Local imports
from anaconda_navigator.static import content


# yapf: enable


# --- Tests
# -----------------------------------------------------------------------------
@pytest.mark.skip
def test_content_urls():
    with open(content.LINKS_INFO_PATH, 'r') as f_handle:
        raw_data = f_handle.read()
    data = json.loads(raw_data)

    for item in data:
        uri = item.get('uri')

        try:
            r = requests.head(uri, timeout=10, verify=False)
            code = r.status_code
            error = None
        except Exception as e:
            code = None
            error = e

        # Temporal bypass for planet.scipy which is failing
        if 'planet.scipy' not in uri:
            print(uri, code, error)
            assert code in [200, 301, 302, 403]


def test_content_encoding():
    """Make sure the bundled content is ascii."""
    # See: https://github.com/ContinuumIO/navigator/issues/1613
    with io.open(content.LINKS_INFO_PATH, 'r', encoding='ascii') as f_handle:
        f_handle.read()
