#
# Copyright (C) 2021 Associated Universities, Inc. Washington DC, USA.
#
# This file is part of NRAO Workspaces.
#
# Workspaces is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Workspaces is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Workspaces.  If not, see <https://www.gnu.org/licenses/>.

""" Make sure we've got all the capability routes"""

# pylint: disable=E0401, W0621
import copy
import http
from typing import List
from unittest.mock import patch

import pytest
from capability.views.capability_request import create_follow_on_capability_request
from pyramid.config import Configurator
from pyramid.interfaces import IRoutesMapper
from pyramid.testing import DummyRequest

from workspaces.capability.schema import (
    Capability,
    CapabilityRequest,
    CapabilityVersion,
)
from workspaces.capability.services.capability_info import CapabilityInfo
from workspaces.capability.services.capability_service import CapabilityService
from workspaces.workflow.schema import WorkflowRequest
from workspaces.workflow.services.workflow_service import WorkflowService

pytest_plugins = ["testing.utils.conftest"]

RouteList = List[str]


@pytest.fixture()
def capability_routes() -> RouteList:
    """
    All the capability routes (or should be)

    :return: list of all available capability routes
    """
    return [
        "home",
        "view_capability",
        "view_active_capability_requests",
        "view_created_capability_requests",
        "create_capability",
        "edit_capability",
        "enable_capability",
        "disable_capability",
        "pause_capability",
        "unpause_capability",
        "view_capability_request",
        "create_capability_request",
        "create_and_submit_capability_request",
        "launch_capability_request_from_ingestion_details",
        "create_follow_on_capability_request",
        "edit_capability_request",
        "get_execution_by_version",
        "create_version_from_previous_execution_script",
        "cancel_capability_request",
        "delete_capability_request",
        "view_all_versions",
        "view_latest_version",
        "view_specific_version",
        "view_version_metadata",
        "edit_version_metadata",
        "create_capability_version",
        "submit_capability_version",
        "add_file_to_latest",
        "get_execution_from_workflow_id",
    ]


def test_routes_exist(test_config: Configurator, capability_routes: RouteList):
    """
    Tests that the Pyramid config has the proper capability routes set up

    :param test_config: Mock pyramid config for testing purposes
    """

    test_config.include("capability.routes")
    mapper = test_config.registry.queryUtility(IRoutesMapper)

    route_names = [route.name for route in mapper.get_routes()]

    for route in route_names:
        assert route in capability_routes

    for route in capability_routes:
        assert route in route_names

    assert len(capability_routes) == len(route_names)