# Path: lepo/api_info.py
# class APIInfo:
#     def __init__(self, operation, router=None):
#         """
#         :type operation: lepo.operation.Operation
#         :type router: lepo.router.Router
#         """
#         self.api = operation.api
#         self.path = operation.path
#         self.operation = operation
#         self.router = router
# 
# Path: lepo/apidef/doc.py
# class Swagger2APIDefinition(APIDefinition):
#     version = SWAGGER_2
#     operation_class = Swagger2Operation
# 
# Path: lepo/apidef/parameter/openapi.py
# class OpenAPI3BodyParameter(OpenAPI3Parameter):
#     """
#     OpenAPI 3 Body Parameter
#     """
# 
#     name = '_body'
# 
#     @property
#     def location(self):
#         return 'body'
# 
#     def get_value(self, request, view_kwargs):
#         media_map = self.media_map
#         content_type_name = media_map.match(request.content_type)
#         if not content_type_name:
#             raise InvalidBodyFormat(f'Content-type {request.content_type} is not supported ({media_map.keys()!r} are)')
#         parameter = media_map[content_type_name]
#         value = read_body(request, parameter=parameter)
#         return WrappedValue(parameter=parameter, value=value)
# 
# Path: lepo/excs.py
# class ErroneousParameters(Exception):
#     def __init__(self, error_map, parameters):
#         self.errors = error_map
#         self.parameters = parameters
# 
# class MissingParameter(ValueError):
#     pass
# 
# Path: lepo/parameter_utils.py
# def read_parameters(request, view_kwargs=None, capture_errors=False):  # noqa: C901
#     """
#     :param request: HttpRequest with attached api_info
#     :type request: HttpRequest
#     :type view_kwargs: dict[str, object]
#     :type capture_errors: bool
#     :rtype: dict[str, object]
#     """
#     if view_kwargs is None:
#         view_kwargs = {}
#     params = {}
#     errors = {}
#     for param in request.api_info.operation.parameters:
#         try:
#             value = param.get_value(request, view_kwargs)
#             if value is NO_VALUE:
#                 if param.has_default:
#                     params[param.name] = param.default
#                 elif param.required:  # Required but missing
#                     errors[param.name] = MissingParameter(f'parameter {param.name} is required but missing')
#                 continue  # No value, or a default was added, or an error was added.
#             params[param.name] = param.cast(request.api_info.api, value)
#         except (NotImplementedError, ImproperlyConfigured):
#             raise
#         except Exception as e:
#             if not capture_errors:
#                 raise
#             errors[param.name] = e
#     if errors:
#         raise ErroneousParameters(errors, params)
#     return params
# 
# Path: lepo_tests/tests/utils.py
# DOC_VERSIONS = ['swagger2', 'openapi3']
# 
# def cast_parameter_value(apidoc, parameter, value):
#     if isinstance(parameter, dict):
#         parameter_class = apidoc.operation_class.parameter_class
#         parameter = parameter_class(parameter)
#     return parameter.cast(apidoc, value)
# 
# def get_router(fixture_name):
#     return Router.from_file(os.path.join(TESTS_DIR, fixture_name))


import pytest
from django.core.exceptions import ImproperlyConfigured
from django.core.files.base import ContentFile
from django.core.files.uploadedfile import UploadedFile
from jsonschema import ValidationError
from lepo.api_info import APIInfo
from lepo.apidef.doc import Swagger2APIDefinition
from lepo.apidef.parameter.openapi import OpenAPI3BodyParameter
from lepo.excs import ErroneousParameters, MissingParameter
from lepo.parameter_utils import read_parameters
from lepo_tests.tests.utils import DOC_VERSIONS, cast_parameter_value, get_router
                },
            },
            'what it do',
        )
    assert "'what' is too long" in str(ei.value)


@routers
def test_files(rf, router):
    request = rf.post('/upload', {
        'file': ContentFile(b'foo', name='foo.txt'),
    })
    request.api_info = APIInfo(router.get_path('/upload').get_operation('post'))
    parameters = read_parameters(request)
    if OpenAPI3BodyParameter.name in parameters:  # Peel into the body parameter
        parameters = parameters[OpenAPI3BodyParameter.name]
    assert isinstance(parameters['file'], UploadedFile)


@routers
def test_multi(rf, router):
    request = rf.get('/multiple-tags?tag=a&tag=b&tag=c')
    request.api_info = APIInfo(router.get_path('/multiple-tags').get_operation('get'))
    parameters = read_parameters(request)
    assert parameters['tag'] == ['a', 'b', 'c']


@routers
def test_default(rf, router):
    request = rf.get('/greet?greetee=doggo')

# Path: lepo/api_info.py
# class APIInfo:
#     def __init__(self, operation, router=None):
#         """
#         :type operation: lepo.operation.Operation
#         :type router: lepo.router.Router
#         """
#         self.api = operation.api
#         self.path = operation.path
#         self.operation = operation
#         self.router = router
# 
# Path: lepo/apidef/doc.py
# class Swagger2APIDefinition(APIDefinition):
#     version = SWAGGER_2
#     operation_class = Swagger2Operation
# 
# Path: lepo/apidef/parameter/openapi.py
# class OpenAPI3BodyParameter(OpenAPI3Parameter):
#     """
#     OpenAPI 3 Body Parameter
#     """
# 
#     name = '_body'
# 
#     @property
#     def location(self):
#         return 'body'
# 
#     def get_value(self, request, view_kwargs):
#         media_map = self.media_map
#         content_type_name = media_map.match(request.content_type)
#         if not content_type_name:
#             raise InvalidBodyFormat(f'Content-type {request.content_type} is not supported ({media_map.keys()!r} are)')
#         parameter = media_map[content_type_name]
#         value = read_body(request, parameter=parameter)
#         return WrappedValue(parameter=parameter, value=value)
# 
# Path: lepo/excs.py
# class ErroneousParameters(Exception):
#     def __init__(self, error_map, parameters):
#         self.errors = error_map
#         self.parameters = parameters
# 
# class MissingParameter(ValueError):
#     pass
# 
# Path: lepo/parameter_utils.py
# def read_parameters(request, view_kwargs=None, capture_errors=False):  # noqa: C901
#     """
#     :param request: HttpRequest with attached api_info
#     :type request: HttpRequest
#     :type view_kwargs: dict[str, object]
#     :type capture_errors: bool
#     :rtype: dict[str, object]
#     """
#     if view_kwargs is None:
#         view_kwargs = {}
#     params = {}
#     errors = {}
#     for param in request.api_info.operation.parameters:
#         try:
#             value = param.get_value(request, view_kwargs)
#             if value is NO_VALUE:
#                 if param.has_default:
#                     params[param.name] = param.default
#                 elif param.required:  # Required but missing
#                     errors[param.name] = MissingParameter(f'parameter {param.name} is required but missing')
#                 continue  # No value, or a default was added, or an error was added.
#             params[param.name] = param.cast(request.api_info.api, value)
#         except (NotImplementedError, ImproperlyConfigured):
#             raise
#         except Exception as e:
#             if not capture_errors:
#                 raise
#             errors[param.name] = e
#     if errors:
#         raise ErroneousParameters(errors, params)
#     return params
# 
# Path: lepo_tests/tests/utils.py
# DOC_VERSIONS = ['swagger2', 'openapi3']
# 
# def cast_parameter_value(apidoc, parameter, value):
#     if isinstance(parameter, dict):
#         parameter_class = apidoc.operation_class.parameter_class
#         parameter = parameter_class(parameter)
#     return parameter.cast(apidoc, value)
# 
# def get_router(fixture_name):
#     return Router.from_file(os.path.join(TESTS_DIR, fixture_name))


# Path: lepo_tests/tests/test_parameters.py
import pytest
from django.core.exceptions import ImproperlyConfigured
from django.core.files.base import ContentFile
from django.core.files.uploadedfile import UploadedFile
from jsonschema import ValidationError
from lepo.api_info import APIInfo
from lepo.apidef.doc import Swagger2APIDefinition
from lepo.apidef.parameter.openapi import OpenAPI3BodyParameter
from lepo.excs import ErroneousParameters, MissingParameter
from lepo.parameter_utils import read_parameters
from lepo_tests.tests.utils import DOC_VERSIONS, cast_parameter_value, get_router

                },
            },
            'what it do',
        )
    assert "'what' is too long" in str(ei.value)


@routers
def test_files(rf, router):
    request = rf.post('/upload', {
        'file': ContentFile(b'foo', name='foo.txt'),
    })
    request.api_info = APIInfo(router.get_path('/upload').get_operation('post'))
    parameters = read_parameters(request)
    if OpenAPI3BodyParameter.name in parameters:  # Peel into the body parameter
        parameters = parameters[OpenAPI3BodyParameter.name]
    assert isinstance(parameters['file'], UploadedFile)


@routers
def test_multi(rf, router):
    request = rf.get('/multiple-tags?tag=a&tag=b&tag=c')
    request.api_info = APIInfo(router.get_path('/multiple-tags').get_operation('get'))
    parameters = read_parameters(request)
    assert parameters['tag'] == ['a', 'b', 'c']


@routers
def test_default(rf, router):
    request = rf.get('/greet?greetee=doggo')

    request.api_info = APIInfo(router.get_path('/greet').get_operation('get'))