# 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/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
# 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 json
import pytest
from lepo.api_info import APIInfo
from lepo.parameter_utils import read_parameters
from lepo_tests.tests.utils import doc_versions, get_router



lil_bub = {'name': 'Lil Bub', 'petType': 'Cat', 'huntingSkill': 'lazy'}
hachiko = {'name': 'Hachiko', 'petType': 'Dog', 'packSize': 83}


@doc_versions
def test_path_refs(doc_version):
    router = get_router(f'{doc_version}/path-refs.yaml')
    assert router.get_path('/b').mapping == router.get_path('/a').mapping


@doc_versions
def test_schema_refs(rf, doc_version):
    router = get_router(f'{doc_version}/schema-refs.yaml')
    request = rf.post('/cat', json.dumps(lil_bub), content_type='application/json')
    request.api_info = APIInfo(router.get_path('/cat').get_operation('post'))
    params = read_parameters(request, {})
    assert params['cat'] == lil_bub



# 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/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
# 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_refs.py
import json
import pytest
from lepo.api_info import APIInfo
from lepo.parameter_utils import read_parameters
from lepo_tests.tests.utils import doc_versions, get_router




lil_bub = {'name': 'Lil Bub', 'petType': 'Cat', 'huntingSkill': 'lazy'}
hachiko = {'name': 'Hachiko', 'petType': 'Dog', 'packSize': 83}


@doc_versions
def test_path_refs(doc_version):
    router = get_router(f'{doc_version}/path-refs.yaml')
    assert router.get_path('/b').mapping == router.get_path('/a').mapping


@doc_versions
def test_schema_refs(rf, doc_version):
    router = get_router(f'{doc_version}/schema-refs.yaml')
    request = rf.post('/cat', json.dumps(lil_bub), content_type='application/json')
    request.api_info = APIInfo(router.get_path('/cat').get_operation('post'))
    params = read_parameters(request, {})
    assert params['cat'] == lil_bub



@doc_versions