From 8e2c5a8346ea9cd88f84308515c992a170429b91 Mon Sep 17 00:00:00 2001 From: p1c2u Date: Sun, 26 Nov 2023 00:43:44 +0000 Subject: [PATCH] Pyflakes pre-commit hook --- .pre-commit-config.yaml | 7 ++ openapi_core/app.py | 11 --- openapi_core/casting/schemas/casters.py | 3 - openapi_core/casting/schemas/factories.py | 3 - openapi_core/configurations.py | 58 ------------- openapi_core/contrib/aiohttp/requests.py | 3 - openapi_core/contrib/django/handlers.py | 1 - openapi_core/contrib/django/middlewares.py | 3 - openapi_core/contrib/falcon/middlewares.py | 2 - openapi_core/contrib/flask/decorators.py | 4 - openapi_core/contrib/starlette/handlers.py | 2 - .../contrib/starlette/integrations.py | 3 - openapi_core/contrib/starlette/middlewares.py | 4 - openapi_core/contrib/starlette/requests.py | 1 - .../media_types/deserializers.py | 4 - .../deserializing/media_types/factories.py | 3 - .../deserializing/media_types/util.py | 1 - .../deserializing/styles/datatypes.py | 1 - .../deserializing/styles/deserializers.py | 7 -- .../deserializing/styles/factories.py | 6 -- openapi_core/deserializing/styles/util.py | 1 - openapi_core/extensions/models/factories.py | 2 - openapi_core/protocols.py | 2 - openapi_core/schema/parameters.py | 7 -- openapi_core/shortcuts.py | 30 ------- .../templating/media_types/datatypes.py | 3 - openapi_core/templating/paths/util.py | 2 - openapi_core/unmarshalling/integrations.py | 15 ---- openapi_core/unmarshalling/processors.py | 16 ---- .../unmarshalling/response/protocols.py | 2 - .../unmarshalling/schemas/factories.py | 1 - .../unmarshalling/schemas/unmarshallers.py | 1 - openapi_core/validation/configurations.py | 6 -- openapi_core/validation/integrations.py | 19 ---- openapi_core/validation/processors.py | 9 -- openapi_core/validation/schemas/factories.py | 1 - openapi_core/validation/validators.py | 1 - poetry.lock | 87 ++++++++++++------- pyproject.toml | 2 +- tests/integration/contrib/aiohttp/conftest.py | 2 +- .../data/v3.0/aiohttpproject/pets/views.py | 8 +- .../contrib/aiohttp/test_aiohttp_project.py | 1 - .../data/v3.0/djangoproject/pets/views.py | 1 - .../data/v3.0/falconproject/pets/resources.py | 1 + .../contrib/falcon/test_falcon_project.py | 1 - tests/integration/contrib/flask/conftest.py | 1 - .../data/v3.0/flaskproject/pets/views.py | 2 +- .../contrib/flask/test_flask_decorator.py | 1 - .../contrib/flask/test_flask_validator.py | 2 - .../contrib/flask/test_flask_views.py | 1 - .../requests/test_requests_validation.py | 2 +- .../v3.0/starletteproject/pets/endpoints.py | 8 +- tests/integration/schema/test_spec.py | 18 ---- tests/integration/test_petstore.py | 2 - .../test_response_unmarshaller.py | 5 ++ .../unmarshalling/test_unmarshallers.py | 4 +- .../validation/test_request_validators.py | 9 -- .../validation/test_response_validators.py | 4 - .../unit/contrib/flask/test_flask_requests.py | 2 - .../test_styles_deserializers.py | 3 - .../templating/test_media_types_finders.py | 1 - tests/unit/templating/test_paths_finders.py | 1 - tests/unit/test_shortcuts.py | 2 +- 63 files changed, 84 insertions(+), 332 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 35275c38..1a006f53 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,3 +37,10 @@ repos: language: system require_serial: true types: [python] + + - id: pyflakes + name: pyflakes + entry: pyflakes + language: system + require_serial: true + types: [python] diff --git a/openapi_core/app.py b/openapi_core/app.py index bc13e9b4..38e270ce 100644 --- a/openapi_core/app.py +++ b/openapi_core/app.py @@ -1,16 +1,6 @@ """OpenAPI core app module""" -import warnings -from dataclasses import dataclass -from dataclasses import field -from functools import lru_cache from pathlib import Path -from typing import Any -from typing import Hashable -from typing import Mapping from typing import Optional -from typing import Type -from typing import TypeVar -from typing import Union from jsonschema._utils import Unset from jsonschema.validators import _UNSET @@ -19,7 +9,6 @@ from jsonschema_path.typing import Schema from openapi_spec_validator import validate from openapi_spec_validator.validation.exceptions import ValidatorDetectError -from openapi_spec_validator.validation.types import SpecValidatorType from openapi_spec_validator.versions.datatypes import SpecVersion from openapi_spec_validator.versions.exceptions import OpenAPIVersionNotFound from openapi_spec_validator.versions.shortcuts import get_spec_version diff --git a/openapi_core/casting/schemas/casters.py b/openapi_core/casting/schemas/casters.py index 64cc6391..94df492b 100644 --- a/openapi_core/casting/schemas/casters.py +++ b/openapi_core/casting/schemas/casters.py @@ -1,6 +1,4 @@ -from typing import TYPE_CHECKING from typing import Any -from typing import Callable from typing import Generic from typing import Iterable from typing import List @@ -12,7 +10,6 @@ from jsonschema_path import SchemaPath -from openapi_core.casting.schemas.datatypes import CasterCallable from openapi_core.casting.schemas.exceptions import CastError from openapi_core.schema.schemas import get_properties from openapi_core.util import forcebool diff --git a/openapi_core/casting/schemas/factories.py b/openapi_core/casting/schemas/factories.py index 3cb49cd8..39c7832b 100644 --- a/openapi_core/casting/schemas/factories.py +++ b/openapi_core/casting/schemas/factories.py @@ -1,12 +1,9 @@ -from typing import Dict from typing import Optional from jsonschema_path import SchemaPath from openapi_core.casting.schemas.casters import SchemaCaster from openapi_core.casting.schemas.casters import TypesCaster -from openapi_core.casting.schemas.datatypes import CasterCallable -from openapi_core.util import forcebool from openapi_core.validation.schemas.datatypes import FormatValidatorsDict from openapi_core.validation.schemas.factories import SchemaValidatorsFactory diff --git a/openapi_core/configurations.py b/openapi_core/configurations.py index a348de21..8e8625a2 100644 --- a/openapi_core/configurations.py +++ b/openapi_core/configurations.py @@ -1,79 +1,21 @@ -import warnings from dataclasses import dataclass -from dataclasses import field -from functools import lru_cache -from pathlib import Path -from typing import Any -from typing import Hashable -from typing import Mapping -from typing import Optional -from typing import Type -from typing import TypeVar from typing import Union from jsonschema._utils import Unset from jsonschema.validators import _UNSET -from jsonschema_path import SchemaPath -from jsonschema_path.handlers.protocols import SupportsRead -from jsonschema_path.typing import Schema -from openapi_spec_validator import validate from openapi_spec_validator.validation.types import SpecValidatorType -from openapi_spec_validator.versions.datatypes import SpecVersion -from openapi_spec_validator.versions.exceptions import OpenAPIVersionNotFound -from openapi_spec_validator.versions.shortcuts import get_spec_version -from openapi_core.exceptions import SpecError -from openapi_core.protocols import Request -from openapi_core.protocols import Response -from openapi_core.protocols import WebhookRequest -from openapi_core.types import AnyRequest from openapi_core.unmarshalling.configurations import UnmarshallerConfig -from openapi_core.unmarshalling.request import ( - UNMARSHALLERS as REQUEST_UNMARSHALLERS, -) -from openapi_core.unmarshalling.request import ( - WEBHOOK_UNMARSHALLERS as WEBHOOK_REQUEST_UNMARSHALLERS, -) -from openapi_core.unmarshalling.request.datatypes import RequestUnmarshalResult -from openapi_core.unmarshalling.request.protocols import RequestUnmarshaller -from openapi_core.unmarshalling.request.protocols import ( - WebhookRequestUnmarshaller, -) from openapi_core.unmarshalling.request.types import RequestUnmarshallerType from openapi_core.unmarshalling.request.types import ( WebhookRequestUnmarshallerType, ) -from openapi_core.unmarshalling.response import ( - UNMARSHALLERS as RESPONSE_UNMARSHALLERS, -) -from openapi_core.unmarshalling.response import ( - WEBHOOK_UNMARSHALLERS as WEBHOOK_RESPONSE_UNMARSHALLERS, -) -from openapi_core.unmarshalling.response.datatypes import ( - ResponseUnmarshalResult, -) -from openapi_core.unmarshalling.response.protocols import ResponseUnmarshaller -from openapi_core.unmarshalling.response.protocols import ( - WebhookResponseUnmarshaller, -) from openapi_core.unmarshalling.response.types import ResponseUnmarshallerType from openapi_core.unmarshalling.response.types import ( WebhookResponseUnmarshallerType, ) -from openapi_core.validation.request import VALIDATORS as REQUEST_VALIDATORS -from openapi_core.validation.request import ( - WEBHOOK_VALIDATORS as WEBHOOK_REQUEST_VALIDATORS, -) -from openapi_core.validation.request.protocols import RequestValidator -from openapi_core.validation.request.protocols import WebhookRequestValidator from openapi_core.validation.request.types import RequestValidatorType from openapi_core.validation.request.types import WebhookRequestValidatorType -from openapi_core.validation.response import VALIDATORS as RESPONSE_VALIDATORS -from openapi_core.validation.response import ( - WEBHOOK_VALIDATORS as WEBHOOK_RESPONSE_VALIDATORS, -) -from openapi_core.validation.response.protocols import ResponseValidator -from openapi_core.validation.response.protocols import WebhookResponseValidator from openapi_core.validation.response.types import ResponseValidatorType from openapi_core.validation.response.types import WebhookResponseValidatorType diff --git a/openapi_core/contrib/aiohttp/requests.py b/openapi_core/contrib/aiohttp/requests.py index c7f330c0..73ad0f76 100644 --- a/openapi_core/contrib/aiohttp/requests.py +++ b/openapi_core/contrib/aiohttp/requests.py @@ -1,10 +1,7 @@ """OpenAPI core contrib aiohttp requests module""" from __future__ import annotations -from typing import cast - from aiohttp import web -from asgiref.sync import AsyncToSync from openapi_core.datatypes import RequestParameters diff --git a/openapi_core/contrib/django/handlers.py b/openapi_core/contrib/django/handlers.py index 2209bc8c..4a0df1a3 100644 --- a/openapi_core/contrib/django/handlers.py +++ b/openapi_core/contrib/django/handlers.py @@ -3,7 +3,6 @@ from typing import Callable from typing import Dict from typing import Iterable -from typing import Optional from typing import Type from django.http import JsonResponse diff --git a/openapi_core/contrib/django/middlewares.py b/openapi_core/contrib/django/middlewares.py index aa410c57..bfdb5474 100644 --- a/openapi_core/contrib/django/middlewares.py +++ b/openapi_core/contrib/django/middlewares.py @@ -13,9 +13,6 @@ DjangoOpenAPIValidRequestHandler, ) from openapi_core.contrib.django.integrations import DjangoIntegration -from openapi_core.contrib.django.requests import DjangoOpenAPIRequest -from openapi_core.contrib.django.responses import DjangoOpenAPIResponse -from openapi_core.unmarshalling.processors import UnmarshallingProcessor class DjangoOpenAPIMiddleware(DjangoIntegration): diff --git a/openapi_core/contrib/falcon/middlewares.py b/openapi_core/contrib/falcon/middlewares.py index 29b8bfba..ae3173ef 100644 --- a/openapi_core/contrib/falcon/middlewares.py +++ b/openapi_core/contrib/falcon/middlewares.py @@ -1,6 +1,5 @@ """OpenAPI core contrib falcon middlewares module""" from typing import Any -from typing import Optional from typing import Type from typing import Union @@ -19,7 +18,6 @@ from openapi_core.contrib.falcon.integrations import FalconIntegration from openapi_core.contrib.falcon.requests import FalconOpenAPIRequest from openapi_core.contrib.falcon.responses import FalconOpenAPIResponse -from openapi_core.unmarshalling.processors import UnmarshallingProcessor from openapi_core.unmarshalling.request.types import RequestUnmarshallerType from openapi_core.unmarshalling.response.types import ResponseUnmarshallerType diff --git a/openapi_core/contrib/flask/decorators.py b/openapi_core/contrib/flask/decorators.py index 497b60d8..4d573596 100644 --- a/openapi_core/contrib/flask/decorators.py +++ b/openapi_core/contrib/flask/decorators.py @@ -2,7 +2,6 @@ from functools import wraps from typing import Any from typing import Callable -from typing import Optional from typing import Type from flask.globals import request @@ -17,9 +16,6 @@ from openapi_core.contrib.flask.providers import FlaskRequestProvider from openapi_core.contrib.flask.requests import FlaskOpenAPIRequest from openapi_core.contrib.flask.responses import FlaskOpenAPIResponse -from openapi_core.unmarshalling.processors import UnmarshallingProcessor -from openapi_core.unmarshalling.request.types import RequestUnmarshallerType -from openapi_core.unmarshalling.response.types import ResponseUnmarshallerType class FlaskOpenAPIViewDecorator(FlaskIntegration): diff --git a/openapi_core/contrib/starlette/handlers.py b/openapi_core/contrib/starlette/handlers.py index fbd16cca..47e68739 100644 --- a/openapi_core/contrib/starlette/handlers.py +++ b/openapi_core/contrib/starlette/handlers.py @@ -1,9 +1,7 @@ """OpenAPI core contrib starlette handlers module""" from typing import Any -from typing import Callable from typing import Dict from typing import Iterable -from typing import Optional from typing import Type from starlette.middleware.base import RequestResponseEndpoint diff --git a/openapi_core/contrib/starlette/integrations.py b/openapi_core/contrib/starlette/integrations.py index 3f30c969..340ff870 100644 --- a/openapi_core/contrib/starlette/integrations.py +++ b/openapi_core/contrib/starlette/integrations.py @@ -1,6 +1,3 @@ -from typing import Callable - -from aioitertools.builtins import list as alist from aioitertools.itertools import tee as atee from starlette.requests import Request from starlette.responses import Response diff --git a/openapi_core/contrib/starlette/middlewares.py b/openapi_core/contrib/starlette/middlewares.py index 9bea9066..d1d80304 100644 --- a/openapi_core/contrib/starlette/middlewares.py +++ b/openapi_core/contrib/starlette/middlewares.py @@ -3,7 +3,6 @@ from starlette.middleware.base import RequestResponseEndpoint from starlette.requests import Request from starlette.responses import Response -from starlette.responses import StreamingResponse from starlette.types import ASGIApp from openapi_core import OpenAPI @@ -14,9 +13,6 @@ StarletteOpenAPIValidRequestHandler, ) from openapi_core.contrib.starlette.integrations import StarletteIntegration -from openapi_core.contrib.starlette.requests import StarletteOpenAPIRequest -from openapi_core.contrib.starlette.responses import StarletteOpenAPIResponse -from openapi_core.unmarshalling.processors import AsyncUnmarshallingProcessor class StarletteOpenAPIMiddleware(StarletteIntegration, BaseHTTPMiddleware): diff --git a/openapi_core/contrib/starlette/requests.py b/openapi_core/contrib/starlette/requests.py index c6d223ae..fdbf486f 100644 --- a/openapi_core/contrib/starlette/requests.py +++ b/openapi_core/contrib/starlette/requests.py @@ -1,7 +1,6 @@ """OpenAPI core contrib starlette requests module""" from typing import Optional -from asgiref.sync import AsyncToSync from starlette.requests import Request from openapi_core.datatypes import RequestParameters diff --git a/openapi_core/deserializing/media_types/deserializers.py b/openapi_core/deserializing/media_types/deserializers.py index 2169cc05..a03c7e0d 100644 --- a/openapi_core/deserializing/media_types/deserializers.py +++ b/openapi_core/deserializing/media_types/deserializers.py @@ -1,8 +1,6 @@ -import warnings from typing import Any from typing import Mapping from typing import Optional -from typing import cast from xml.etree.ElementTree import ParseError from jsonschema_path import SchemaPath @@ -106,7 +104,6 @@ def evolve( def decode(self, location: Mapping[str, Any]) -> Mapping[str, Any]: # schema is required for multipart assert self.schema is not None - schema_props = self.schema.get("properties") properties = {} for prop_name, prop_schema in get_properties(self.schema).items(): try: @@ -127,7 +124,6 @@ def decode_property( location: Mapping[str, Any], ) -> Any: if self.encoding is None or prop_name not in self.encoding: - prop_schema_type = prop_schema.getkey("type", "") if self.mimetype == "application/x-www-form-urlencoded": # default serialization strategy for complex objects # in the application/x-www-form-urlencoded diff --git a/openapi_core/deserializing/media_types/factories.py b/openapi_core/deserializing/media_types/factories.py index b39d65a5..45bc5075 100644 --- a/openapi_core/deserializing/media_types/factories.py +++ b/openapi_core/deserializing/media_types/factories.py @@ -3,9 +3,6 @@ from jsonschema_path import SchemaPath -from openapi_core.deserializing.media_types.datatypes import ( - DeserializerCallable, -) from openapi_core.deserializing.media_types.datatypes import ( MediaTypeDeserializersDict, ) diff --git a/openapi_core/deserializing/media_types/util.py b/openapi_core/deserializing/media_types/util.py index fb5cc645..16254382 100644 --- a/openapi_core/deserializing/media_types/util.py +++ b/openapi_core/deserializing/media_types/util.py @@ -2,7 +2,6 @@ from json import loads from typing import Any from typing import Mapping -from typing import Union from urllib.parse import parse_qsl from xml.etree.ElementTree import Element from xml.etree.ElementTree import fromstring diff --git a/openapi_core/deserializing/styles/datatypes.py b/openapi_core/deserializing/styles/datatypes.py index 6e0b99f7..27fc7f6c 100644 --- a/openapi_core/deserializing/styles/datatypes.py +++ b/openapi_core/deserializing/styles/datatypes.py @@ -1,7 +1,6 @@ from typing import Any from typing import Callable from typing import Dict -from typing import List from typing import Mapping DeserializerCallable = Callable[[bool, str, str, Mapping[str, Any]], Any] diff --git a/openapi_core/deserializing/styles/deserializers.py b/openapi_core/deserializing/styles/deserializers.py index b6dbfd93..2303f7a3 100644 --- a/openapi_core/deserializing/styles/deserializers.py +++ b/openapi_core/deserializing/styles/deserializers.py @@ -1,17 +1,10 @@ import warnings from typing import Any -from typing import Callable -from typing import List from typing import Mapping from typing import Optional -from jsonschema_path import SchemaPath - from openapi_core.deserializing.exceptions import DeserializeError from openapi_core.deserializing.styles.datatypes import DeserializerCallable -from openapi_core.deserializing.styles.exceptions import ( - EmptyQueryParameterValue, -) class StyleDeserializer: diff --git a/openapi_core/deserializing/styles/factories.py b/openapi_core/deserializing/styles/factories.py index cfacb2ce..5758d97d 100644 --- a/openapi_core/deserializing/styles/factories.py +++ b/openapi_core/deserializing/styles/factories.py @@ -1,13 +1,7 @@ -import re -from functools import partial -from typing import Any -from typing import Dict -from typing import Mapping from typing import Optional from jsonschema_path import SchemaPath -from openapi_core.deserializing.styles.datatypes import DeserializerCallable from openapi_core.deserializing.styles.datatypes import StyleDeserializersDict from openapi_core.deserializing.styles.deserializers import StyleDeserializer diff --git a/openapi_core/deserializing/styles/util.py b/openapi_core/deserializing/styles/util.py index e04728a9..8290b7b4 100644 --- a/openapi_core/deserializing/styles/util.py +++ b/openapi_core/deserializing/styles/util.py @@ -3,7 +3,6 @@ from typing import Any from typing import List from typing import Mapping -from typing import Optional from openapi_core.schema.protocols import SuportsGetAll from openapi_core.schema.protocols import SuportsGetList diff --git a/openapi_core/extensions/models/factories.py b/openapi_core/extensions/models/factories.py index 0bf9a82f..158318a3 100644 --- a/openapi_core/extensions/models/factories.py +++ b/openapi_core/extensions/models/factories.py @@ -1,11 +1,9 @@ """OpenAPI X-Model extension factories module""" from dataclasses import make_dataclass -from pydoc import ErrorDuringImport from pydoc import locate from typing import Any from typing import Dict from typing import Iterable -from typing import Optional from typing import Type from jsonschema_path import SchemaPath diff --git a/openapi_core/protocols.py b/openapi_core/protocols.py index 338225c9..82bf1532 100644 --- a/openapi_core/protocols.py +++ b/openapi_core/protocols.py @@ -6,8 +6,6 @@ from typing import runtime_checkable from openapi_core.datatypes import RequestParameters -from openapi_core.typing import RequestType -from openapi_core.typing import ResponseType @runtime_checkable diff --git a/openapi_core/schema/parameters.py b/openapi_core/schema/parameters.py index 4f43ea05..967e53f3 100644 --- a/openapi_core/schema/parameters.py +++ b/openapi_core/schema/parameters.py @@ -1,14 +1,7 @@ -from typing import Any -from typing import Dict -from typing import Mapping -from typing import Optional from typing import Tuple from jsonschema_path import SchemaPath -from openapi_core.schema.protocols import SuportsGetAll -from openapi_core.schema.protocols import SuportsGetList - def get_style( param_or_header: SchemaPath, default_location: str = "header" diff --git a/openapi_core/shortcuts.py b/openapi_core/shortcuts.py index 34a149e8..35e3783b 100644 --- a/openapi_core/shortcuts.py +++ b/openapi_core/shortcuts.py @@ -1,46 +1,26 @@ """OpenAPI core shortcuts module""" from typing import Any -from typing import Dict from typing import Optional from typing import Union from jsonschema.validators import _UNSET from jsonschema_path import SchemaPath -from openapi_spec_validator.versions import consts as versions -from openapi_spec_validator.versions.datatypes import SpecVersion -from openapi_spec_validator.versions.exceptions import OpenAPIVersionNotFound -from openapi_spec_validator.versions.shortcuts import get_spec_version from openapi_core.app import OpenAPI from openapi_core.configurations import Config -from openapi_core.exceptions import SpecError from openapi_core.protocols import Request from openapi_core.protocols import Response from openapi_core.protocols import WebhookRequest from openapi_core.types import AnyRequest -from openapi_core.unmarshalling.request import V30RequestUnmarshaller -from openapi_core.unmarshalling.request import V31RequestUnmarshaller -from openapi_core.unmarshalling.request import V31WebhookRequestUnmarshaller from openapi_core.unmarshalling.request.datatypes import RequestUnmarshalResult -from openapi_core.unmarshalling.request.protocols import RequestUnmarshaller -from openapi_core.unmarshalling.request.protocols import ( - WebhookRequestUnmarshaller, -) from openapi_core.unmarshalling.request.types import AnyRequestUnmarshallerType from openapi_core.unmarshalling.request.types import RequestUnmarshallerType from openapi_core.unmarshalling.request.types import ( WebhookRequestUnmarshallerType, ) -from openapi_core.unmarshalling.response import V30ResponseUnmarshaller -from openapi_core.unmarshalling.response import V31ResponseUnmarshaller -from openapi_core.unmarshalling.response import V31WebhookResponseUnmarshaller from openapi_core.unmarshalling.response.datatypes import ( ResponseUnmarshalResult, ) -from openapi_core.unmarshalling.response.protocols import ResponseUnmarshaller -from openapi_core.unmarshalling.response.protocols import ( - WebhookResponseUnmarshaller, -) from openapi_core.unmarshalling.response.types import ( AnyResponseUnmarshallerType, ) @@ -48,19 +28,9 @@ from openapi_core.unmarshalling.response.types import ( WebhookResponseUnmarshallerType, ) -from openapi_core.validation.request import V30RequestValidator -from openapi_core.validation.request import V31RequestValidator -from openapi_core.validation.request import V31WebhookRequestValidator -from openapi_core.validation.request.protocols import RequestValidator -from openapi_core.validation.request.protocols import WebhookRequestValidator from openapi_core.validation.request.types import AnyRequestValidatorType from openapi_core.validation.request.types import RequestValidatorType from openapi_core.validation.request.types import WebhookRequestValidatorType -from openapi_core.validation.response import V30ResponseValidator -from openapi_core.validation.response import V31ResponseValidator -from openapi_core.validation.response import V31WebhookResponseValidator -from openapi_core.validation.response.protocols import ResponseValidator -from openapi_core.validation.response.protocols import WebhookResponseValidator from openapi_core.validation.response.types import AnyResponseValidatorType from openapi_core.validation.response.types import ResponseValidatorType from openapi_core.validation.response.types import WebhookResponseValidatorType diff --git a/openapi_core/templating/media_types/datatypes.py b/openapi_core/templating/media_types/datatypes.py index 37c4c064..77e01f66 100644 --- a/openapi_core/templating/media_types/datatypes.py +++ b/openapi_core/templating/media_types/datatypes.py @@ -1,6 +1,3 @@ from collections import namedtuple -from dataclasses import dataclass -from typing import Mapping -from typing import Optional MediaType = namedtuple("MediaType", ["mime_type", "parameters", "media_type"]) diff --git a/openapi_core/templating/paths/util.py b/openapi_core/templating/paths/util.py index b6844555..a8b6440a 100644 --- a/openapi_core/templating/paths/util.py +++ b/openapi_core/templating/paths/util.py @@ -1,5 +1,3 @@ -from typing import Tuple - from openapi_core.templating.paths.datatypes import Path diff --git a/openapi_core/unmarshalling/integrations.py b/openapi_core/unmarshalling/integrations.py index d3f4b708..e850d57f 100644 --- a/openapi_core/unmarshalling/integrations.py +++ b/openapi_core/unmarshalling/integrations.py @@ -1,9 +1,5 @@ """OpenAPI core unmarshalling processors module""" -from typing import Any from typing import Generic -from typing import Optional - -from jsonschema_path import SchemaPath from openapi_core.app import OpenAPI from openapi_core.protocols import Request @@ -11,20 +7,9 @@ from openapi_core.typing import RequestType from openapi_core.typing import ResponseType from openapi_core.unmarshalling.request.datatypes import RequestUnmarshalResult -from openapi_core.unmarshalling.request.processors import ( - RequestUnmarshallingProcessor, -) -from openapi_core.unmarshalling.request.types import RequestUnmarshallerType from openapi_core.unmarshalling.response.datatypes import ( ResponseUnmarshalResult, ) -from openapi_core.unmarshalling.response.processors import ( - ResponseUnmarshallingProcessor, -) -from openapi_core.unmarshalling.response.types import ResponseUnmarshallerType -from openapi_core.unmarshalling.typing import AsyncValidRequestHandlerCallable -from openapi_core.unmarshalling.typing import ErrorsHandlerCallable -from openapi_core.unmarshalling.typing import ValidRequestHandlerCallable from openapi_core.validation.integrations import ValidationIntegration diff --git a/openapi_core/unmarshalling/processors.py b/openapi_core/unmarshalling/processors.py index 7470ee2b..0ac14574 100644 --- a/openapi_core/unmarshalling/processors.py +++ b/openapi_core/unmarshalling/processors.py @@ -1,26 +1,10 @@ """OpenAPI core unmarshalling processors module""" -from typing import Any -from typing import Generic -from typing import Optional - -from jsonschema_path import SchemaPath - -from openapi_core.protocols import Request -from openapi_core.protocols import Response from openapi_core.typing import RequestType from openapi_core.typing import ResponseType from openapi_core.unmarshalling.integrations import ( AsyncUnmarshallingIntegration, ) from openapi_core.unmarshalling.integrations import UnmarshallingIntegration -from openapi_core.unmarshalling.request.processors import ( - RequestUnmarshallingProcessor, -) -from openapi_core.unmarshalling.request.types import RequestUnmarshallerType -from openapi_core.unmarshalling.response.processors import ( - ResponseUnmarshallingProcessor, -) -from openapi_core.unmarshalling.response.types import ResponseUnmarshallerType from openapi_core.unmarshalling.typing import AsyncValidRequestHandlerCallable from openapi_core.unmarshalling.typing import ErrorsHandlerCallable from openapi_core.unmarshalling.typing import ValidRequestHandlerCallable diff --git a/openapi_core/unmarshalling/response/protocols.py b/openapi_core/unmarshalling/response/protocols.py index 8666e84d..ad9d719b 100644 --- a/openapi_core/unmarshalling/response/protocols.py +++ b/openapi_core/unmarshalling/response/protocols.py @@ -1,6 +1,4 @@ """OpenAPI core validation response protocols module""" -from typing import Any -from typing import Mapping from typing import Optional from typing import Protocol from typing import runtime_checkable diff --git a/openapi_core/unmarshalling/schemas/factories.py b/openapi_core/unmarshalling/schemas/factories.py index 948113a1..6472cab5 100644 --- a/openapi_core/unmarshalling/schemas/factories.py +++ b/openapi_core/unmarshalling/schemas/factories.py @@ -1,4 +1,3 @@ -import sys import warnings from typing import Optional diff --git a/openapi_core/unmarshalling/schemas/unmarshallers.py b/openapi_core/unmarshalling/schemas/unmarshallers.py index 9c574b84..575d24a8 100644 --- a/openapi_core/unmarshalling/schemas/unmarshallers.py +++ b/openapi_core/unmarshalling/schemas/unmarshallers.py @@ -1,7 +1,6 @@ import logging from typing import Any from typing import Iterable -from typing import Iterator from typing import List from typing import Mapping from typing import Optional diff --git a/openapi_core/validation/configurations.py b/openapi_core/validation/configurations.py index 60eb1fb4..f910015f 100644 --- a/openapi_core/validation/configurations.py +++ b/openapi_core/validation/configurations.py @@ -15,12 +15,6 @@ from openapi_core.deserializing.styles.factories import ( StyleDeserializersFactory, ) -from openapi_core.unmarshalling.schemas.datatypes import ( - FormatUnmarshallersDict, -) -from openapi_core.unmarshalling.schemas.factories import ( - SchemaUnmarshallersFactory, -) from openapi_core.validation.schemas.datatypes import FormatValidatorsDict from openapi_core.validation.schemas.factories import SchemaValidatorsFactory diff --git a/openapi_core/validation/integrations.py b/openapi_core/validation/integrations.py index d16ecdb6..3541d20c 100644 --- a/openapi_core/validation/integrations.py +++ b/openapi_core/validation/integrations.py @@ -1,30 +1,11 @@ """OpenAPI core unmarshalling processors module""" -from typing import Any from typing import Generic -from typing import Optional - -from jsonschema_path import SchemaPath from openapi_core.app import OpenAPI from openapi_core.protocols import Request from openapi_core.protocols import Response from openapi_core.typing import RequestType from openapi_core.typing import ResponseType -from openapi_core.unmarshalling.request.datatypes import RequestUnmarshalResult -from openapi_core.unmarshalling.request.processors import ( - RequestUnmarshallingProcessor, -) -from openapi_core.unmarshalling.request.types import RequestUnmarshallerType -from openapi_core.unmarshalling.response.datatypes import ( - ResponseUnmarshalResult, -) -from openapi_core.unmarshalling.response.processors import ( - ResponseUnmarshallingProcessor, -) -from openapi_core.unmarshalling.response.types import ResponseUnmarshallerType -from openapi_core.unmarshalling.typing import AsyncValidRequestHandlerCallable -from openapi_core.unmarshalling.typing import ErrorsHandlerCallable -from openapi_core.unmarshalling.typing import ValidRequestHandlerCallable class ValidationIntegration(Generic[RequestType, ResponseType]): diff --git a/openapi_core/validation/processors.py b/openapi_core/validation/processors.py index 08f1f41a..ab789819 100644 --- a/openapi_core/validation/processors.py +++ b/openapi_core/validation/processors.py @@ -1,16 +1,7 @@ """OpenAPI core validation processors module""" -from typing import Any -from typing import Optional - -from jsonschema_path import SchemaPath - -from openapi_core.protocols import Request -from openapi_core.protocols import Response from openapi_core.typing import RequestType from openapi_core.typing import ResponseType from openapi_core.validation.integrations import ValidationIntegration -from openapi_core.validation.request.types import RequestValidatorType -from openapi_core.validation.response.types import ResponseValidatorType class ValidationProcessor(ValidationIntegration[RequestType, ResponseType]): diff --git a/openapi_core/validation/schemas/factories.py b/openapi_core/validation/schemas/factories.py index e4b316c0..a71d5139 100644 --- a/openapi_core/validation/schemas/factories.py +++ b/openapi_core/validation/schemas/factories.py @@ -1,5 +1,4 @@ from copy import deepcopy -from typing import Mapping from typing import Optional from typing import Type diff --git a/openapi_core/validation/validators.py b/openapi_core/validation/validators.py index 03e80f1b..f885913e 100644 --- a/openapi_core/validation/validators.py +++ b/openapi_core/validation/validators.py @@ -1,5 +1,4 @@ """OpenAPI core validation validators module""" -import re import warnings from functools import cached_property from typing import Any diff --git a/poetry.lock b/poetry.lock index 4c4fb49e..54ba0fd6 100644 --- a/poetry.lock +++ b/poetry.lock @@ -651,6 +651,20 @@ files = [ [package.extras] test = ["pytest (>=6)"] +[[package]] +name = "execnet" +version = "2.0.2" +description = "execnet: rapid multi-Python deployment" +optional = false +python-versions = ">=3.7" +files = [ + {file = "execnet-2.0.2-py3-none-any.whl", hash = "sha256:88256416ae766bc9e8895c76a87928c0012183da3cc4fc18016e6f050e025f41"}, + {file = "execnet-2.0.2.tar.gz", hash = "sha256:cc59bc4423742fd71ad227122eb0dd44db51efb3dc4095b45ac9a08c770096af"}, +] + +[package.extras] +testing = ["hatch", "pre-commit", "pytest", "tox"] + [[package]] name = "falcon" version = "3.1.1" @@ -710,19 +724,19 @@ typing = ["typing-extensions (>=4.8)"] [[package]] name = "flake8" -version = "5.0.4" -description = "the modular source code checker: pep8 pyflakes and co" +version = "2.3.0" +description = "the modular source code checker: pep8, pyflakes and co" optional = false -python-versions = ">=3.6.1" +python-versions = "*" files = [ - {file = "flake8-5.0.4-py2.py3-none-any.whl", hash = "sha256:7a1cf6b73744f5806ab95e526f6f0d8c01c66d7bbe349562d22dfca20610b248"}, - {file = "flake8-5.0.4.tar.gz", hash = "sha256:6fbe320aad8d6b95cec8b8e47bc933004678dc63095be98528b7bdd2a9f510db"}, + {file = "flake8-2.3.0-py2.py3-none-any.whl", hash = "sha256:c99cc9716d6655d9c8bcb1e77632b8615bf0abd282d7abd9f5c2148cad7fc669"}, + {file = "flake8-2.3.0.tar.gz", hash = "sha256:5ee1a43ccd0716d6061521eec6937c983efa027793013e572712c4da55c7c83e"}, ] [package.dependencies] -mccabe = ">=0.7.0,<0.8.0" -pycodestyle = ">=2.9.0,<2.10.0" -pyflakes = ">=2.5.0,<2.6.0" +mccabe = ">=0.2.1" +pep8 = ">=1.5.7" +pyflakes = ">=0.8.1" [[package]] name = "flask" @@ -1440,6 +1454,17 @@ files = [ {file = "pathspec-0.11.2.tar.gz", hash = "sha256:e0d8d0ac2f12da61956eb2306b69f9469b42f4deb0f3cb6ed47b9cce9996ced3"}, ] +[[package]] +name = "pep8" +version = "1.7.1" +description = "Python style guide checker" +optional = false +python-versions = "*" +files = [ + {file = "pep8-1.7.1-py2.py3-none-any.whl", hash = "sha256:b22cfae5db09833bb9bd7c8463b53e1a9c9b39f12e304a8d0bba729c501827ee"}, + {file = "pep8-1.7.1.tar.gz", hash = "sha256:fe249b52e20498e59e0b5c5256aa52ee99fc295b26ec9eaa85776ffdb9fe6374"}, +] + [[package]] name = "pkgutil-resolve-name" version = "1.3.10" @@ -1499,17 +1524,6 @@ nodeenv = ">=0.11.1" pyyaml = ">=5.1" virtualenv = ">=20.10.0" -[[package]] -name = "pycodestyle" -version = "2.9.1" -description = "Python style guide checker" -optional = false -python-versions = ">=3.6" -files = [ - {file = "pycodestyle-2.9.1-py2.py3-none-any.whl", hash = "sha256:d1735fc58b418fd7c5f658d28d943854f8a849b01a5d0a1e6f3f3fdd0166804b"}, - {file = "pycodestyle-2.9.1.tar.gz", hash = "sha256:2c9607871d58c76354b697b42f5d57e1ada7d261c261efac224b664affdc5785"}, -] - [[package]] name = "pydantic" version = "2.4.2" @@ -1666,13 +1680,13 @@ all = ["phonenumbers (>=8,<9)", "pycountry (>=22,<23)"] [[package]] name = "pyflakes" -version = "2.5.0" +version = "3.1.0" description = "passive checker of Python programs" optional = false -python-versions = ">=3.6" +python-versions = ">=3.8" files = [ - {file = "pyflakes-2.5.0-py2.py3-none-any.whl", hash = "sha256:4579f67d887f804e67edb544428f264b7b24f435b263c4614f384135cea553d2"}, - {file = "pyflakes-2.5.0.tar.gz", hash = "sha256:491feb020dca48ccc562a8c0cbe8df07ee13078df59813b83959cbdada312ea3"}, + {file = "pyflakes-3.1.0-py2.py3-none-any.whl", hash = "sha256:4132f6d49cb4dae6819e5379898f2b8cce3c5f23994194c24b77d5da2e36f774"}, + {file = "pyflakes-3.1.0.tar.gz", hash = "sha256:a0aae034c444db0071aa077972ba4768d40c830d9539fd45bf4cd3f8f6992efc"}, ] [[package]] @@ -1748,6 +1762,20 @@ pytest = ">=7.0.0" docs = ["sphinx (>=5.3)", "sphinx-rtd-theme (>=1.0)"] testing = ["coverage (>=6.2)", "flaky (>=3.5.0)", "hypothesis (>=5.7.1)", "mypy (>=0.931)", "pytest-trio (>=0.7.0)"] +[[package]] +name = "pytest-cache" +version = "1.0" +description = "pytest plugin with mechanisms for caching across test runs" +optional = false +python-versions = "*" +files = [ + {file = "pytest-cache-1.0.tar.gz", hash = "sha256:be7468edd4d3d83f1e844959fd6e3fd28e77a481440a7118d430130ea31b07a9"}, +] + +[package.dependencies] +execnet = ">=1.1.dev1" +pytest = ">=2.2" + [[package]] name = "pytest-cov" version = "4.1.0" @@ -1768,18 +1796,19 @@ testing = ["fields", "hunter", "process-tests", "pytest-xdist", "six", "virtuale [[package]] name = "pytest-flake8" -version = "1.1.1" +version = "0.1" description = "pytest plugin to check FLAKE8 requirements" optional = false python-versions = "*" files = [ - {file = "pytest-flake8-1.1.1.tar.gz", hash = "sha256:ba4f243de3cb4c2486ed9e70752c80dd4b636f7ccb27d4eba763c35ed0cd316e"}, - {file = "pytest_flake8-1.1.1-py2.py3-none-any.whl", hash = "sha256:e0661a786f8cbf976c185f706fdaf5d6df0b1667c3bcff8e823ba263618627e7"}, + {file = "pytest-flake8-0.1.tar.gz", hash = "sha256:6b30619538937f274a373ace5fe2895def15066f0d3bad5784458ae0bce61a60"}, + {file = "pytest_flake8-0.1-py2.py3-none-any.whl", hash = "sha256:d2ecd5343ae56b4ac27ffa09d88111cc97dd7fdbc881231dfcdbc852f9ea5121"}, ] [package.dependencies] -flake8 = ">=4.0" -pytest = ">=7.0" +flake8 = ">=2.3" +pytest = ">=2.4.2" +pytest-cache = "*" [[package]] name = "python-multipart" @@ -2501,4 +2530,4 @@ starlette = ["aioitertools", "starlette"] [metadata] lock-version = "2.0" python-versions = "^3.8.0" -content-hash = "41d5d6a586c800a56df3c967fdd0fe0a82159f5592eced1049df0537e44384bc" +content-hash = "ed496bb4138f4693f383311f6bcb598931570a3ce8045413e4e3fb1bdd087a3d" diff --git a/pyproject.toml b/pyproject.toml index 66eee704..3fc838be 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,7 +73,6 @@ openapi-spec-validator = "^0.7.1" requests = {version = "*", optional = true} werkzeug = "*" jsonschema-path = "^0.3.1" -asgiref = "^3.6.0" jsonschema = "^4.18.0" multidict = {version = "^6.0.4", optional = true} aioitertools = {version = "^0.11.0", optional = true} @@ -108,6 +107,7 @@ deptry = ">=0.11,<0.13" aiohttp = "^3.8.4" pytest-aiohttp = "^1.0.4" bump2version = "^1.0.1" +pyflakes = "^3.1.0" [tool.poetry.group.docs.dependencies] sphinx = ">=5.3,<8.0" diff --git a/tests/integration/contrib/aiohttp/conftest.py b/tests/integration/contrib/aiohttp/conftest.py index ce299473..ead341a5 100644 --- a/tests/integration/contrib/aiohttp/conftest.py +++ b/tests/integration/contrib/aiohttp/conftest.py @@ -102,7 +102,7 @@ def router( ) router_ = web.RouteTableDef() handler = test_routes[request.param] - route = router_.post("/browse/{id}/")(handler) + router_.post("/browse/{id}/")(handler) return router_ diff --git a/tests/integration/contrib/aiohttp/data/v3.0/aiohttpproject/pets/views.py b/tests/integration/contrib/aiohttp/data/v3.0/aiohttpproject/pets/views.py index c9130b58..ad721df3 100644 --- a/tests/integration/contrib/aiohttp/data/v3.0/aiohttpproject/pets/views.py +++ b/tests/integration/contrib/aiohttp/data/v3.0/aiohttpproject/pets/views.py @@ -1,12 +1,8 @@ from base64 import b64decode -from io import BytesIO from aiohttp import web from aiohttpproject.openapi import openapi -from multidict import MultiDict -from openapi_core import unmarshal_request -from openapi_core import unmarshal_response from openapi_core.contrib.aiohttp import AIOHTTPOpenAPIWebRequest from openapi_core.contrib.aiohttp import AIOHTTPOpenAPIWebResponse @@ -28,6 +24,7 @@ async def get(self): self.request, body=request_body ) request_unmarshalled = openapi.unmarshal_request(openapi_request) + request_unmarshalled.raise_for_errors() response = web.Response( body=self.OPENID_LOGO, content_type="image/gif", @@ -36,6 +33,7 @@ async def get(self): response_unmarshalled = openapi.unmarshal_response( openapi_request, openapi_response ) + response_unmarshalled.raise_for_errors() return response async def post(self): @@ -44,9 +42,11 @@ async def post(self): self.request, body=request_body ) request_unmarshalled = openapi.unmarshal_request(openapi_request) + request_unmarshalled.raise_for_errors() response = web.Response(status=201) openapi_response = AIOHTTPOpenAPIWebResponse(response) response_unmarshalled = openapi.unmarshal_response( openapi_request, openapi_response ) + response_unmarshalled.raise_for_errors() return response diff --git a/tests/integration/contrib/aiohttp/test_aiohttp_project.py b/tests/integration/contrib/aiohttp/test_aiohttp_project.py index ea659378..9b67705a 100644 --- a/tests/integration/contrib/aiohttp/test_aiohttp_project.py +++ b/tests/integration/contrib/aiohttp/test_aiohttp_project.py @@ -3,7 +3,6 @@ from base64 import b64encode import pytest -from starlette.testclient import TestClient @pytest.fixture(autouse=True, scope="session") diff --git a/tests/integration/contrib/django/data/v3.0/djangoproject/pets/views.py b/tests/integration/contrib/django/data/v3.0/djangoproject/pets/views.py index cb83ce71..1cdb3c4e 100644 --- a/tests/integration/contrib/django/data/v3.0/djangoproject/pets/views.py +++ b/tests/integration/contrib/django/data/v3.0/djangoproject/pets/views.py @@ -1,6 +1,5 @@ from base64 import b64decode -from django.conf import settings from django.http import FileResponse from django.http import HttpResponse from django.http import JsonResponse diff --git a/tests/integration/contrib/falcon/data/v3.0/falconproject/pets/resources.py b/tests/integration/contrib/falcon/data/v3.0/falconproject/pets/resources.py index be69008e..5d0a83f4 100644 --- a/tests/integration/contrib/falcon/data/v3.0/falconproject/pets/resources.py +++ b/tests/integration/contrib/falcon/data/v3.0/falconproject/pets/resources.py @@ -95,4 +95,5 @@ def on_get(self, request, response, petId=None): def on_post(self, request, response, petId=None): data = request.stream.read() + assert data == self.OPENID_LOGO response.status = HTTP_201 diff --git a/tests/integration/contrib/falcon/test_falcon_project.py b/tests/integration/contrib/falcon/test_falcon_project.py index ca9bc066..7ed3a19c 100644 --- a/tests/integration/contrib/falcon/test_falcon_project.py +++ b/tests/integration/contrib/falcon/test_falcon_project.py @@ -2,7 +2,6 @@ from json import dumps import pytest -from falcon.constants import MEDIA_URLENCODED class BaseTestFalconProject: diff --git a/tests/integration/contrib/flask/conftest.py b/tests/integration/contrib/flask/conftest.py index 80e8579c..a89e729a 100644 --- a/tests/integration/contrib/flask/conftest.py +++ b/tests/integration/contrib/flask/conftest.py @@ -1,6 +1,5 @@ import pytest from flask import Flask -from jsonschema_path import SchemaPath @pytest.fixture(scope="session") diff --git a/tests/integration/contrib/flask/data/v3.0/flaskproject/pets/views.py b/tests/integration/contrib/flask/data/v3.0/flaskproject/pets/views.py index 091b942e..f9b55a03 100644 --- a/tests/integration/contrib/flask/data/v3.0/flaskproject/pets/views.py +++ b/tests/integration/contrib/flask/data/v3.0/flaskproject/pets/views.py @@ -24,5 +24,5 @@ def get(self, petId): return send_file(fp, mimetype="image/gif") def post(self, petId): - data = request.stream.read() + assert request.data == self.OPENID_LOGO return Response(status=201) diff --git a/tests/integration/contrib/flask/test_flask_decorator.py b/tests/integration/contrib/flask/test_flask_decorator.py index cda6cd09..91637b94 100644 --- a/tests/integration/contrib/flask/test_flask_decorator.py +++ b/tests/integration/contrib/flask/test_flask_decorator.py @@ -1,5 +1,4 @@ import pytest -from flask import Flask from flask import jsonify from flask import make_response diff --git a/tests/integration/contrib/flask/test_flask_validator.py b/tests/integration/contrib/flask/test_flask_validator.py index 45773c39..4e24e848 100644 --- a/tests/integration/contrib/flask/test_flask_validator.py +++ b/tests/integration/contrib/flask/test_flask_validator.py @@ -1,7 +1,5 @@ from json import dumps -import pytest -from flask import Flask from flask.testing import FlaskClient from flask.wrappers import Response diff --git a/tests/integration/contrib/flask/test_flask_views.py b/tests/integration/contrib/flask/test_flask_views.py index a1caa2c7..fa00c198 100644 --- a/tests/integration/contrib/flask/test_flask_views.py +++ b/tests/integration/contrib/flask/test_flask_views.py @@ -1,5 +1,4 @@ import pytest -from flask import Flask from flask import jsonify from flask import make_response diff --git a/tests/integration/contrib/requests/test_requests_validation.py b/tests/integration/contrib/requests/test_requests_validation.py index 69aa1c34..b989ee37 100644 --- a/tests/integration/contrib/requests/test_requests_validation.py +++ b/tests/integration/contrib/requests/test_requests_validation.py @@ -207,7 +207,7 @@ def test_request_binary_valid(self, request_unmarshaller, data_gif): data=data_gif, ) request_prepared = request.prepare() - openapi_request = RequestsOpenAPIRequest(request) + openapi_request = RequestsOpenAPIRequest(request_prepared) result = request_unmarshaller.unmarshal(openapi_request) assert not result.errors assert result.body == data_gif diff --git a/tests/integration/contrib/starlette/data/v3.0/starletteproject/pets/endpoints.py b/tests/integration/contrib/starlette/data/v3.0/starletteproject/pets/endpoints.py index 1ec8e17b..b17b3029 100644 --- a/tests/integration/contrib/starlette/data/v3.0/starletteproject/pets/endpoints.py +++ b/tests/integration/contrib/starlette/data/v3.0/starletteproject/pets/endpoints.py @@ -4,11 +4,6 @@ from starlette.responses import Response from starlette.responses import StreamingResponse -from openapi_core import unmarshal_request -from openapi_core import unmarshal_response -from openapi_core.contrib.starlette import StarletteOpenAPIRequest -from openapi_core.contrib.starlette import StarletteOpenAPIResponse - OPENID_LOGO = b64decode( """ R0lGODlhEAAQAMQAAO3t7eHh4srKyvz8/P5pDP9rENLS0v/28P/17tXV1dHEvPDw8M3Nzfn5+d3d @@ -96,9 +91,10 @@ async def pet_detail_endpoint(request): async def pet_photo_endpoint(request): - body = await request.body() if request.method == "GET": contents = iter([OPENID_LOGO]) return StreamingResponse(contents, media_type="image/gif") elif request.method == "POST": + body = await request.body() + assert body == OPENID_LOGO return Response(status_code=201) diff --git a/tests/integration/schema/test_spec.py b/tests/integration/schema/test_spec.py index 56f14c29..d8191f3e 100644 --- a/tests/integration/schema/test_spec.py +++ b/tests/integration/schema/test_spec.py @@ -3,8 +3,6 @@ import pytest from jsonschema_path import SchemaPath -from openapi_core import V30RequestValidator -from openapi_core import V30ResponseValidator from openapi_core.schema.servers import get_server_url from openapi_core.schema.specs import get_spec_url @@ -31,14 +29,6 @@ def spec_dict(self, content_factory): def schema_path(self, spec_dict, base_uri): return SchemaPath.from_dict(spec_dict, base_uri=base_uri) - @pytest.fixture - def request_validator(self, schema_path): - return V30RequestValidator(schema_path) - - @pytest.fixture - def response_validator(self, schema_path): - return V30ResponseValidator(schema_path) - def test_spec(self, schema_path, spec_dict): url = "http://petstore.swagger.io/v1" @@ -325,14 +315,6 @@ def schema_path(self, spec_dict, base_uri): base_uri=base_uri, ) - @pytest.fixture - def request_validator(self, spec): - return RequestValidator(spec) - - @pytest.fixture - def response_validator(self, spec): - return ResponseValidator(spec) - def test_spec(self, schema_path, spec_dict): info = schema_path / "info" info_spec = spec_dict["info"] diff --git a/tests/integration/test_petstore.py b/tests/integration/test_petstore.py index cf79321f..f00bbfbc 100644 --- a/tests/integration/test_petstore.py +++ b/tests/integration/test_petstore.py @@ -14,7 +14,6 @@ from openapi_core import validate_response from openapi_core.casting.schemas.exceptions import CastError from openapi_core.datatypes import Parameters -from openapi_core.deserializing.exceptions import DeserializeError from openapi_core.deserializing.styles.exceptions import ( EmptyQueryParameterValue, ) @@ -1326,7 +1325,6 @@ def test_get_pet_invalid_security(self, spec): view_args = { "petId": "1", } - auth = "authuser" request = MockRequest( host_url, "GET", diff --git a/tests/integration/unmarshalling/test_response_unmarshaller.py b/tests/integration/unmarshalling/test_response_unmarshaller.py index 515696a0..3c67cf60 100644 --- a/tests/integration/unmarshalling/test_response_unmarshaller.py +++ b/tests/integration/unmarshalling/test_response_unmarshaller.py @@ -137,11 +137,16 @@ def test_invalid_header(self, response_unmarshaller): "name": 1, } userdata_json = json.dumps(userdata) + cookies = { + "user": "123", + "userdata": userdata_json, + } request = MockRequest( self.host_url, "delete", "/v1/tags", path_pattern="/v1/tags", + cookies=cookies, ) response_json = { "data": [ diff --git a/tests/integration/unmarshalling/test_unmarshallers.py b/tests/integration/unmarshalling/test_unmarshallers.py index 7efb8ed9..04c980a6 100644 --- a/tests/integration/unmarshalling/test_unmarshallers.py +++ b/tests/integration/unmarshalling/test_unmarshallers.py @@ -355,7 +355,7 @@ def test_string_datetime_invalid(self, unmarshallers_factory): unmarshaller.unmarshal(value) assert len(exc_info.value.schema_errors) == 1 assert ( - f"is not a 'date-time'" in exc_info.value.schema_errors[0].message + "is not a 'date-time'" in exc_info.value.schema_errors[0].message ) def test_string_password(self, unmarshallers_factory): @@ -396,7 +396,7 @@ def test_string_uuid_invalid(self, unmarshallers_factory): with pytest.raises(InvalidSchemaValue) as exc_info: unmarshaller.unmarshal(value) assert len(exc_info.value.schema_errors) == 1 - assert f"is not a 'uuid'" in exc_info.value.schema_errors[0].message + assert "is not a 'uuid'" in exc_info.value.schema_errors[0].message @pytest.mark.parametrize( "type,format,value,expected", diff --git a/tests/integration/validation/test_request_validators.py b/tests/integration/validation/test_request_validators.py index 5cae21a9..14a7e6d6 100644 --- a/tests/integration/validation/test_request_validators.py +++ b/tests/integration/validation/test_request_validators.py @@ -1,23 +1,14 @@ -import json from base64 import b64encode import pytest from openapi_core import V30RequestValidator -from openapi_core.datatypes import Parameters from openapi_core.templating.media_types.exceptions import MediaTypeNotFound from openapi_core.templating.paths.exceptions import OperationNotFound from openapi_core.templating.paths.exceptions import PathNotFound from openapi_core.templating.security.exceptions import SecurityNotFound from openapi_core.testing import MockRequest -from openapi_core.unmarshalling.request.unmarshallers import ( - V30RequestUnmarshaller, -) -from openapi_core.validation.request.exceptions import InvalidParameter from openapi_core.validation.request.exceptions import MissingRequiredParameter -from openapi_core.validation.request.exceptions import ( - MissingRequiredRequestBody, -) from openapi_core.validation.request.exceptions import ( RequestBodyValidationError, ) diff --git a/tests/integration/validation/test_response_validators.py b/tests/integration/validation/test_response_validators.py index 807aa13e..dcc1c0a3 100644 --- a/tests/integration/validation/test_response_validators.py +++ b/tests/integration/validation/test_response_validators.py @@ -1,5 +1,4 @@ import json -from dataclasses import is_dataclass import pytest @@ -13,9 +12,6 @@ from openapi_core.templating.responses.exceptions import ResponseNotFound from openapi_core.testing import MockRequest from openapi_core.testing import MockResponse -from openapi_core.unmarshalling.response.unmarshallers import ( - V30ResponseUnmarshaller, -) from openapi_core.validation.response.exceptions import DataValidationError from openapi_core.validation.response.exceptions import InvalidData from openapi_core.validation.response.exceptions import InvalidHeader diff --git a/tests/unit/contrib/flask/test_flask_requests.py b/tests/unit/contrib/flask/test_flask_requests.py index 63e51abf..48209cc6 100644 --- a/tests/unit/contrib/flask/test_flask_requests.py +++ b/tests/unit/contrib/flask/test_flask_requests.py @@ -1,5 +1,3 @@ -from urllib.parse import urljoin - import pytest from werkzeug.datastructures import Headers from werkzeug.datastructures import ImmutableMultiDict diff --git a/tests/unit/deserializing/test_styles_deserializers.py b/tests/unit/deserializing/test_styles_deserializers.py index 3c516143..29e52d25 100644 --- a/tests/unit/deserializing/test_styles_deserializers.py +++ b/tests/unit/deserializing/test_styles_deserializers.py @@ -4,9 +4,6 @@ from openapi_core.deserializing.exceptions import DeserializeError from openapi_core.deserializing.styles import style_deserializers_factory -from openapi_core.deserializing.styles.exceptions import ( - EmptyQueryParameterValue, -) from openapi_core.schema.parameters import get_style_and_explode diff --git a/tests/unit/templating/test_media_types_finders.py b/tests/unit/templating/test_media_types_finders.py index 9580c30c..c94ff5b6 100644 --- a/tests/unit/templating/test_media_types_finders.py +++ b/tests/unit/templating/test_media_types_finders.py @@ -3,7 +3,6 @@ from openapi_core.templating.media_types.exceptions import MediaTypeNotFound from openapi_core.templating.media_types.finders import MediaTypeFinder -from openapi_core.testing import MockResponse class TestMediaTypes: diff --git a/tests/unit/templating/test_paths_finders.py b/tests/unit/templating/test_paths_finders.py index cb0821ee..d150911f 100644 --- a/tests/unit/templating/test_paths_finders.py +++ b/tests/unit/templating/test_paths_finders.py @@ -7,7 +7,6 @@ from openapi_core.templating.paths.exceptions import PathsNotFound from openapi_core.templating.paths.exceptions import ServerNotFound from openapi_core.templating.paths.finders import APICallPathFinder -from openapi_core.testing import MockRequest class BaseTestSimpleServer: diff --git a/tests/unit/test_shortcuts.py b/tests/unit/test_shortcuts.py index 963c4658..0dd18651 100644 --- a/tests/unit/test_shortcuts.py +++ b/tests/unit/test_shortcuts.py @@ -593,7 +593,7 @@ def test_request(self, mock_validate, spec_v31): class TestValidateRequest: - def test_spec_not_detected(self, spec_invalid): + def test_spec_invalid(self, spec_invalid): request = mock.Mock(spec=Request) with pytest.raises(SpecError):