# Path: lepo/excs.py
# class InvalidParameterDefinition(ImproperlyConfigured):
#     pass
# 
# class RouterValidationError(Exception):
#     def __init__(self, error_map):
#         self.errors = error_map
#         self.description = '\n'.join(f'{operation.id}: {error}' for (operation, error) in self.flat_errors)
#         super().__init__(f'Router validation failed:\n{self.description}')
# 
#     @property
#     def flat_errors(self):
#         for operation, errors in sorted(self.errors.items(), key=str):
#             for error in errors:
#                 yield (operation, error)
# 
# Path: lepo/validate.py
# def validate_router(router):
#     errors = defaultdict(list)
#     for path in router.get_paths():
#         for operation in path.get_operations():
#             # Check the handler exists.
#             try:
#                 router.get_handler(operation.id)
#             except MissingHandler as e:
#                 errors[operation].append(e)
# 
#             for param in operation.parameters:
#                 if param.location == 'header' and '_' in param.name:  # See https://github.com/akx/lepo/issues/23
#                     ipd = InvalidParameterDefinition(
#                         f'{param.name}: Header parameter names may not contain underscores (Django bug 25048)'
#                     )
#                     errors[operation].append(ipd)
# 
#     if errors:
#         raise RouterValidationError(errors)
# 
# Path: lepo_tests/tests/utils.py
# TESTS_DIR = os.path.dirname(__file__)
# DOC_VERSIONS = ['swagger2', 'openapi3']
# def get_router(fixture_name):
# def get_data_from_response(response, status=200):
# def cast_parameter_value(apidoc, parameter, value):
# def get_apidoc_from_version(version, content={}):
# def make_request_for_operation(operation, method='GET', query_string=''):


import pytest
from lepo.excs import InvalidParameterDefinition, RouterValidationError
from lepo.validate import validate_router
from lepo_tests.tests.utils import doc_versions, get_router



@doc_versions
def test_validator(doc_version):
    router = get_router(f'{doc_version}/schema-refs.yaml')
    with pytest.raises(RouterValidationError) as ei:
        validate_router(router)
    assert len(ei.value.errors) == 2


@doc_versions
def test_header_underscore(doc_version):
    router = get_router(f'{doc_version}/header-underscore.yaml')

# Path: lepo/excs.py
# class InvalidParameterDefinition(ImproperlyConfigured):
#     pass
# 
# class RouterValidationError(Exception):
#     def __init__(self, error_map):
#         self.errors = error_map
#         self.description = '\n'.join(f'{operation.id}: {error}' for (operation, error) in self.flat_errors)
#         super().__init__(f'Router validation failed:\n{self.description}')
# 
#     @property
#     def flat_errors(self):
#         for operation, errors in sorted(self.errors.items(), key=str):
#             for error in errors:
#                 yield (operation, error)
# 
# Path: lepo/validate.py
# def validate_router(router):
#     errors = defaultdict(list)
#     for path in router.get_paths():
#         for operation in path.get_operations():
#             # Check the handler exists.
#             try:
#                 router.get_handler(operation.id)
#             except MissingHandler as e:
#                 errors[operation].append(e)
# 
#             for param in operation.parameters:
#                 if param.location == 'header' and '_' in param.name:  # See https://github.com/akx/lepo/issues/23
#                     ipd = InvalidParameterDefinition(
#                         f'{param.name}: Header parameter names may not contain underscores (Django bug 25048)'
#                     )
#                     errors[operation].append(ipd)
# 
#     if errors:
#         raise RouterValidationError(errors)
# 
# Path: lepo_tests/tests/utils.py
# TESTS_DIR = os.path.dirname(__file__)
# DOC_VERSIONS = ['swagger2', 'openapi3']
# def get_router(fixture_name):
# def get_data_from_response(response, status=200):
# def cast_parameter_value(apidoc, parameter, value):
# def get_apidoc_from_version(version, content={}):
# def make_request_for_operation(operation, method='GET', query_string=''):


# Path: lepo_tests/tests/test_router_validator.py
import pytest
from lepo.excs import InvalidParameterDefinition, RouterValidationError
from lepo.validate import validate_router
from lepo_tests.tests.utils import doc_versions, get_router




@doc_versions
def test_validator(doc_version):
    router = get_router(f'{doc_version}/schema-refs.yaml')
    with pytest.raises(RouterValidationError) as ei:
        validate_router(router)
    assert len(ei.value.errors) == 2


@doc_versions
def test_header_underscore(doc_version):
    router = get_router(f'{doc_version}/header-underscore.yaml')

    with pytest.raises(RouterValidationError) as ei: